Fix: Force current currency reload on currency code change - #40348
Open
satishashilwar wants to merge 1 commit into
Open
Fix: Force current currency reload on currency code change#40348satishashilwar wants to merge 1 commit into
satishashilwar wants to merge 1 commit into
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
satishashilwar
force-pushed
the
fix/40333-force-currency-reload
branch
from
December 7, 2025 19:41
e4de114 to
a7ef876
Compare
Author
|
@magento run all tests |
Author
|
@magento run Unit Tests, Static Tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (*)