Draq Posted February 1, 2013 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 Share this post Link to post Share on other sites More sharing options...
Alex Simonchik BelVG Posted February 1, 2013 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 Share this post Link to post Share on other sites More sharing options...
Draq Posted February 1, 2013 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 Share this post Link to post Share on other sites More sharing options...
Alex Simonchik BelVG Posted February 1, 2013 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 3 Share this post Link to post Share on other sites More sharing options...
vekia Posted February 1, 2013 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 Share this post Link to post Share on other sites More sharing options...
Draq Posted February 1, 2013 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! Share this post Link to post Share on other sites More sharing options...
vekia Posted February 1, 2013 Posted February 1, 2013 which version of prestashop you use? Where you exactly insert code that you pasted? Share this post Link to post Share on other sites More sharing options...
Draq Posted February 1, 2013 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 Share this post Link to post Share on other sites More sharing options...
Alex Simonchik BelVG Posted February 4, 2013 Posted February 4, 2013 Hi, you need require next: require(dirname(__FILE__).'/config/config.inc.php'); instead of require classes. Regards Share this post Link to post Share on other sites More sharing options...
expmedia-Christian Posted July 4, 2013 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) Share this post Link to post Share on other sites More sharing options...
Alex Simonchik BelVG Posted July 5, 2013 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 Share this post Link to post Share on other sites More sharing options...
vekia Posted July 5, 2013 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 Share this post Link to post Share on other sites More sharing options...
expmedia-Christian Posted July 5, 2013 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? Share this post Link to post Share on other sites More sharing options...
vekia Posted July 6, 2013 Posted July 6, 2013 and when you change the order status in the back office - everything works well? Share this post Link to post Share on other sites More sharing options...
expmedia-Christian Posted July 8, 2013 Posted July 8, 2013 Yes, if I change it in the back office it works. Share this post Link to post Share on other sites More sharing options...
expmedia-Christian Posted July 13, 2013 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? Share this post Link to post Share on other sites More sharing options...
PatrickJose Posted September 8, 2013 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! Share this post Link to post Share on other sites More sharing options...
christian123 Posted September 23, 2013 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 Share this post Link to post Share on other sites More sharing options...
Alex Simonchik BelVG Posted September 24, 2013 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 Share this post Link to post Share on other sites More sharing options...
seb776 Posted April 8, 2014 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) Share this post Link to post Share on other sites More sharing options...
Alex Simonchik BelVG Posted April 9, 2014 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 Share this post Link to post Share on other sites More sharing options...
magnetique Posted June 17, 2014 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 Share this post Link to post Share on other sites More sharing options...
MisterMAD Posted July 15, 2014 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 ?> Share this post Link to post Share on other sites More sharing options...
vekia Posted July 15, 2014 Posted July 15, 2014 hello turn on error reporting in your shop does this script spawn some errors then? Share this post Link to post Share on other sites More sharing options...
MisterMAD Posted July 16, 2014 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. Share this post Link to post Share on other sites More sharing options...
MisterMAD Posted July 18, 2014 Posted July 18, 2014 Nessuno riesce ad aiutarmi ? Share this post Link to post Share on other sites More sharing options...
MisterMAD Posted July 20, 2014 Posted July 20, 2014 up Share this post Link to post Share on other sites More sharing options...
vekia Posted July 20, 2014 Posted July 20, 2014 please use english language here, we are in english section not everyone knows italian, this is why no replies here. Share this post Link to post Share on other sites More sharing options...
MisterMAD Posted July 23, 2014 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 Share this post Link to post Share on other sites More sharing options...
OliB Posted July 23, 2014 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 ? Share this post Link to post Share on other sites More sharing options...
MisterMAD Posted July 25, 2014 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 ... Share this post Link to post Share on other sites More sharing options...
MisterMAD Posted July 28, 2014 Posted July 28, 2014 help Share this post Link to post Share on other sites More sharing options...
rugydp Posted August 12, 2014 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 Share this post Link to post Share on other sites More sharing options...
vekia Posted August 12, 2014 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? Share this post Link to post Share on other sites More sharing options...
rugydp Posted August 12, 2014 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) Share this post Link to post Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 25, 2014 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. Share this post Link to post Share on other sites More sharing options...
rugydp Posted August 26, 2014 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); Share this post Link to post Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 26, 2014 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) Share this post Link to post Share on other sites More sharing options...
rugydp Posted August 26, 2014 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, Share this post Link to post Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 26, 2014 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 Share this post Link to post Share on other sites More sharing options...
rugydp Posted August 26, 2014 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. Share this post Link to post Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 26, 2014 Posted August 26, 2014 No problem, I hope someone else will be able to help me. Kind regards Daniele Share this post Link to post Share on other sites More sharing options...
vekia Posted August 26, 2014 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 Share this post Link to post Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 26, 2014 Posted August 26, 2014 It is on admin folder. Share this post Link to post Share on other sites More sharing options...
ItalianBoutiqueShoes Posted August 29, 2014 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) 2 Share this post Link to post Share on other sites More sharing options...
itx Posted August 30, 2014 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. Share this post Link to post Share on other sites More sharing options...
ItalianBoutiqueShoes Posted September 1, 2014 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); Share this post Link to post Share on other sites More sharing options...
pneumon1c Posted September 2, 2014 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) Share this post Link to post Share on other sites More sharing options...
limonaderose Posted October 21, 2014 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> Share this post Link to post Share on other sites More sharing options...
vekia Posted October 22, 2014 Posted October 22, 2014 what ps version? Share this post Link to post Share on other sites More sharing options...
limonaderose Posted October 22, 2014 Posted October 22, 2014 I use this code on prestashop 1.6.0.8: Share this post Link to post Share on other sites More sharing options...
vekia Posted October 22, 2014 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))); Share this post Link to post Share on other sites More sharing options...
limonaderose Posted October 22, 2014 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... Share this post Link to post Share on other sites More sharing options...
limonaderose Posted October 23, 2014 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)); Share this post Link to post Share on other sites More sharing options...
Rineez Posted October 25, 2014 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. Share this post Link to post Share on other sites More sharing options...
Rineez Posted October 25, 2014 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 Share this post Link to post Share on other sites More sharing options...
limonaderose Posted October 27, 2014 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'; Share this post Link to post Share on other sites More sharing options...
limonaderose Posted October 27, 2014 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. Share this post Link to post Share on other sites More sharing options...
Rineez Posted October 27, 2014 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) Share this post Link to post Share on other sites More sharing options...
limonaderose Posted October 27, 2014 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! Share this post Link to post Share on other sites More sharing options...
limonaderose Posted October 27, 2014 Posted October 27, 2014 But do you know why my code need to be in the same folder than config.php to work? Share this post Link to post Share on other sites More sharing options...
clawzee Posted November 6, 2014 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) Share this post Link to post Share on other sites More sharing options...
tuk66 Posted November 7, 2014 Posted November 7, 2014 English translations no longer exist in the /translations/en folder (in PS 1.6). Share this post Link to post Share on other sites More sharing options...
Turtle Wet Sports Posted September 29, 2015 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 ? Share this post Link to post Share on other sites More sharing options...
yaso Posted October 6, 2015 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. Share this post Link to post Share on other sites More sharing options...
deech123 Posted October 16, 2015 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. Share this post Link to post Share on other sites More sharing options...
Totti Posted October 19, 2015 Posted October 19, 2015 Also I had done this in the past (at least for me) bug. Share this post Link to post Share on other sites More sharing options...
jalloun Posted November 24, 2015 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) Share this post Link to post Share on other sites More sharing options...
lovemyseo Posted June 10, 2016 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 Share this post Link to post Share on other sites More sharing options...
imms12 Posted June 10, 2016 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 Share this post Link to post Share on other sites More sharing options...
tuk66 Posted June 11, 2016 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. Share this post Link to post Share on other sites More sharing options...
m.schambion Posted October 17, 2016 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. Share this post Link to post Share on other sites More sharing options...
Liofey Posted February 28, 2017 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); 2 Share this post Link to post Share on other sites More sharing options...
[email protected] Posted February 28, 2017 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 Share this post Link to post Share on other sites More sharing options...
santi_cb Posted June 28, 2017 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! Share this post Link to post Share on other sites More sharing options...
wouababelouba Posted August 2, 2017 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 Share this post Link to post Share on other sites More sharing options...
col_vert Posted September 28, 2017 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 Share this post Link to post Share on other sites More sharing options...
col_vert Posted September 28, 2017 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) Share this post Link to post Share on other sites More sharing options...
RamonAlonso Posted December 11, 2017 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) Share this post Link to post Share on other sites More sharing options...
el_boda Posted September 17, 2018 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) Share this post Link to post Share on other sites More sharing options...
Gombidi Bilişim Posted April 2, 2019 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+ ;) Share this post Link to post Share on other sites More sharing options...
ndiaga Posted November 20, 2019 Posted November 20, 2019 (edited) On 4/2/2019 at 1:52 AM, Gombidi Bilişim said: Sorry for late, it worked on 1.7+ Yes it works for 1.7 . Here is a function: public function changeOrderStatus($id_order, $id_order_status) { $history = new OrderHistory(); $history->id_order = (int)$id_order; $history->changeIdOrderState((int)$id_order_status, (int)($id_order)); } Edited November 20, 2019 by ndiaga (see edit history) Share this post Link to post Share on other sites More sharing options...
dandumit Posted August 11, 2020 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 Share this post Link to post Share on other sites
Recommended Posts