Prestashop: Update order state with Order::setCurrentState() add new line for invoice in order view

Created on 12 Sep 2019  路  27Comments  路  Source: PrestaShop/PrestaShop

Describe the bug
When update the order with Order::setCurrentState() create a new line in payments for create the invoice.

To Reproduce
Update state with webservice

[Edited by Khouloud]

Steps to reproduce the issue:

  1. Edit the status "Payment accepted" as described in the screenshot
    image
  2. Create a new order, the first status created is "Payment accepted" [you can create an order from the BO or you can use a Paypal module]
  3. Install the module
    fgorderstate.zip
  4. Click on Configure => click on the link & edit the order_id
  5. Go the BO => Orders => previous Order created => error => new payment line added => wrong
    image
BO Bug Fixed Minor Order Order statuses PR available

All 27 comments

Hi @FlorentinGarnier,

Is it the same issue reported in this ticket: https://github.com/PrestaShop/PrestaShop/issues/11154?

Thanks!

Hi @khouloudbelguith it seems to be the same problem. In my use case the line was created when I set the state to 'Delivered' The invoice was generated on new payment line.

@FlorentinGarnier, so can I close the issue as a duplicate of #11154?

Thanks!

@khouloudbelguith I don't know because I have attached PR #15514 to this issue

Hi @FlorentinGarnier,

When we update the order (tracking number ) via web service a new line is added to the ps_order_history as reported here: https://github.com/PrestaShop/PrestaShop/issues/11154
image
But there is no clone added to the payment seection after updating the status of the order throw web service.
I used this script

<html><head><title>pUT DATA</title></head><body>
<?php
define('DEBUG', true);
ini_set('display_errors','on');
define('PS_SHOP_PATH', 'http://prestashop.local/1761');
define('PS_WS_AUTH_KEY', 'Key');
require_once('PSWebServiceLibrary.php');
$ws = new PrestaShopWebservice(
    'http://prestashop.local/1761',
    'Key',
    false);



$id = 5; //ID order Here

$xml = $ws->get(array('resource' => 'orders', 'id' => $id));

echo "BEFORE\n";
echo $xml->asXML();

unset($xml->order->current_state);
//unset($xml->order->manufacturer_name);
//unset($xml->order->associations->order_features); 
//unset($xml->order->quantity);
//unset($xml->order->associations);

$xml->order->current_state = 5;
$xml->order->shipping_number = 12;


$opt['putXml'] = $xml->asXML();
$opt['id'] = $id;
$opt['resource'] = 'orders';

$xml = $ws->edit($opt);


$xml = $ws->get(array('resource' => 'orders', 'id' => $id));
echo "AFTER\n";
echo $xml->asXML();

I attached a screen record
https://drive.google.com/file/d/1lnL8HkcyIoiLecje1NVWqwMAHub-HWQ0/view
Thanks to check & feedback.

Okay, my bad, I don't use ws for changing order state, but my module use really Order::setCurrentState() and, for my mind, the easy way for you to test it, was to use WS.

Order::setCurrentState() is used by Order::setWsCurrentState() I was thinking that probably it was more easy for you to testing.

@FlorentinGarnier, could you please provide me a demo module to test it.
Thanks!

I wrote this little module https://github.com/FlorentinGarnier/fgorderstate
You can test it with a POST request like http://localhost:8000/module/fgorderstate/webhook?order_id=4302&token=abracadabra&method=task_status_change the token is really abracadabra

@FlorentinGarnier, I tried with your module.
I have an exception when navigating to the URL
image
Thanks!

Can you try with WebHook instead of webhook like that http://localhost:8000/module/fgorderstate/WebHook?order_id=4302&token=abracadabra&method=task_status_changeit's strange it works on my desktop

@FlorentinGarnier, when I change order_id from 4302 to 9.
I don't have any order with id = 4302.
I have this exception
image

Thanks!

@khouloudbelguith, I have changed filename, Pull the lasts commit from module and for information the bug is present when we remove invoice creation on payment accepted state.

I have tested it from docker environment with ps 1.7.7.0 and not with url rewrite.
So the correct url has change,

For exemple : http://localhost:8001/index.php?fc=module&module=fgorderstate&controller=webhook&order_id=5&token=abracadabra&method=task_status_change

don't forget to change the order_id

Thanks

@FlorentinGarnier, I uploaded a new module after changes.
I tried with a new link, but the same issue.

fgorderstate.zip

https://drive.google.com/file/d/1xxMykY1Z1C1TSkw_UEsjsFl0cnTqZgHH/view

Thanks!

@khouloudbelguith Okay...
it's very strange because I have created a new environment only for testing this module and it works. I have created a config page for this module with link generated by context. You can click on it and don't forget to change the order_id .

Thanks and sorry for your time.

@FlorentinGarnier, thanks!
Now, it is OK.
I tried with the develop branch & Ps1.7.6.1 => Same behavior.
In the payment section => only one line is displayed
image
Which is correct.

Thanks!

Nice!!! but i have notice that the bug is present when we remove invoice creation on payment accepted state.

@FlorentinGarnier,

I attached a screen record
https://drive.google.com/file/d/19jSda5yKCbI-B1GRJqFSs0oUJm3uvFGi/view
Thanks to check & feedback.

@khouloudbelguith

I attached a screen
https://coruscant.florentingarnier.net:5001/d/f/511623635889336369

@FlorentinGarnier, your link is not accessible.
Thanks!

@khouloudbelguith , can you try to put state "Payment Accepted" before lauch the link ?

@FlorentinGarnier, yes I tried with this also & it is OK
In my screen record at 01:23
https://drive.google.com/file/d/19jSda5yKCbI-B1GRJqFSs0oUJm3uvFGi/view
Thanks!

@khouloudbelguith the state of your order is awaiting bank wire payment but in my use case the order state is payment accepted that create a payment row without invoice. And when we use the module, create another payment row for making invoice.

https://drive.google.com/file/d/136ClA-DFIVHWSZUuKEbh6o6qxOPPC7Z1/view?usp=sharing

@FlorentinGarnier,

state is payment accepted that create a payment row without invoice

How did you do that?
According to your screen record, the invoice is enabled on your status: payment accepted
image

Thanks!

@khouloudbelguith,

I have deactivated Invoice Mail attachement and reproduce the bug.

  1. Create an order with status Payment accepted
  2. the payment is created
  3. Fire the module link and a new payment row with invoice is created.

https://drive.google.com/open?id=1kx4JkcKvMx5pYgOfnRts6LrJpttJEagT

@FlorentinGarnier, thanks for these clarifications.
I manage to reproduce the issue with PS1.7.6.1 & PS1.7.5.2.
Steps to reproduce the issue:

  1. Edit the status "Payment accepted" as described in the screenshot
    image
  2. Create a new order, the first status created is "Payment accepted" [you can create an order from the BO or you can use a Paypal module]
  3. Install the module
    fgorderstate.zip
  4. Click on Configure => click on the link & edit the order_id
  5. Go the BO => Orders => previous Order created => error => new payment line added => wrong
    image
    I鈥檒l add this to the debug roadmap.
    Thanks!

@khouloudbelguith ,

Very good !!!, for information I have just managed to reproduce with webservice and finnaly the bug appear with WS too. I have Tested with your earlier WS code.

Thanks

Was this page helpful?
0 / 5 - 0 ratings