Jump to content

How to change status (to shipped) via code


bluco

Recommended Posts

Hello,

When we change the status in our prestashop manually from "Pago aceptado" (payment accepted) to "Enviado" (Shipped) everything works properly (See the picture attached: 1_change_status.png

 

But when We do it via code it duplicates transactions entries. Please, find attached picture 2 (correct example manually) and picture 3 (incorrect example via code).

This is our test code:

$id_orderaux = 538;
$order = new Order($id_orderaux);
$id_order_state = '4';
$id_employee = '2';

$order->setCurrentState($id_order_state, $id_employee);

 

Please, find also attached an screenshot of an order before changing status to Shipped (4_example_order_in_accepted_payment_status).

 

Data about our system:

Prestashop version:  1.7.7.5

MySQL: 10.0.38-MariaDB-0+deb8u1

PHP: 7.3.20

 

Thank you very much

1_change_status.png

3_incorrect_changed_by_code.png

2_correct_changed_manually.png

4_example_order_in_accepted_payment_status.png

Link to comment
Share on other sites

Hello,

Something like this 
 

$order = new Order((int) $id_order);
$history = new OrderHistory();
$history->id_order = (int) $order->id;
if ($order->current_state != (int) $id_order_status) {
    $history->changeIdOrderState((int) $id_order_status, $order, true);
    $history->addWithemail(true);
}

Thank you 

  • Like 1
Link to comment
Share on other sites

Hello Nishith,

Thanks for you quick answer. I'm afraid it didn't work properly. I've runned the following code:

<?php

define('DEBUG', true);
ini_set('display_errors','on');


require '../vendor/autoload.php';
require '../config/config.inc.php';


$id_order = 557;
$id_order_status = '4';
$id_employee = '2';

$order = new Order((int) $id_order);
$history = new OrderHistory();
$history->id_order = (int) $order->id;
if ($order->current_state != (int) $id_order_status) {
    $history->changeIdOrderState((int) $id_order_status, $order, true);
    $history->addWithemail(true);
}

?>

 

It changed the status to "Enviado" (Shipped) but it didn't created a history of the  change and it didn't created the slip.

Please, find attached an screnshoot of the result.

Here you can find an order changed the status manually.

2_correct_changed_manually.png

 

 

557 wrong result.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...