Websites and applications

Change an order's status according to the payment method in PrestaShop

Reviewed on 7 min read orders PrestaShop

In PrestaShop, each payment module decides which status the order gets when it is confirmed. For example, with cash on delivery it is left as "Awaiting Cash On Delivery validation" and with bank transfer as "Awaiting bank wire payment". If you want it to come in with a different status, you need to change the second argument of the validateOrder() call in the payment module.

If all you want is to change the name, the colour or the email that is sent, you do not need to touch any code: edit the status in Orders > Statuses.

Where the status is set

It is in the controllers/front/validation.php file of each payment module:

Module File Status it assigns
Cash on delivery modules/ps_cashondelivery/controllers/front/validation.php PS_OS_COD_VALIDATION (in 1.x versions of the module, PS_OS_PREPARATION)
Bank transfer modules/ps_wirepayment/controllers/front/validation.php PS_OS_BANKWIRE
Cheque modules/ps_checkpayment/controllers/front/validation.php PS_OS_CHEQUE

Inside you will see a call like this one (cash on delivery module 2.x and 3.x):

$this->module->validateOrder(
    (int) $this->context->cart->id,
    (int) Configuration::getGlobalValue(Ps_Cashondelivery::CONFIG_OS_CASH_ON_DELIVERY),
    (float) $this->context->cart->getOrderTotal(true, Cart::BOTH),
    $this->module->displayName,
    null,
    [],
    (int) $this->context->currency->id,
    false,
    $customer->secure_key
);

The second argument is the status. CONFIG_OS_CASH_ON_DELIVERY is equivalent to PS_OS_COD_VALIDATION. For the order to come in as, for example, "Processing in progress", that argument must be (int) Configuration::get('PS_OS_PREPARATION').

These are the statuses that come with PrestaShop:

Key Status
PS_OS_CHEQUE Awaiting check payment
PS_OS_PAYMENT Payment accepted
PS_OS_PREPARATION Processing in progress
PS_OS_SHIPPING Shipped
PS_OS_DELIVERED Delivered
PS_OS_CANCELED Canceled
PS_OS_REFUND Refunded
PS_OS_ERROR Payment error
PS_OS_OUTOFSTOCK_PAID (or PS_OS_OUTOFSTOCK) On backorder (paid)
PS_OS_OUTOFSTOCK_UNPAID On backorder (not paid)
PS_OS_BANKWIRE Awaiting bank wire payment
PS_OS_WS_PAYMENT Remote payment accepted
PS_OS_COD_VALIDATION Awaiting Cash On Delivery validation

Bear in mind that a status marked as paid (for example PS_OS_PAYMENT) makes PrestaShop generate the invoice and count the order as paid. For cash on delivery or bank transfer, the usual choice is PS_OS_PREPARATION or a status of your own.

If you have created your own status in Orders > Statuses, use its number, which appears in the ID column of the list: for example (int) 15.

If you edit the module's file directly, the change is lost the next time you update the module. From PrestaShop 1.7 you can overwrite the module's controller with an override, which stays outside the module's folder.

For the cash on delivery module, create the file override/modules/ps_cashondelivery/controllers/front/validation.php with this content:

<?php

class Ps_CashondeliveryValidationModuleFrontControllerOverride extends Ps_CashondeliveryValidationModuleFrontController
{
    public function postProcess()
    {
        $cart = $this->context->cart;
        $orderStep1 = $this->context->link->getPageLink('order', true, (int) $this->context->language->id, ['step' => 1]);

        if (!Validate::isLoadedObject($cart) || !$cart->id_customer || !$cart->id_address_delivery || !$cart->id_address_invoice || $cart->isVirtualCart()) {
            Tools::redirect($orderStep1);
        }

        $customer = new Customer($cart->id_customer);
        if (!Validate::isLoadedObject($customer)) {
            Tools::redirect($orderStep1);
        }

        $this->module->validateOrder(
            (int) $cart->id,
            (int) Configuration::get('PS_OS_PREPARATION'), // Status the order comes in with
            (float) $cart->getOrderTotal(true, Cart::BOTH),
            $this->module->displayName,
            null,
            [],
            (int) $this->context->currency->id,
            false,
            $customer->secure_key
        );

        Tools::redirect($this->context->link->getPageLink('order-confirmation', true, (int) $this->context->language->id, [
            'id_cart' => (int) $cart->id,
            'id_module' => (int) $this->module->id,
            'id_order' => (int) $this->module->currentOrder,
            'key' => $customer->secure_key,
        ]));
    }
}

Change PS_OS_PREPARATION to the key of the status you want. Then:

  1. Check that in Advanced Parameters > Performance the Disable all overrides option is set to No.
  2. Delete the file var/cache/prod/class_index.php (in PrestaShop 1.6, cache/class_index.php) or click Clear cache on that same screen, so that PrestaShop detects the override.

For bank transfer or cheque the procedure is the same: copy the module's validation.php to override/modules/<module>/controllers/front/validation.php, rename the class by adding Override at the end and make it extend the original one. Change only the status in the validateOrder() call. If the original controller uses private methods, copy them into your class as well, because they cannot be called from the override.

In PrestaShop 1.6

In 1.6 module controller overrides do not exist. Edit modules/cashondelivery/controllers/front/validation.php directly (or the one of the payment module you use) and change the second argument of validateOrder(), which in the cash on delivery module is Configuration::get('PS_OS_PREPARATION'). Make a note of the change: you will have to repeat it if you update the module.

Check that it works

Place a test order with that payment method and open the order in Orders > Orders: the new status must appear as the first status in the history. If the previous one still appears, clear the cache from step 2 again.

You may also find useful

Something wrong or out of date? Tell us and we will review it.