Draq Posted February 1, 2013 Share Posted February 1, 2013 Hello all, is there some nice person, which can write me simple example of how to change order status with php script? I think that in PS is some function for this, but I am new to object programming in php. So would be someone so nice to show me hot to easily change status order with php? Thank you very much Link to comment Share on other sites More sharing options...
Alex Simonchik BelVG Posted February 1, 2013 Share Posted February 1, 2013 (edited) Hi, try some like this: public function hookOrderConfirmation($params) { .... $objOrder = $params['objOrder']; $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState((int)(Configuration::get($this->name.'_status_id')), (int)($objOrder->id)); .... } Regards Edited February 1, 2013 by Alexander Simonchik (see edit history) 4 Link to comment Share on other sites More sharing options...
Draq Posted February 1, 2013 Author Share Posted February 1, 2013 HI, many thanks. But I am little bit worse tahn i thought For example I want to change order with id 1 to status with id 3. What I must write? Thank you very much Link to comment Share on other sites More sharing options...
Alex Simonchik BelVG Posted February 1, 2013 Share Posted February 1, 2013 Some like that: $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 4 Link to comment Share on other sites More sharing options...
vekia Posted February 1, 2013 Share Posted February 1, 2013 Alexander solution works like a charm, so if it also works for you @Draq - please mark this topic as solved 1 Link to comment Share on other sites More sharing options...
Draq Posted February 1, 2013 Author Share Posted February 1, 2013 I am sory for disturbing you, but when I have code: <?php require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 echo 'done'; ?> It wortes me fatal error: Class 'ObjectModel' not found in C:\wamp\www\classes\order\Order.php on line 29 I have PS 1.5.0.17, Thank you so much! Link to comment Share on other sites More sharing options...
vekia Posted February 1, 2013 Share Posted February 1, 2013 which version of prestashop you use? Where you exactly insert code that you pasted? Link to comment Share on other sites More sharing options...
Draq Posted February 1, 2013 Author Share Posted February 1, 2013 I have prestashop 1.5.0.17 and this code i have in locallhost/expcp/script.php and prestashop is instaled on root of loacalhost Link to comment Share on other sites More sharing options...
Alex Simonchik BelVG Posted February 4, 2013 Share Posted February 4, 2013 Hi, you need require next: require(dirname(__FILE__).'/config/config.inc.php'); instead of require classes. Regards Link to comment Share on other sites More sharing options...
expmedia-Christian Posted July 4, 2013 Share Posted July 4, 2013 (edited) Hello, I'm working on a Prestashop for a friend. This code works like a charm for me. It sets the Order-Status perfectly! I only got one Problem, my friend wants the automated eMail which is send if you switch the status in the Backend to be send via my Script too... so if I for example set the order status to 4, it should send out an eMail that the article was given to delivery! Can you help me somehow? Right now my code looks like this: require('../config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; $objOrder = new Order($_GET["order"]); //order with id=$_GET["action"] $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState($_GET["status"], (int)($objOrder->id)); //order status=4 $statusmeldung = '<h1 style="background: rgb(255,0,0); margin-top: 214px;">ORDER ID '.$_GET["order"].' auf Status '.$_GET["status"].' gesetzt!</h1>'; Thanks in advance -Christian Edited July 4, 2013 by expmedia-Christian (see edit history) Link to comment Share on other sites More sharing options...
Alex Simonchik BelVG Posted July 5, 2013 Share Posted July 5, 2013 Hi Christian, take a look "Orders -> Statuses" at your backend, there is the place where you can choose email template for order status http://clip2net.com/clip/m226647/1373006904-clip-73kb.png Regards 1 Link to comment Share on other sites More sharing options...
vekia Posted July 5, 2013 Share Posted July 5, 2013 that's right Alex has got absolutely right, when you use default classes and script to change order status - then email will be automatically send, just turn it on under the page that Alex suggested i've noticed (from your code) that you use default classes (in this case order history & order classes) so it will work for you (hope you use ps 1.5) 1 Link to comment Share on other sites More sharing options...
expmedia-Christian Posted July 5, 2013 Share Posted July 5, 2013 Hi, thanks for your help! Yes we use Prestashop 1.5.4.1. The eMail in the status is set, here are some screenshots. Here's how the order looks if I set it to status 4 via my external script: There's this missing: But the order itself is on Status 4 ... I guess that's why there's no eMail going out? Link to comment Share on other sites More sharing options...
vekia Posted July 6, 2013 Share Posted July 6, 2013 and when you change the order status in the back office - everything works well? Link to comment Share on other sites More sharing options...
expmedia-Christian Posted July 8, 2013 Share Posted July 8, 2013 Yes, if I change it in the back office it works. Link to comment Share on other sites More sharing options...
expmedia-Christian Posted July 13, 2013 Share Posted July 13, 2013 Yes, if I change it in the back office it works. And that's the issue, it should work with the external script too, is there any possiblity to get this working? Link to comment Share on other sites More sharing options...
PatrickJose Posted September 8, 2013 Share Posted September 8, 2013 How can I implement this functionality right after when I add the tracking number? For example, I add the tracking number and it change the order status to shipped. Thanks! Link to comment Share on other sites More sharing options...
christian123 Posted September 23, 2013 Share Posted September 23, 2013 Hello, I'm working on a Prestashop for a friend. This code works like a charm for me. It sets the Order-Status perfectly! I only got one Problem, my friend wants the automated eMail which is send if you switch the status in the Backend to be send via my Script too... so if I for example set the order status to 4, it should send out an eMail that the article was given to delivery! Can you help me somehow? Right now my code looks like this: require('../config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; $objOrder = new Order($_GET["order"]); //order with id=$_GET["action"] $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState($_GET["status"], (int)($objOrder->id)); //order status=4 $statusmeldung = '<h1 style="background: rgb(255,0,0); margin-top: 214px;">ORDER ID '.$_GET["order"].' auf Status '.$_GET["status"].' gesetzt!</h1>'; Thanks in advance-Christian hi am trying to make some trick, i want to change the order status with the Order and OrderHistory classes from the PS at another php module different to the PS, am using the 1.5.4.1 Version already, the issues is than when am going to require require('../config/config.inc.php'); for those lines $context->shop = Shop::initialize(); define('_THEME_NAME_', $context->shop->getTheme()); define('__PS_BASE_URI__', $context->shop->getBaseURI()); i can't do nothing, thats redirecting me to the official frontend WS where's been the Prestashop site please if some budy can provide some fix i realy appreciate it Link to comment Share on other sites More sharing options...
Alex Simonchik BelVG Posted September 24, 2013 Share Posted September 24, 2013 Hi christian, in my opinion the best idea is create a custom module for prestashop and make some API for changing Order state Regards Link to comment Share on other sites More sharing options...
seb776 Posted April 8, 2014 Share Posted April 8, 2014 (edited) Thanks Alexander Simonchik. I think we should have a nicer api like $order->addHistory($order_state_id); Don't you think ? Edited April 8, 2014 by seb776 (see edit history) Link to comment Share on other sites More sharing options...
Alex Simonchik BelVG Posted April 9, 2014 Share Posted April 9, 2014 Hi seb776, different version of PrestaShop has some differences, so if your solution is work, you can inform your version Regards Link to comment Share on other sites More sharing options...
magnetique Posted June 17, 2014 Share Posted June 17, 2014 And that's the issue, it should work with the external script too, is there any possiblity to get this working? I know it is an old thread but I'm in the same situation, the order status has been changed, but the emails were not sent. I found solution to the Alex original code: $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 just add this at the end: $history->addWithemail(true); in my PS version 1.4.10 it works perfectly 1 Link to comment Share on other sites More sharing options...
MisterMAD Posted July 15, 2014 Share Posted July 15, 2014 Hello, I can not run the script on my site, I have prestashop 1.5.6.2, I tried to update an order but the script is as if they were empty, I forget something? <?php echo "<center><h1>Aggiorna Ordine</h1></center>"; require('../web2014/config/config.inc.php'); require('../web2014/classes/order/Order.php'); require('../web2014/classes/order/OrderHistory.php'); $objOrder = new Order(14203883); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(4, (int)($objOrder->id)); //order status=3 ?> Link to comment Share on other sites More sharing options...
vekia Posted July 15, 2014 Share Posted July 15, 2014 hello turn on error reporting in your shop does this script spawn some errors then? Link to comment Share on other sites More sharing options...
MisterMAD Posted July 16, 2014 Share Posted July 16, 2014 Ciao, questo è l'errore : Fatal error: Cannot redeclare class OrderCore in /var/www/vhosts/mysite.it/httpdocs/web2014/classes/order/Order.php on line 1967 Ho aperto Order.php, ma il rigo 1967, corrisponde a fondo pagina, non riesco ad individuare la problematica. Link to comment Share on other sites More sharing options...
MisterMAD Posted July 18, 2014 Share Posted July 18, 2014 Nessuno riesce ad aiutarmi ? Link to comment Share on other sites More sharing options...
MisterMAD Posted July 20, 2014 Share Posted July 20, 2014 up Link to comment Share on other sites More sharing options...
vekia Posted July 20, 2014 Share Posted July 20, 2014 please use english language here, we are in english section not everyone knows italian, this is why no replies here. Link to comment Share on other sites More sharing options...
MisterMAD Posted July 23, 2014 Share Posted July 23, 2014 Here is the error that I get Fatal error : Cannot redeclare classe OrderCore in / var/www/vhosts/mysite.it/httpdocs/web2014/classes/order/Order.php on line 1967 I opened order.php, but the line 1967 corresponds to the bottom of the page, I can not identify the problem. Please help me Link to comment Share on other sites More sharing options...
OliB Posted July 23, 2014 Share Posted July 23, 2014 Sounds like an Override for this php File makes some problems. Is there a file in ../override/classes/order/order.php ? Link to comment Share on other sites More sharing options...
MisterMAD Posted July 25, 2014 Share Posted July 25, 2014 I checked in / override / classes / order / there is only one OrderPayment.php ... The'm trying them all but I can not understand why I get this error ... Link to comment Share on other sites More sharing options...
MisterMAD Posted July 28, 2014 Share Posted July 28, 2014 help Link to comment Share on other sites More sharing options...
rugydp Posted August 12, 2014 Share Posted August 12, 2014 I have the exact same Problem. Either I try: $history = new OrderHistory(); $history->id_order = (int)$id; $history->changeIdOrderState((int)$this->ID_ORDER_STATE_EXPORTED, $history->id_order); $history->addWithemail(); $history->save(); or $order = new Order($id); $order->setCurrentState($this->ID_ORDER_STATE_EXPORTED); I get the error: Cannot redeclare class OrderCore in [...]/classes/order/Order.php on line 2068 The error is triggered by $order->setCurrentState and by $history->changeIdOrderState. The object/instances are created without any problems. Only calling the functions/methods does not work. What am I doing wrong? Thanks Link to comment Share on other sites More sharing options...
vekia Posted August 12, 2014 Share Posted August 12, 2014 errors like that appear usually when library was attached before somewhere else usually it's related to modules that attach order class do you use some not default payment modules? Link to comment Share on other sites More sharing options...
rugydp Posted August 12, 2014 Share Posted August 12, 2014 (edited) errors like that appear usually when library was attached before somewhere else usually it's related to modules that attach order class do you use some not default payment modules? Thanks, vekia. Actually I'm developing a module to export orders as an xml file and change the state accordingly. I don't include or attach or redeclare the class in my module as I assume PrestaShop includes its core classes as needed. I instantiate Order objects without any problems, only when I call the $xxxx->setCurrentState() function it fails with mentioned error message. Do I miss some basic concept of PrestaShop development? Can't I use core classes for module development like using an API? UPDATE: I solved it. I had a line where I asked for an array of order states with a given state like: $orderIDs = OrderCore::getOrderIdsByStatus($this->ID_ORDER_STATE_PAYED); I changed it to: $orderIDs = Order::getOrderIdsByStatus($this->ID_ORDER_STATE_PAYED); and now it works. I really missed some kind of basic concept here. I still would appreciate some advise on when using SomeclassCore and when to use just Someclass. Any comments? Thanx anyways. Edited August 12, 2014 by rugydp (see edit history) Link to comment Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 25, 2014 Share Posted August 25, 2014 Hello, I have a Prestashop 1.6.0.6 version. I try this code but the order status did not change. I did not receive any error. Someone know how do it on Prestashop 1.6 version? Thanks. Link to comment Share on other sites More sharing options...
rugydp Posted August 26, 2014 Share Posted August 26, 2014 Hello, I have a Prestashop 1.6.0.6 version. I try this code but the order status did not change. I did not receive any error. Someone know how do it on Prestashop 1.6 version? Thanks. Which code did you try? If you want to change a state of the order programatically, you need to create an order object with the id of the order and then set the current state with the order state id. These two lines should do the trick. $order = new Order($id_order); $order->setCurrentState($id_order_state); Link to comment Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 26, 2014 Share Posted August 26, 2014 (edited) Hello, I used the following code and don't work. require_once('../config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; $objOrder = new Order($id_order); $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); I tryed as you suggest but nothing change. require_once('../config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; $order = new Order($id_order); $order->setCurrentState(3); Edited August 26, 2014 by ItalianBoutiqueShoes (see edit history) Link to comment Share on other sites More sharing options...
rugydp Posted August 26, 2014 Share Posted August 26, 2014 Did you actually try to replace the $id_order variable with an existing ID of an order? You shouldn't need to include the classes as the line require_once(dirname(__FILE__).'/../../config/config.inc.php'); does the job. In modules context I hat to include it with ../../ to get it working. What exactly are you trying to do? Regards, Link to comment Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 26, 2014 Share Posted August 26, 2014 My interelly code is the follow $id_order = 3; require_once('../config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; $order = new Order($id_order); $order->setCurrentState(3); So, yes the $id_order variable is set. This code is on a file on the admin folder. If I change the path I receive the following error so the classes are well included Warning: require_once(/config/config.inc.php) [function.require-once]: failed to open stream: No such file or directory in xxx on line 13 Fatal error: require_once() [function.require]: Failed opening required '/config/config.inc.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in xxx on line 13 Link to comment Share on other sites More sharing options...
rugydp Posted August 26, 2014 Share Posted August 26, 2014 Okay, so your path is all right. It should actually change the order's state to 3. I'm afraid have no idea, why it shouldn't work. Sorry. Link to comment Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 26, 2014 Share Posted August 26, 2014 No problem, I hope someone else will be able to help me. Kind regards Daniele Link to comment Share on other sites More sharing options...
vekia Posted August 26, 2014 Share Posted August 26, 2014 where is your .php file located? it looks like path to config what you use is wrong this is why i asked about location of your .php file Link to comment Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 26, 2014 Share Posted August 26, 2014 It is on admin folder. Link to comment Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 29, 2014 Share Posted August 29, 2014 (edited) I found a solution: it work like this: you need to require only config.inc.pho file. I hope it send also email confirmation. It is for version 1.6 and 1.5 I think. $id_order = 3; require_once('../config/config.inc.php'); //require_once '../classes/order/Order.php'; //require_once '../classes/order/OrderHistory.php'; $order = new Order($id_order); $order->setCurrentState(3); Edited August 29, 2014 by ItalianBoutiqueShoes (see edit history) 3 Link to comment Share on other sites More sharing options...
itx Posted August 30, 2014 Share Posted August 30, 2014 I found a solution: it work like this: you need to require only config.inc.pho file. I hope it send also email confirmation. It is for version 1.6 and 1.5 I think. $id_order = 3; require_once('../config/config.inc.php'); //require_once '../classes/order/Order.php'; //require_once '../classes/order/OrderHistory.php'; $order = new Order($id_order); $order->setCurrentState(3); This one is the only solution works for me. The previous solution using changeIdOrderState function didn't work for me. The function only change $order->current_state and not changing $order->id_order_state. Link to comment Share on other sites More sharing options...
ItalianBoutiqueShoes Posted September 1, 2014 Share Posted September 1, 2014 I confirm that the following code will also send emails when setted properly. require_once('../config/config.inc.php'); $order = new Order($id_order); $order->setCurrentState(3); 1 Link to comment Share on other sites More sharing options...
pneumon1c Posted September 2, 2014 Share Posted September 2, 2014 (edited) Hi Community !! I try the same, but the order state doesn't change. I'm using 1.4.7. Could this be the problem? I know the Classes are directly in directory "classes" not "classes/order". Do you know a working solution for 1.4.7 ? Thanks for your help! thats my code: public function hookOrderConfirmation($status,$orderid) { require('../config/config.inc.php'); require_once '../classes/Order.php'; require_once '../classes/OrderHistory.php'; $objOrder = new Order($orderid); $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState($status, (int)($objOrder->id)); } Edited September 2, 2014 by pneumon1c (see edit history) Link to comment Share on other sites More sharing options...
limonaderose Posted October 21, 2014 Share Posted October 21, 2014 Hi,I'm quite new to prestashop too...I'm running this on my local host. When it runs, it loads my homepage and do nothing. Any clue? I use this code on prestashop 1.6.0.8: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <title>Page de gestion des envois : echo</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php require(dirname(__FILE__).'/../config/config.inc.php'); //require('../prestashop/config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 echo 'done'; ?> </body></html> Link to comment Share on other sites More sharing options...
vekia Posted October 22, 2014 Share Posted October 22, 2014 what ps version? Link to comment Share on other sites More sharing options...
limonaderose Posted October 22, 2014 Share Posted October 22, 2014 I use this code on prestashop 1.6.0.8: Link to comment Share on other sites More sharing options...
vekia Posted October 22, 2014 Share Posted October 22, 2014 can you show what code: $history->changeIdOrderState(3, (int)($objOrder->id)); returns? use it in print_r(); print_r($history->changeIdOrderState(3, (int)($objOrder->id))); Link to comment Share on other sites More sharing options...
limonaderose Posted October 22, 2014 Share Posted October 22, 2014 It can not return anyting since the first line: require(dirname(__FILE__).'/../prestashop/config/config.inc.php'); brings me directly to http://127.0.0.1/prestashop/en/ The problem is coming from require and include, but I'cant understand... Link to comment Share on other sites More sharing options...
limonaderose Posted October 23, 2014 Share Posted October 23, 2014 Actually, I'm wondering if I can simply change it in the database that way: Will it mess with prestashop or is it doing the job? $db-> exec("UPDATE ps_orders SET current_state = 4 WHERE id_order = $id_comm"); date_default_timezone_set('America/Montreal'); $date_stat=date("Y-m-d H:i:s"); $upt_st= $db->prepare('INSERT INTO ps_order_history(id_order, id_order_state, date_add) VALUES(?, ?, ?)'); $upt_st->execute(array($id_comm, 4, $date_stat)); Link to comment Share on other sites More sharing options...
Rineez Posted October 25, 2014 Share Posted October 25, 2014 I recommend to use: $order = new Order($id_order); $order->setCurrentState($id_order_state); rather than using OrderHistory class directly which also works, but does not send emails even if the new status is configured in the back office to trigger emails : $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState($status, (int)($objOrder->id)); If you look inside the code for Order::setCurrentState() method (in Prestashop 1.5) you can see that it executes almost the same above code with OrderHistory class plus some more code. This additional code does an update action on the order itself, and executes OrderHistory::addWithemail() method, which also ensures the email notification will be sent for status change. Link to comment Share on other sites More sharing options...
Rineez Posted October 25, 2014 Share Posted October 25, 2014 Actually, I'm wondering if I can simply change it in the database that way: Will it mess with prestashop or is it doing the job? $db-> exec("UPDATE ps_orders SET current_state = 4 WHERE id_order = $id_comm"); date_default_timezone_set('America/Montreal'); $date_stat=date("Y-m-d H:i:s"); $upt_st= $db->prepare('INSERT INTO ps_order_history(id_order, id_order_state, date_add) VALUES(?, ?, ?)'); $upt_st->execute(array($id_comm, 4, $date_stat)); This is definitely not a good idea in my opinion. Do this only if you really know what you are doing. Because, you will be breaking/bypassing the whole hook systems available in Prestashop by doing it like this. That means you will loose a lot of nice features available to configure in backoffice. Email notifications for status change is just one example. You will definitely end up writing lot more customization code if you take a path like this. Don't reinvent the wheels. If you want to get the maximum benefit of using prestashop, use the core classes as much as possible. 1 Link to comment Share on other sites More sharing options...
limonaderose Posted October 27, 2014 Share Posted October 27, 2014 Thanks for your opinion. Do you know what's wrong with these line: require(dirname(__FILE__).'/../config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; Link to comment Share on other sites More sharing options...
limonaderose Posted October 27, 2014 Share Posted October 27, 2014 Apparently they are the one not working: after reading the first line, it opens my home page and the rest of the script is not read. Link to comment Share on other sites More sharing options...
Rineez Posted October 27, 2014 Share Posted October 27, 2014 (edited) Thanks for your opinion. Do you know what's wrong with these line: require(dirname(__FILE__).'/../config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; I can't say anything for sure because you have given relative paths. The correctness of these lines depends on where you have written this code. Where have you placed the file with these lines? Edited October 27, 2014 by Rineez (see edit history) Link to comment Share on other sites More sharing options...
limonaderose Posted October 27, 2014 Share Posted October 27, 2014 Working now! For information: The relative path was set correctly but I change with the complete path of the file from C: and it was still loading the homepage. I then move my code in the same folder than config.php and it was not loading the homepage anymore. Finally I kept: require('C:\xampp\htdocs/prestashop/config/config.inc.php'); and removed the require to Order.php and OrderHistory.php. and it worked. Thanks for your help everybody! Link to comment Share on other sites More sharing options...
limonaderose Posted October 27, 2014 Share Posted October 27, 2014 But do you know why my code need to be in the same folder than config.php to work? Link to comment Share on other sites More sharing options...
clawzee Posted November 6, 2014 Share Posted November 6, 2014 (edited) I know it is an old thread but I'm in the same situation, the order status has been changed, but the emails were not sent. I found solution to the Alex original code: $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 just add this at the end: $history->addWithemail(true); in my PS version 1.4.10 it works perfectly The code works fine and even sends the notification email. But the generated PDF attached to the email has some warnings like those shown below. Can someone tell me how should I get rid of these? Thank you in advance! Warning: include(/presta/translations/en/pdf.php): failed to open stream: No such file or directory in /presta/classes/Translate.php on line 214 Warning: include(): Failed opening '/presta/translations/en/pdf.php' for inclusion (include_path='/presta/tools/htmlpurifier/standalone:.:/usr/lib/php:/usr/local/lib/php') in /presta/classes/Translate.php on line 214 Edited November 6, 2014 by clawzee (see edit history) Link to comment Share on other sites More sharing options...
tuk66 Posted November 7, 2014 Share Posted November 7, 2014 English translations no longer exist in the /translations/en folder (in PS 1.6). Link to comment Share on other sites More sharing options...
Turtle Wet Sports Posted September 29, 2015 Share Posted September 29, 2015 I confirm that the following code will also send emails when setted properly. require_once('../config/config.inc.php'); $order = new Order($id_order); $order->setCurrentState(3); Hi everybody ! I tried a bunch of propositions here and nothing helps : as soon as I put require('../config/config.inc.php'); in my script, it stops here, doing nothing with no error and no warning.. My script is on the admin directory.. PS version 1.6.1 Any idea ? Link to comment Share on other sites More sharing options...
yaso Posted October 6, 2015 Share Posted October 6, 2015 Hello everyone I know it is a bit old thread but seemed to be close to my problem. I'm running php script to read xml file. From that xml file i'm getting order id and tracking code for the order. The script updates the tracking code into database and changes the orderstatus afterwards. Now the problem is that when the script changes the order status, it does send the shipping email to customer but the shipping email is not working correctly. The shipping email is missing the "{followup}"(trackingcode/url) information if i change the status by my script. But if i run the script without changing the status, and change the status manually from BO the shipping email now has the working {followup} information from database. Any ideas why this is happening if i change the orderstatus from script instead of BO?P.s Tried changing the status with setCurrentState and changeIdOrderState, with no difference in end result. Link to comment Share on other sites More sharing options...
deech123 Posted October 16, 2015 Share Posted October 16, 2015 @yaso, every time you change something on your carrier, the system makes a new carrier with new ID. I think also that this is not a good way prestashop handles changes to carriers. if you look at your db and table carriers, you will see you will have one extra after each change ;-) so make a new test order, and test your script, it will work ;-) D. Link to comment Share on other sites More sharing options...
Totti Posted October 19, 2015 Share Posted October 19, 2015 Also I had done this in the past (at least for me) bug. Link to comment Share on other sites More sharing options...
jalloun Posted November 24, 2015 Share Posted November 24, 2015 (edited) works like a charm, thank you alex. Im using ps 1.6.0.14 Edited November 24, 2015 by jalloun (see edit history) Link to comment Share on other sites More sharing options...
lovemyseo Posted June 10, 2016 Share Posted June 10, 2016 When I tried to change order status as customer are not getting emails when order status is changed I got this error Hi I just updated my shop to PS 1.6.1.5 and tried to change the order status like to go Order--> status and tried to mark few fields I got this error An error occurred while updating an object. order_state (Unknown column 'pdf_delivery' in 'field list') Not sure what is the issue Installing old version of mail alerts can help me? Please respond asap Link to comment Share on other sites More sharing options...
imms12 Posted June 10, 2016 Share Posted June 10, 2016 hi.. I am having some problems with my prestashop and i need some expert to help me.. for which I can pay.. not much but I will. Anyone inerested please email me on [email protected] or message me on whatsapp at +923343515883 Thanks Link to comment Share on other sites More sharing options...
tuk66 Posted June 11, 2016 Share Posted June 11, 2016 When I tried to change order status as customer are not getting emails when order status is changed I got this error Hi I just updated my shop to PS 1.6.1.5 and tried to change the order status like to go Order--> status and tried to mark few fields I got this error An error occurred while updating an object. order_state (Unknown column 'pdf_delivery' in 'field list') Not sure what is the issue Installing old version of mail alerts can help me? Please respond asap pdf_delivery is field in the ps_order_state table. Check this table. You should see 14 fields. Link to comment Share on other sites More sharing options...
m.schambion Posted October 17, 2016 Share Posted October 17, 2016 Hello everybody, I read the whole thread but were not able to found where to put the code if I need to change the status automatically after the order creation. Do I need to override the order class ? Thanks in advance. Mat. Link to comment Share on other sites More sharing options...
Liofey Posted February 28, 2017 Share Posted February 28, 2017 For prestashop 1.6.1.7 When I check into the code, it need additional code : This is works for me If you want save without send email $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 $history->add(true); If you want save with send email $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 $history->addWithemail(true); 3 Link to comment Share on other sites More sharing options...
[email protected] Posted February 28, 2017 Share Posted February 28, 2017 Hi, I have a script which is changing order status from external program^ but it is changing order status directly in the database. Can somebody help me to change the script in order to use native Prestashop status change? Here is my code: <? ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); include(dirname(__FILE__).'/config/config.inc.php'); $result = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'orders where date_add >= now() - INTERVAL 24 HOUR;'); if(isset($result) && !empty($result)){ foreach($result as $item){ if((int)$item['current_state']==5){continue;} $url=" XXXXXXXXX". "idOrder=".$item['shipping_number']. "&user=test". "&password=123456". "&cid=4541"; $mych = curl_init(); curl_setopt($mych, CURLOPT_URL, $url); curl_setopt($mych, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($mych, CURLOPT_HEADER, 0); $data = curl_exec($mych); curl_close($mych); /* echo "<pre>"; print_r($data); echo "</pre>";*/ $rez=""; if(isset($data) && !empty($data) && $data != 'null' ){ $rez = json_decode($data, true); switch ((int)$rez['status']){ case 3: Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET current_state = 1 WHERE shipping_number = '.$item["shipping_number"]); break; case 4: Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET current_state = 1 WHERE shipping_number = '.$item["shipping_number"]); break; case 5: Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET current_state = 1 WHERE shipping_number = '.$item["shipping_number"]); break; case 6: Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET current_state = 1 WHERE shipping_number = '.$item["shipping_number"]); break; case 7: Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET current_state = 1 WHERE shipping_number = '.$item["shipping_number"]); break; case 8: Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET current_state = 4 WHERE shipping_number = '.$item["shipping_number"]); break; default: Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'orders SET current_state = 3 WHERE shipping_number = '.$item["shipping_number"]); } }else{ /*Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'orders` SET `current_state` = 5 WHERE `shipping_number` = '.$item["shipping_number"]);*/ } } } echo 1; ?> Regards Suren Link to comment Share on other sites More sharing options...
santi_cb Posted June 28, 2017 Share Posted June 28, 2017 Hi! Firstly thank you for your codes, I try them and those work for me. I am trying to develop something to check the status ID and change it to other status. Any idea? Best regards! Link to comment Share on other sites More sharing options...
wouababelouba Posted August 2, 2017 Share Posted August 2, 2017 Bonjour, Ayant été confronté à cette problématique, voilà la solution qui a fonctionné (Presta v1.6.1.11) : $new_history = new OrderHistory(); $new_history->id_order = (int) $id_order; $new_history->id_order_state = (int) $mon_statut; $new_history->add(true); $new_history->save(); 1 Link to comment Share on other sites More sharing options...
col_vert Posted September 28, 2017 Share Posted September 28, 2017 Hey there ! This topic is quite old, but i see we still have the same requirements ! I would like to change the status of EVERY orders with status X, and apply them status Y. The code in this topic actually just change the status for order id = Z (one order only..) Hope you can help ! cheers Link to comment Share on other sites More sharing options...
col_vert Posted September 28, 2017 Share Posted September 28, 2017 (edited) the idea is to have a php file , and call it with cron tasks. Edited September 28, 2017 by col_vert (see edit history) Link to comment Share on other sites More sharing options...
RamonAlonso Posted December 11, 2017 Share Posted December 11, 2017 (edited) Hello. Here is how you can change the state of a group of orders from a cron task: DEFINE('TOKEN','123456'); if(!(isset($_REQUEST['token']) && $_REQUEST['token'] == TOKEN)) die('Access forbidden'); require_once('../config/config.inc.php'); DEFINE('ENVIO_CREADO_TOURLINE_EXPRESS', 30); DEFINE('ENVIADO', 4); DEFINE('PAGO_ACEPTADO', 2); DEFINE('PREPARACION_EN_PROCESO',3); DEFINE('ENTREGADO',5); DEFINE('CANCELADO', 6); // From /classes/order/Order.php // Marked as deprecated // getOrdersIdByDate($date_from, $date_to, $id_customer = null, $type = null) // getOrderIdsByStatus($id_order_state) foreach(Order::getOrderIdsByStatus(ENVIO_CREADO_TOURLINE_EXPRESS) as $order) { //echo 'Order n.: ' . $order . "\n"; $objOrder = new Order($order); $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(ENVIADO, (int)($objOrder->id)); //$history->addWithemail(true); $history->add(true); } echo 'Updated.'; I define the different states at the top. Later I search for the orders with the state I want to change and with a foreach I change the state to those orders. Please, note that getOrderIdsByStatus and getordersIdByDate (if you want to search by dates) are deprecated, but by now they work. I've tested with Presta 1.6.1.9 Write that code in a php file and add it to a cron task, for example http://mydomain.com/myscripts/change-order-state.php?token=123456 Remember to change token! Edited December 11, 2017 by RamonAlonso (see edit history) Link to comment Share on other sites More sharing options...
el_boda Posted September 17, 2018 Share Posted September 17, 2018 (edited) On 21/10/2014 at 10:09 PM, limonaderose said: Hi, I'm quite new to prestashop too... I'm running this on my local host. When it runs, it loads my homepage and do nothing. Any clue? I use this code on prestashop 1.6.0.8: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <title>Page de gestion des envois : echo</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php require(dirname(__FILE__).'/../config/config.inc.php'); //require('../prestashop/config/config.inc.php'); require_once '../classes/order/Order.php'; require_once '../classes/order/OrderHistory.php'; $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 echo 'done'; ?> </body> </html> Hello. Can anyone tell me, please, if this code can be used on PS 1.7.3.0 and if not what could be the changes. I confess my ignorance in this matter, but I'm looking for the code that can change the satus and send emails. Thank you. Edited September 17, 2018 by el_boda (see edit history) Link to comment Share on other sites More sharing options...
Gombidi Bilişim Posted April 2, 2019 Share Posted April 2, 2019 On 9/17/2018 at 6:43 PM, el_boda said: Hello. Can anyone tell me, please, if this code can be used on PS 1.7.3.0 and if not what could be the changes. I confess my ignorance in this matter, but I'm looking for the code that can change the satus and send emails. Thank you. Sorry for late, it worked on 1.7+ ;) Link to comment Share on other sites More sharing options...
dandumit Posted August 11, 2020 Share Posted August 11, 2020 Hello All, I am on presta 1.6 I am changing order state on a script , it works simply calling $order->setCurrentState(4,1); // I have added employee id as well $order->save(); Unfortunately it does not trigger hooks on order status update. Could you please suggest what to do to have triggered as well those hooks ? I have a trigger for example to send a SMS when order it's being sent. Thank you, DAniel Link to comment Share on other sites More sharing options...
kepwsian Posted December 30, 2020 Share Posted December 30, 2020 (edited) Dear All, presta 1.7.6.5 I would like to change order status from external file located: {Presta_Folder}/some_folder/someFile.php /*File source*/ <?php require('../config/config.inc.php'); $objOrder = new Order(1); //order with id=1 $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState(3, (int)($objOrder->id)); //order status=3 $history->addWithemail(); in general, the status change operation work, i mean Status has new value, but no e-mail have been sent - instead of this server responds err:500 it seems there is problem to acces to Mail.php, but maybe i am wrong. Have you any idea ? Serwer Logs: [Wed Dec 30 20:00:49 2020] [error] [client xxxx] request="GET / HTTP/1.1" pid=140466905475053 uid=3409069 gid=3409069 [Wed Dec 30 20:22:11 2020] [error] [client xxxxx] request="GET /Some_Folder/someFile.php?id_order=11 HTTP/1.1" pid=140466905431992 uid=3409069 gid=3409069 [Wed Dec 30 20:22:11 2020] [error] [client xxxx] PHP Fatal error: Uncaught Exception: Kernel Container is not available in {Presta_Folder} /src/Adapter/ContainerFinder.php:77\nStack trace:\n#0 {Presta_Folder} /classes/Tools.php(796): PrestaShop\\PrestaShop\\Adapter\\ContainerFinder->getContainer()\n#1 {Presta_Folder} /classes/Tools.php(773): ToolsCore::getContextLocale(Object(Context))\n#2 {Presta_Folder} /classes/order/OrderHistory.php(513): ToolsCore::displayPrice(85.6, Object(Currency), false)\n#3 {Presta_Folder} /classes/order/OrderHistory.php(468): OrderHistoryCore->sendEmail(Object(Order), false)\n#4 {Presta_Folder} /Some_Folder/ExternalChangeOrderId.php(16): OrderHistoryCore->addWithemail(true)\n#5 {main}\n thrown in {Presta_Folder} /src/Adapter/ContainerFinder.php on line 77 Edited December 30, 2020 by kepwsian (see edit history) Link to comment Share on other sites More sharing options...
metalines Posted January 12, 2022 Share Posted January 12, 2022 Hello, The solution provided above does work correctly, thank you very much! However, i hope someone can point me in the right direction with an error that has come up. If i change an order the order status 5 (delivered) it calls upon a module we have that sends a discount code to the customer during the process of updating order status. It throws the following error: (1/1) ClassNotFoundException Attempted to load class "LinevenHcomDiscount" from the global namespace. Did you forget a "use" statement? in Mail.php line 197 at LinevenHcomMail::sendMailsToCustomer(25138)in BackofficeOrderStatus.php line 28 at LinevenHcomAdminBackofficeOrderStatusController->updateAction()in Controller.php line 114 at LinevenHcomController->run('update')in homecomments.php line 307 at HomeComments->hookUpdateOrderStatus(array('newOrderStatus' => object(OrderState), 'id_order' => 25138, 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 2))in jprestaspeedpack.php line 2601 at Jprestaspeedpack::execHook('m', object(HomeComments), 'hookupdateOrderStatus', array('newOrderStatus' => object(OrderState), 'id_order' => 25138, 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 2))in Hook.php line 31 at Hook::coreCallHook(object(HomeComments), 'hookupdateOrderStatus', array('newOrderStatus' => object(OrderState), 'id_order' => 25138, 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 2))in Hook.php line 359 at HookCore::callHookOn(object(HomeComments), 'actionOrderStatusUpdate', array('newOrderStatus' => object(OrderState), 'id_order' => 25138, 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 2))in Hook.php line 907 at HookCore::exec('actionOrderStatusUpdate', array('newOrderStatus' => object(OrderState), 'id_order' => 25138, 'cookie' => object(Cookie), 'cart' => object(Cart), 'altern' => 2), null, false, true, false, '1')in OrderHistory.php line 107 at OrderHistoryCore->changeIdOrderState(5, 25138)in test.php line 165 I hope someone can help, i think i just need to include the module possibly but im not sure. Thanks in advance! Link to comment Share on other sites More sharing options...
GoPure Kratom Posted October 9, 2022 Share Posted October 9, 2022 (edited) I was able to make this code work, I got a couple of issues. I want to replicate the same functionality when an order is changed to Payment Accepted in the BO, which does changes to a few tables. When order status is changed to Payment Accepted in the BO, a new row is inserted to (at least) both ps_order_history and ps_order_invoice and the respective ps_orders entry is of course updated as well. While experimenting with this code, I noticed a strange thing: If include the $history->save(); - the row is created into ps_order_history , but not in ps_order_invoice If I comment the $history->save(); - the row is created into ps_order_invoice, but not in ps_order_history This seems super weird? Any ideas why this is happening? IMO both should be updated? Also, are there any other tables that should be updated explicitly than the ones mentioned above? I am also getting this error lot fo times: Notice: Trying to get property 'precision' of non-object in /home/816694.cloudwaysapps.com/xxxx/public_html/classes/Context.php on line 498 Fatal error: Uncaught TypeError: Argument 1 passed to PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision::getPrecision() must be of the type int, null given, called in /home/816694.cloudwaysapps.com/xxxx/public_html/classes/Context.php on line 498 and defined in /home/816694.cloudwaysapps.com/xxxx/public_html/src/Core/Localization/CLDR/ComputingPrecision.php:41 Stack trace: #0 /home/816694.cloudwaysapps.com/xxxx/public_html/classes/Context.php(498): PrestaShop\PrestaShop\Core\Localization\CLDR\ComputingPrecision->getPrecision() #1 /home/816694.cloudwaysapps.com/xxxx/public_html/classes/order/Order.php(1465): ContextCore->getComputingPrecision() #2 /home/816694.cloudwaysapps.com/xxxx/public_html/classes/order/Order.php(1353): OrderCore->setInvoiceDetails() #3 /home/816694.cloudwaysapps.com/xxxx/public_html/classes/order/OrderHistory.php(371): OrderCore->setInvoice() #4 /home/816694.cloudwaysapps.com/xxxx/public_html/yyyyyyyyy.php(13): OrderHistoryCore->changeIdOrderS in /home/816694.cloudwaysapps.com/xxxx/public_html/src/Core/Localization/CLDR/ComputingPrecision.php on line 41 Here's what I'm using (with 1.7.8.7): <?php require(dirname(__FILE__).'/config/config.inc.php'); echo 'Includes done'.'<br/>'; echo 'Order ID:'.$_GET["oid"].'<br/>'; echo 'Order Status:'.$_GET["status"].'<br/>'; $objOrder = new Order($_GET["oid"]); $history = new OrderHistory(); $history->id_order = (int)$objOrder->id; $history->changeIdOrderState($_GET["status"], (int)($objOrder->id)); //order status 2 = Payment Accepted //$history->addWithemail(true); $history->save(); ?> Edited October 9, 2022 by GoPure Kratom (see edit history) 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