Jump to content
Draq

Changing order status vith php

Recommended Posts

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

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 by Alexander Simonchik (see edit history)
  • Like 3

Share this post


Link to post
Share on other sites

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

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

  • Like 2

Share this post


Link to post
Share on other sites

Alexander solution works like a charm, so if it also works for you @Draq - please mark this topic as solved :)

  • Like 1

Share this post


Link to post
Share on other sites

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

which version of prestashop you use?

Where you exactly insert code that you pasted?

Share this post


Link to post
Share on other sites

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

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 by expmedia-Christian (see edit history)

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

Hi, thanks for your help!

 

Yes we use Prestashop 1.5.4.1.

 

The eMail in the status is set, here are some screenshots.

emailtemplate.png

 

Here's how the order looks if I set it to status 4 via my external script:

howitlooks.png

 

There's this missing:

missing.png

 

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

and when you change the order status in the back office - everything works well?

Share this post


Link to post
Share on other sites

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

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

Thanks Alexander Simonchik.

 

I think we should have a nicer api like

$order->addHistory($order_state_id);

Don't you think ?

Edited by seb776 (see edit history)

Share this post


Link to post
Share on other sites

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 :)

  • Like 1

Share this post


Link to post
Share on other sites
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

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

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

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

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

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

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

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

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 by rugydp (see edit history)

Share this post


Link to post
Share on other sites

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

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

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 by ItalianBoutiqueShoes (see edit history)

Share this post


Link to post
Share on other sites

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

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

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

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

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 by ItalianBoutiqueShoes (see edit history)
  • Like 2

Share this post


Link to post
Share on other sites

 

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

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

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 by pneumon1c (see edit history)

Share this post


Link to post
Share on other sites

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

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

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

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

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.

  • Like 1

Share this post


Link to post
Share on other sites

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

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

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 by Rineez (see edit history)

Share this post


Link to post
Share on other sites

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

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 by clawzee (see edit history)

Share this post


Link to post
Share on other sites

English translations no longer exist in the /translations/en folder (in PS 1.6).

Share this post


Link to post
Share on other sites

 

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

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

@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

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

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 imms@hotmail.com or message me on whatsapp at +923343515883

 

Thanks

Share this post


Link to post
Share on other sites

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

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

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);
  • Like 2

Share this post


Link to post
Share on other sites

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

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

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();
  • Like 1

Share this post


Link to post
Share on other sites

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

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 by RamonAlonso (see edit history)

Share this post


Link to post
Share on other sites
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 by el_boda (see edit history)

Share this post


Link to post
Share on other sites
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
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 by ndiaga (see edit history)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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