Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Order total wrong from AdminOrder when VAT number used #18

@ckubitza

Description

@ckubitza

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:

  1. Have products with taxes and VAT-number module is active
  2. Place an order from admin orders page with an invoice address in another EU country and a VAT-number so no taxes should be applied (correctly shown in the order summary at the bottom)
  3. The order is created with correct order details (..._price_tax_incl = ..._price_tax_excl in table ps_order_details), but the order totals are wrong (e.g. total_products != total_products_wt in table ps_orders). These wrong values lead to an invalid invoice because the product sum is wrong.

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

Context::getContext()->cart = $cart;

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions