-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix: Force current currency reload on currency code change #40348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-develop
Are you sure you want to change the base?
Fix: Force current currency reload on currency code change #40348
Conversation
|
Hi @satishashilwar. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Fixed an issue where calling setCurrentCurrencyCode() multiple times
did not update the currency returned by getCurrentCurrency() due to
internal caching.
The issue occurred because getCurrentCurrency() caches the currency
object in the store's data using the 'current_currency' key. When
setCurrentCurrencyCode() was called to change the currency code, the
cached currency object was not cleared, causing getCurrentCurrency()
to return the old currency instead of loading the new one.
Solution:
- Added unsetData('current_currency') in setCurrentCurrencyCode()
to clear the cached currency when the currency code changes
- This forces getCurrentCurrency() to reload the currency based on
the new currency code on its next call
Changes:
- Updated Store::setCurrentCurrencyCode() to clear cached currency
- Added unit test to verify currency cache is cleared on code change
Test coverage:
- Added testSetCurrentCurrencyCodeClearsCachedCurrency() unit test
- Test verifies unsetData() is called when currency code changes
- Test verifies behavior with multiple currency code changes
Manual testing:
1. Create store with multiple available currencies (USD, EUR)
2. Call $store->setCurrentCurrencyCode('USD')
3. Verify $store->getCurrentCurrency()->getCode() returns 'USD'
4. Call $store->setCurrentCurrencyCode('EUR')
5. Verify $store->getCurrentCurrency()->getCode() returns 'EUR'
6. Without this fix, step 5 would return 'USD'
Fixes: magento#40333
e4de114 to
a7ef876
Compare
|
@magento run all tests |
|
@magento run Unit Tests, Static Tests |
Description (*)
Fixed an issue where calling
setCurrentCurrencyCode()multiple times did not update the currency returned bygetCurrentCurrency()due to internal caching.Root Cause:
getCurrentCurrency()caches the currency object using the'current_currency'key. WhensetCurrentCurrencyCode()changed the currency code, it didn't clear this cache, causinggetCurrentCurrency()to return stale data.Solution:
Added
unsetData('current_currency')insetCurrentCurrencyCode()to clear the cached currency when the currency code changes, forcinggetCurrentCurrency()to reload the currency based on the new code.Changes:
Store::setCurrentCurrencyCode()to clear cached currencytestSetCurrentCurrencyCodeClearsCachedCurrency()Related Pull Requests
None
Fixed Issues (if relevant)
Manual testing scenarios (*)
$store->setCurrentCurrencyCode('USD')$store->getCurrentCurrency()->getCode()returns'USD'$store->setCurrentCurrencyCode('EUR')$store->getCurrentCurrency()->getCode()returns'EUR'(without this fix, it would still return'USD')Questions or comments
None
Contribution checklist (*)