magento2: Multi-Currency not working when setting Custom Prices on adding product to Cart. This occurs on version 2.4.2 and previous versions as well
Preconditions (*)
- Magento version 2.4.2.
- Clean instance of Magento.
- Sample products has been imported.
- Two currencies have been defined: dollar and euro.
- Dollar is default currency.
- One website has been defined with two stores: English(default one) and Spanish store.
- A custom module that catches checkout_cart_product_add_after event to set Custom Price according to some specific business logic: https://www.mageplaza.com/devdocs/add-product-to-cart-with-custom-price-magento-2.html
Steps to reproduce (*)
- Enter PDP in front-end.
- Add product to Cart(dollar currency).
- For this product prices has been set(in the code) to 100 dollars.
- Product has been added to Cart.
- @magento give me 2.4-develop instance - upcoming 2.4.x release
Expected result (*)
- Either in mini-cart section or Cart Page the price must be the calculated in the custom module.
- For dollar currency the price should be 100 dollars.
- For euro currency the price should be 87 euros.
Actual result (*)
- For dollar currency the price is 100 dollars.
- For euro currency the price is 100 euros.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- [ x] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
Hi @engcom-Alfa. 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` branchDetails- 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.
I’d really like to add the labels you require in previous answer but I cant’ find a way to do that over here
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 33 (8 by maintainers)
[Magento Version 2.4.6]
I faced the same issue while using the above code to add a custom price. I found there is one file where the getCustomPrice() function is called but it is not implemented that’s why we did not get the proper custom price.
Path: /vendor/magento/module-quote/Model/Quote/Item.php
After I solved addtocart event issue there was one more problem because of the currency switcher. I checked the quote_item table and found a difference between normal and custom price values. I created a plugin for it and fixed that issue.
Path: vendor/magento/module-directory/Controller/Currency/SwitchAction.php
I added the whole solution here.
app/code/Msquare/ModuleName/etc/frontend
events.xml
app/code/Msquare/ModuleName/Observer
CustomPrice.php
app/code/Msquare/ModuleName/Helper
Data.php
app/code/Msquare/ModuleName/etc/frontend
di.xml
app/code/Msquare/ModuleName/Plugin/Direcotry/Controller/Currency
SwitchAction.php
Note: Here NO_SYMBOL constant value is 1. You can also add static value.
Path: vendor/magento/framework/Currency/Data/Currency.php