0

I am running magento 2.4.3 and I am having as default currency EUR in my website and as allowed currencies, EUR and USD only. Visiting the site homepage, EUR shows to be the default currency but when I visit some products or pages the currency shows to USD and I am not able to change back to EUR from currency switcher. After redeploying and clearing the cache issue seems to fix but only temporarily. After a while random pages show in USD currency and can't change to EUR from the switcher. I have no error in console or server logs. I am using a custom theme and the developer told me that is propably caching related. I am using varnish caching and redis for session and db. Also for logged in users the currency in a page it may be different than this from not signed in users. I suspect redis but I am not sure. Here is the env.php conf.

return [
    'backend' => [
        'frontName' => 'admin'
    ],
    'remote_storage' => [
        'driver' => 'file'
    ],
    'queue' => [
        'consumers_wait_for_messages' => 1
    ],
    'crypt' => [
        'key' => 'f1554499d1bssdf72f97b84664bee3'
    ],
    'db' => [
        'table_prefix' => '',
        'connection' => [
            'default' => [
                'host' => 'localhost',
                'dbname' => 'db_prod',
                'username' => 'root',
                'password' => 'ddd',
                'model' => 'mysql4',
                'engine' => 'innodb',
                'initStatements' => 'SET NAMES utf8;',
                'active' => '1',
                'driver_options' => [
                    1014 => false
                ]
            ]
        ]
    ],
    'resource' => [
        'default_setup' => [
            'connection' => 'default'
        ]
    ],
    'x-frame-options' => 'SAMEORIGIN',
    'MAGE_MODE' => 'production',
    'session' => [
        'save' => 'redis',
        'redis' => [
            'host' => '/run/redis-sessions/redis-sessions.sock',
            'password' => 'sdfdfsdf',
            'database' => '2',
            'log_level' => '4',
            'port' => '6380',
            'timeout' => '2.5',
            'persistent_identifier' => '',
            'compression_threshold' => '2048',
            'compression_library' => 'gzip',
            'max_concurrency' => '35',
            'break_after_frontend' => '5',
            'break_after_adminhtml' => '30',
            'first_lifetime' => '600',
            'bot_first_lifetime' => '60',
            'bot_lifetime' => '7200',
            'disable_locking' => '1',
            'min_lifetime' => '60',
            'max_lifetime' => '2592000',
            'sentinel_master' => '',
            'sentinel_servers' => '',
            'sentinel_connect_retries' => '5',
            'sentinel_verify_master' => '0'
        ]
    ],
    'cache' => [
        'frontend' => [
            'default' => [
                'id_prefix' => 'd80_',
                'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
                'backend_options' => [
                    'server' => '/run/redis/redis-server.sock',
                    'database' => '0',
                    'port' => '6379',
                    'password' => 'sdfsdfsd',
                    'compress_data' => '1',
                    'compression_lib' => 'gzip',
                    'preload_keys' => [
                        'd80_EAV_ENTITY_TYPES',
                        'd80_GLOBAL_PLUGIN_LIST',
                        'd80_DB_IS_UP_TO_DATE',
                        'd80_SYSTEM_DEFAULT'
                    ]
                ]
            ]
        ],
        'allow_parallel_generation' => false
    ],
    'lock' => [
        'provider' => 'db',
        'config' => [
            'prefix' => ''
        ]
    ],
    'directories' => [
        'document_root_is_pub' => true
    ],
    'cache_types' => [
        'config' => 1,
        'layout' => 1,
        'block_html' => 1,
        'collections' => 1,
        'reflection' => 1,
        'db_ddl' => 1,
        'compiled_config' => 1,
        'eav' => 1,
        'customer_notification' => 1,
        'config_integration' => 1,
        'config_integration_api' => 1,
        'full_page' => 1,
        'config_webservice' => 1,
        'translate' => 1,
        'vertex' => 1,
        'mageworx_shipping_carriers' => 1,
        'ox_megamenu' => 1
    ],
    'downloadable_domains' => [
        '127.0.0.1',
        'localhost'
    ],
    'install' => [
        'date' => 'Wed, 07 Apr 2021 23:09:04 +0000'
    ],
    'http_cache_hosts' => [
        [
            'host' => 'localhost',
            'port' => '80'
        ]
    ],
    'dev' => [
        'debug' => [
            'debug_logging' => 0
        ],
        'syslog' => [
            'syslog_logging' => 0
        ]
    ],
    'db_logger' => [
        'output' => 'disabled',
        'log_everything' => 1,
        'query_time_threshold' => '0.001',
        'include_stacktrace' => 1
    ]
];

1 Answer 1

0

I finally found the cause of this issue and I think I can say it is a kind of bug on FPC or maybe better on the Store Object.

The main problem is the FPC relay on COOKIE to check the currency and create the request ID, this is not consistent and can break the cache in some weird situation.

To reproduce:

  1. Access to a product page
  2. Switch to another currency ( anyone different from the default)
  3. Delete the currency cookie
  4. Clean the FPC cache
  5. Access again the page

From this moment on the page is cached with a different currency from the default one ( try to open the page within incognito mode ). This is bad because potentially a user can alter the cache behavior.

2
  • I am not able to reproduce the steps. What's the name of the currency cookie to delete? Feb 8 at 8:33
  • I saw that when varnish is restarted everything seems back to normal with the currency switcher. After a while again, in some pages the currency switcher does not work, leaving only the second currency selected by default. I run varnishlog and I saw that in those pages X-Magento-Vary cookie is not set so the correct variation of the page is not loaded. BerespHeader Set-Cookie: (X-Magento-Vary is missing) sudo varnishlog -g request -q "ReqUrl eq '/page'" Feb 27 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.