Prestashop Returns with any Order Status

If you have an online sales website based on Prestashop, you must have experienced returns of products for either a refund of a change of product.

If you are not familiar with how to do returns using Prestashop, read these first:

Merchandise return (RMAs) in Prestashop

And in French, you have these two good articles:

  1. La gestion des retours et des avoirs dans Prestashop
  2. Prestashop – Gérer les retours produits

Now, the problem is that (at least up to version 1.2.5) Prestashop will only allow returns if the order status is set to “Delivered”. I personally never bother to use this status, and I assume I am not an isolated case. So instead of being forced to do what Prestashop expects, I have hacked the classes/Order.php PHP template to get it to accept return for any order status of my choice.

  1. Go to your Prestashop back office
  2. Activate the returns, and choose the number of days for returns. Careful, a value of zero will allow all orders to potentially claim a refund.
  3. Hack the classes/Orders.php file with the simple following changes:
  4. You want to add:
    if ($result[‘days’] == NULL) return false; as shown in this function:

    	public function getNumberOfDays()
    	{
    		$nbReturnDays = intval(Configuration::get('PS_ORDER_RETURN_NB_DAYS'));
    		
    		
    		if (!$nbReturnDays)
    			return true;
    		$result = Db::getInstance()->getRow('
    		SELECT TO_DAYS(NOW()) - TO_DAYS(`delivery_date`)  AS days FROM `'._DB_PREFIX_.'orders`
    		WHERE `id_order` = '.intval($this->id));
    		
    		if ($result['days'] == NULL)
    			return false;
    				
    		if ($result['days'] < = $nbReturnDays)
    			return true;
    		return false;
    	}
    
  5. Then this is the function you want to use instead of the default isReturnable. Remember to adapter the orderstatus numbers to what you actually want to allow returns. In my case it's 12, 13, 14, 15, which are personal order statuses.
  6. 	public function isReturnable()
    	{
    		$returnsActivated= intval(Configuration::get('PS_ORDER_RETURN')) == 1; 
    		$notTooLate= $this->getNumberOfDays();
    		$statusEligible = (intval($this->getCurrentState()) == _PS_OS_DELIVERED_ 
    						|| intval($this->getCurrentState()) == 12
    						|| intval($this->getCurrentState()) == 13
    						|| intval($this->getCurrentState()) == 14
    						|| intval($this->getCurrentState()) == 15);		
    		
    		return ($returnsActivated && $notTooLate && $statusEligible);
    		// ORIGINAL CODE :
    		//return (intval(Configuration::get('PS_ORDER_RETURN')) == 1 && $this->getNumberOfDays() && (intval($this->getCurrentState()) == _PS_OS_DELIVERED_ || intval($this->getCurrentState()) == 15));
    		}
    

Be Sociable, Share!

4 thoughts on “Prestashop Returns with any Order Status

Leave a Reply

Your email address will not be published. Required fields are marked *