Jump to content

how to change order status in prestashop


Recommended Posts

hello I am using ps

Is there any one can help me.., I have change order status when order place successfully. for that I have created new order status when module install. in orderConfirmation hook I have written following line of code.


public function hookOrderConfirmation($params)

$objOrder = $params['objOrder'];
$history = new OrderHistory();
$history->id_order = (int)$objOrder->id;
$history->changeIdOrderState(Configuration::get('PS_OS_ADVANCEORDER'), (int)$objOrder->id, true);

its change order status as well but what conflict with payment modules is that hook paymentReturn call after hook orderConfirmation so in "PayBycheque" or "PayByBank" crosscheck as follos in paymentReturn hook


public function hookPaymentReturn($params)

if (!$this->active)
$state = $params['objOrder']->getCurrentState();
if ($state == Configuration::get('PS_OS_BANKWIRE') || $state == Configuration::get('PS_OS_OUTOFSTOCK'))
'total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false),
'bankwireDetails' => Tools::nl2br($this->details),
'bankwireAddress' => Tools::nl2br($this->address),
'bankwireOwner' => $this->owner,
'status' => 'ok',
'id_order' => $params['objOrder']->id
if (isset($params['objOrder']->reference) && !empty($params['objOrder']->reference))
$this->smarty->assign('reference', $params['objOrder']->reference);
$this->smarty->assign('status', 'failed');
return $this->display(__FILE__, 'payment_return.tpl');

so problem is when order is place it is not display order-confimation page but display like follows warning.

"We noticed a problem with your order. If you think this is an error, feel free to contact our expert customer support team. .".

Edited by NishantVadgama (see edit history)
Link to comment
Share on other sites

I came across the same issue recently, but could not find any workaround so I associate to your question

I have found one solution for this initially that is override OrderConfirmationController's initContent() method in your module and write as follows.


public function initContent()

'is_guest' => $this->context->customer->is_guest,
'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn(),
'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation()
if ($this->context->customer->is_guest)
'id_order' => $this->id_order,
'reference_order' => $this->reference,
'id_order_formatted' => sprintf('#%06d', $this->id_order),
'email' => $this->context->customer->email
/* If guest we clear the cookie for security reason */

This is same as original but I have just swap there red color line of code so in execution first execute paymentReturn() and then OrderConfirmation(). this works fine with me. I hope It will help you.


Thank You.

Link to comment
Share on other sites

Well actually the problem is not only there, as the order should also be inverted inside the paymentModule class, method validateOrder, otherwise they will keep mismatching (that was my issue, apparently slightly different from yours)

Link to comment
Share on other sites

still not an issue untill PaymentReturn hook because its order status remains as it is untill orderConfirmation hook call and payment validation performs before the PaymentReturn hook so. but yes if you want to order with out of stock product then PaymentModule class validation method creates problem. can you tell me in detail what actually want to do.its my pleasure if I can help you anyway.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...