Magento2: Cart unit item price is shown in wrong currency if custom_price is used

Created on 4 Mar 2020  路  5Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.3.4
  2. Multi-Currency Setup
  3. quote_item.custom_price is used

Steps to reproduce (*)

  1. Install Magento 2.3.4
  2. Deploy sample data
  3. Default currency is already US-Dollar (USD)
  4. Add 2nd allow currency f.e. EURO (EUR)
  5. Set rate f.e. 1 USD = 1.5 EUR
  6. Switch to EUR by currency switcher in frontend
  7. Add product with qty 2 in cart.
  8. Set a custom item price by observer or in the database quote_item.custom_price
  9. Open cart page

Sample:

$item->setCustomPrice(10)
$item->setOriginalCustomPrice(10)

Expected result (*)

I would expect to see:

  • Item unit price: 15 EUR
  • Row subtotal: 30 EUR

Actual result (*)

  • Item unit price: 10 EUR
  • Row subtotal: 30 EUR

It seems that quote_item.custom_price is currently always stored in base currency which is then not converted during cart item output.

Suggestion

Best practice would be to have 4 columns for quote_item

  • base_custom_price
  • custom_price
  • base_original_custom_price
  • original_custom_price

Additional info from engcom

  • _Stores - Currency - Currency Rates_
    eurotousd

  • Magento 2 Database, _quote_item_ table custom_price set to 10
    quote_cust_price

  • Storefront, 2 itmes added to Cart
    10x2

Pricing Clear Description Confirmed Format is valid P3 ready for dev Reported on 2.3.4 Reproduced on 2.4.x S2

Most helpful comment

Took me a while to figure out but vendor/magento/module-tax/Model/Sales/Total/Quote/CommonTaxCollector.php:692

$quoteItem->setCustomPrice($baseItemTaxDetails->getPrice());

should be:

$quoteItem->setCustomPrice($itemTaxDetails->getPrice());

All 5 comments

Hi @borriglione. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@borriglione do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-Bravo. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hello @borriglione

Thank you for your report.

We are able to reproduce this behavior on Magento 2.4-develop, and we have added additional info to the description

Hi @borriglione
I think this issue is false case testing. relate to :
https://github.com/magento/magento2/issues/12493

Took me a while to figure out but vendor/magento/module-tax/Model/Sales/Total/Quote/CommonTaxCollector.php:692

$quoteItem->setCustomPrice($baseItemTaxDetails->getPrice());

should be:

$quoteItem->setCustomPrice($itemTaxDetails->getPrice());

Was this page helpful?
0 / 5 - 0 ratings