Jump to content

Order status update - How can it have the order status to be update on its own after a certain date?


Recommended Posts

Hello everyone !


I'm quite new in prestashop development and i'm trying to do something that's not quite easy to me. 

I'm looking for a way to have the order status to be update automatically at a certain date. 


Trying to be clear : 

- We are using an addon to manage rental of the products.

- There is a "supposed date of return".

- I want that 36h before that date, the system change the order status to a new one i created. 


I thought about overriding the OrderHistory class like below but i feel i'm way to far from doing the right thing. 

Any ideas to help me ? Thanks a lot ! 

class OrderHistory extends OrderHistoryCore
    public function changeIdOrderState($new_order_state, $id_order, $use_existing_payment = false)

/*Changes made by the rental module developers */
		parent::changeIdOrderState($new_order_state, $id_order, $use_existing_payment);
		if((int)$id_order->id_cart > 0 ) {
			if($new_order_state == _PS_OS_PAYMENT_) {
			} else {

/*My updates begin here*/
		$today = date();
		$alert_dt = ($dpr_dt-2160);
		$current_order_state = $order->getCurrentOrderState();

		if($today == $alert_dt) {
			// Create new OrderHistory
			$history = new OrderHistory();
			$history->id_order = $order->id;
			$history->id_employee = (int)$this->context->employee->id;

			$use_existings_payment = false;
			if (!$order->hasInvoice()) {
					$use_existings_payment = true;
			$history->changeIdOrderState((18)$order_state->id, $order, $use_existings_payment);

			$carrier = new Carrier($order->id_carrier, $order->id_lang);
			$templateVars = array();
			if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) {
					$templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));

			// Save all changes
			if ($history->addWithemail(true, $templateVars)) {
					// synchronizes quantities if needed..
					if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
							foreach ($order->getProducts() as $product) {
									if (StockAvailable::dependsOnStock($product['product_id'])) {
											StockAvailable::synchronize($product['product_id'], (int)$product['id_shop']);


			$this->errors[] = Tools::displayError('An error occurred while changing order status, or we were unable to send an email to the customer.');


id of custom status is 18

$dpr_dt is date when the product is supposed to be returned by the client. 


PS: First time i post in that forum, not sure if i did it correctly :/ 

Share this post

Link to post
Share on other sites



You can use this module https://www.prestashop.com/forums/topic/559310-free-module-order-status-notice-product-private-url/

you will need to change it a bit by adding update condition based on date.


Thanks for your answer but it doesn't suit my needs. I would have to manually change the status. And that's exactly what i don't want to have to do. 

Share this post

Link to post
Share on other sites

  • 8 months later...

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More