Timeline for Change Magento 2 website based on IP
Current License: CC BY-SA 4.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 31, 2020 at 18:39 | comment | added | rex | since you already worked much through this, I would recommend taking a look at this example github.com/princefishthrower/example-magento-2-geo-ip-redirect and this github.com/princefishthrower/example-magento-2-geo-ip-redirect/… | |
Jul 24, 2020 at 21:25 | comment | added | Reshad Zazai | I have added ?ip=$ip to $ipdat = @json_decode(file_get_contents("geoplugin.net/json.gp?ip=$ip")); now the variable $countryCode has the country of the user, not the server, but there is one more issue if a user1 access the website with his country code the US after a cache flush, the store-view US will be displayed to that and every other user from the cache and the event will not be triggered again even if the user2 has country code DE. | |
Jul 24, 2020 at 19:52 | comment | added | Reshad Zazai | $ipdat = @json_decode(file_get_contents("geoplugin.net/json.gp")); May I know why you are not passing the user IP address because by default geoplugin.net/json.gp will take the server IP address and return the country where the website is hosted not the user country. | |
Jul 20, 2020 at 15:30 | comment | added | Joao71 | is it working? What are you using to "emulate" different website calls to test this out? | |
Jul 19, 2020 at 10:55 | comment | added | Joao71 | Please make sure you run the following commands: php bin/magento setup:upgrade php setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento indexer:reindex php bin/magento cache:clean php bin/magento cache:flush Also you can use Xdebug to check if the observer is running. Let me know what error it is throwing so I can help | |
Jul 18, 2020 at 15:45 | comment | added | Reshad Zazai | But the solution didn't work yet. | |
Jul 18, 2020 at 15:44 | comment | added | Reshad Zazai | 1: I have created and registered a module, and then created events.xml under /var/www/html/magento/app/code/Zazai/Module/etc/events.xml. 2: I have created PostDespatchEvent.php file under /var/www/html/magento/app/code/Zazai/Module/Observer/PostDespatchEvent.php 3: I have replaced the term Vendor with Zazai in both the files 4: I have changed 'PT' and 'default' if($countryCode == 'PT') { $this->_storeManager->setCurrentStore('default'); } according to the 'country code' and 'store code' I wanted navigation for. | |
Jul 17, 2020 at 1:19 | history | answered | Joao71 | CC BY-SA 4.0 |