-
Notifications
You must be signed in to change notification settings - Fork 42
Order total wrong from AdminOrder when VAT number used #18
Comments
Hi @ckubitza, I did not manage to reproduce the issue with PS1.7.6.1 & the module VAT v2.1.0. |
Oh, I didn't noticed that there is an update for the vatmodule, I was using v2.0.0. So I tried the new version and indeed, the issue doesn't show up now. |
@ckubitza, so the issue is fixed after upgrading the module? Thanks! |
Well, yes. But I tend to think that the update in the module is just obfuscating the real bug. |
With the new version there are no taxes applied => so can you explain to me how the module is just obfuscating the real bug & not fixing the issue? Thanks! |
In my observations I have found out, that the total price calculation is not given an address, so it tries to get it from the cart in the context, which is not set at this time when the adminorder is used. Here I made some logs for the calls in the vatnumber module (edit: Original:
... and here with my changes (setting the cart in context before getting totals):
|
@ckubitza, thanks for your feedback. Thanks! |
Describe the bug
Wrong tax is applied to order totals when order is created from admin page with a foreign address which has a VAT-number. Product taxes are correct but not the totals. Frontend orders are not affected.
To Reproduce
Steps to reproduce the behavior:
Additional information
PrestaShop version: 1.7.6.0
PHP version: 7.2
VAT-number module: 2.0.0
Technical Details
It seams that the order total is calculated here https://github.com/PrestaShop/PrestaShop/blob/c389f90984cdf46c42ecf970342553b6db867aee/controllers/admin/AdminOrdersController.php#L1248 which internally uses the Product::getPriceStatic() function but without an address_id. In this situation, the function tries to get it from the cart object in the context. But the context does not have a cart object yet, so a default address is used with a wrong country. You can see that $id_address is NULL here https://github.com/PrestaShop/PrestaShop/blob/b2f4a3508462790192259028e2e39c3f58a4baca/classes/Product.php#L3218 (compare it to a frontend order which is working correctly).
Possible Solution
Add this
after this line: https://github.com/PrestaShop/PrestaShop/blob/c389f90984cdf46c42ecf970342553b6db867aee/controllers/admin/AdminOrdersController.php#L1231 to set the correct cart in the context before the totals are calculated.
I could provide a pull request for this.
The text was updated successfully, but these errors were encountered: