Zagalux Posted March 28, 2020 Share Posted March 28, 2020 I'm trying to change the order status for all orders that have a specific order status, I have the code to change it but I don't know exactly how to load and go through all orders, like a foreach for example. I don't know if I should use a sql query for getting it and put it in an array or if there's any function in prestashop that allows me to verify every order that has a specific status id and use it in a function to change it. I'll add it to a cron job and run it every now and then... Thanks for your help Link to comment Share on other sites More sharing options...
Guest Posted March 28, 2020 Share Posted March 28, 2020 (edited) Change id order states: $current_order_state = 2; $new_order_state = 6; Uncomment $ history-> addWithemail () to send email to customer <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.inc.php'); include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.inc.php'); include(dirname(__FILE__) . '/init.php'); $current_order_state = 2; $new_order_state = 6; $get_orders_by_state = Db::getInstance()->ExecuteS('SELECT `current_state`, `id_order` FROM `'._DB_PREFIX_.'orders` WHERE `current_state` = '.$current_order_state.' ORDER BY `id_order`'); foreach ($get_orders_by_state as $orders) { $order = new Order($orders['id_order']); $history = new OrderHistory(); $history->id_order = (int)$order->id; $history->changeIdOrderState((int) $new_order_state, $order->id); /* send email */ /* $history->addWithemail(); */ $history->save(); } Edited March 28, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Zagalux Posted March 28, 2020 Author Share Posted March 28, 2020 5 hours ago, Guest said: Change id order states: $current_order_state = 2; $new_order_state = 6; Uncomment $ history-> addWithemail () to send email to customer <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.inc.php'); include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.inc.php'); include(dirname(__FILE__) . '/init.php'); $current_order_state = 2; $new_order_state = 6; $get_orders_by_state = Db::getInstance()->ExecuteS('SELECT `current_state`, `id_order` FROM `'._DB_PREFIX_.'orders` WHERE `current_state` = '.$current_order_state.' ORDER BY `id_order`'); foreach ($get_orders_by_state as $orders) { $order = new Order($orders['id_order']); $history = new OrderHistory(); $history->id_order = (int)$order->id; $history->changeIdOrderState((int) $new_order_state, $order->id); /* send email */ /* $history->addWithemail(); */ $history->save(); } Guest Thank you so much my friend! It worked like a charm!!! I'm quite new in prestashop and that just helped me a lot. Link to comment Share on other sites More sharing options...
Guest Posted March 28, 2020 Share Posted March 28, 2020 I gladly helped. 😉 Link to comment Share on other sites More sharing options...
renaud2263 Posted April 29, 2021 Share Posted April 29, 2021 Hello Daniel, i'm trying to execute your code to update the order history, but some orders are bugging with the fatal error : Quote Argument 1 passed to PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision::getPrecision() must be of the type int, null given, called in /homepages/21/d473697229/htdocs/mywebsite/classes/Context.php on line 467 and defined in /homepages/21/d473697229/htdocs/mywebsite/src/Core/Localization/CLDR/ComputingPrecision.php:41 and I really don't understand why. Do you have an idea ? Thanking you in advance. Renaud. 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