Iletait1maille Posted January 19, 2017 Share Posted January 19, 2017 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); require_once(_PS_MODULE_DIR_.'ipslocationadvanced/ipslocationadvanced.php'); if((int)$id_order->id_cart > 0 ) { IPSLocationAdvanced::changeReservationOrder(array('id_cart'=>(int)$id_order->id_cart),(int)$id_order->id); if($new_order_state == _PS_OS_PAYMENT_) { IPSLocationAdvanced::updateStatusReservation(array('id_order'=>$id_order->id),_IPS_STATUS_PAYMENT_); } else { IPSLocationAdvanced::updateStatusReservation(array('id_order'=>$id_order->id),_IPS_STATUS_RESERVE_); } } /*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']); } } } Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&vieworder&token='.$this->token); } $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 :/ Link to comment Share on other sites More sharing options...
Iletait1maille Posted January 19, 2017 Author Share Posted January 19, 2017 Hi, 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. Link to comment Share on other sites More sharing options...
William K. Posted September 27, 2017 Share Posted September 27, 2017 Hello, do you have an update on this (using ndiaga's module or without it), I want to accomplish something similar but i'm not sure about the best way to handle it. Thanks in advance. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now