How To Change An Order Status With A PHP Script In Prestashop

How To Change An Order Status With A PHP Script In Prestashop

Here is a nice PHP code for you to easily change the status of an order in your Presta store.

For example, you want to change the order with id 1 to the status with id 3:



17 comments

  1. Hi! i need this trick! Which file i need to edit? (classes/… ? )
    I need to make ALL orders, paid by paypal, check and others.. ALWAYS in : “waiting approval” so then i will change in others status i made.

    ex. I buy and pay with paypal (or on delivery), the order MUST to be in “waiting approval”, or how i will rename it, and then i will change in “in progress” etc… Usually the new orders, are in “working”. I don’t want that!

    Thanks!

  2. Simon,

    The article describes how to change the order status with the help of the hook hookOrderConfirmation.

    Therefore, first you need to create a module which would use it. The order status is defined by the
    payment module which customer used when making the purchase. For instance, for the payment
    module bankwire the status will be saved in the constant Configuration::get(‘PS_OS_BANKWIRE’). While when paying by cheque it will be saved in Configuration::get(‘PS_OS_CHEQUE’)

  3. Hi Alex

    I can’t find the php file to modify according your tip.
    I have PS 1.5.4.0
    Are you so glad to give me the pattern to find this file?
    eg. root/…/…/file.php

    Thanks in advance

  4. Stefano,

    It is meant here that you need to create a module to use the hook ‘OrderConfirmation’

  5. In your order confirm script, first include the prestashop framework:

    include_once(dirname(__FILE__).’/../../config/config.inc.php’);
    include_once(dirname(__FILE__).’/../../init.php’);

  6. Thomas, what version do you mean as in 1.5.х changeIdOrderState() function is enough.

  7. Hi Alex,

    Tnks!

    The function changes the order status but no order history.

    Do you know how to also change the order history?

  8. Davis,

    What are you talking about exactly? Changes in the order history are also saving, because we use OrderHistory class.

  9. Hi Alex,

    Do you know if it’s possible to setup an automatic status change, ie once an order id is set to shipped – it automatically changes to ‘delivered’ after something like 3-4 days? If so, how would you propose it could be done?

    Many Thanks,
    Joel

  10. Joel, sure this is possible. I would recommend you to use Cron for this purpose, and you can find a sample code in the article (in the example of changing order status #1).

  11. Hi,
    I try your code, it works perfectly, thanks!

    But it seems that the email for with this status is not send.
    Do you know how to send this email.

    Thanks.

  12. Cesari,

    The class OrderHistory has a specific method for that:

  13. Hi. is it possible use this in a cronjob? like setting a time rule (for orders made after 5 days , for example)
    could you please give us how to do it? thanks

Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *