Commit a7ef876
committed
Fix: Force current currency reload on currency code change
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: #403331 parent 0a3b703 commit a7ef876
File tree
2 files changed
+104
-0
lines changed- app/code/Magento/Store
- Model
- Test/Unit/Model
2 files changed
+104
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
914 | 917 | | |
915 | 918 | | |
916 | 919 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
819 | 819 | | |
820 | 820 | | |
821 | 821 | | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
822 | 923 | | |
823 | 924 | | |
824 | 925 | | |
| |||
0 commit comments