I faced the issue like “auto currency switcher is not working after installing varnish, it displayed the firstly loaded cached content to all the locations”. The solution is we need to add country code as a vary header so each country region has separate cached content. e.g) India has separate cached content of the home page, USA has separate cached content of home page similarly each country has a different type of cached contents.

We assume you already configured the varnish in Magento 2. Please follow the below steps to get and set country code in the varnish configuration file. We need to install GeoIP vmod to get country code

GeoIP vmod installation:

Varnish configuration:
Need to add the below line in /etc/varnish/default.vcl

Magento code change:
You need to find the place of set currency code execution block in PHP and retrieve the currency code from vary header and set it as currency code.

I hope it helps.

 

About Bilal

I'm a software programmer, I handle Magento2 modifications at any level.

View all posts by Bilal →

Leave a Reply

Your email address will not be published. Required fields are marked *