My website is going to be viewed worldwide, but I want only certain countries to be able to view prices/purchase goods.

In total there will be 5 different regions that will be able to view prices/buy products, but the product ranges will vary depending on region.

I thought about using GeoIP to determine where the customer is based, but how do I do this using different stores/store views?



The principle is fairly simple, you can just add the appropriate logic into your .htaccess file or into the index.php file. You need only set the environment variables for the store/website so that Magento can load the appropriate one.

The environment variables are,

  • MAGE_RUN_CODE - Whatever you set as the store/website code in your admin
  • MAGE_RUN_TYPE - Either website or store depending on the scope of the code you are trying to load

If you are using Apache, you could use mod_geoip2; Nginx, recompile with the geoip module; MageStack, use the existing GEO_ environment variables; if anything else, you could load the PHP PECL extension for geoip.

Then its just a case of using a simple setenvif, set or conditional statement to set the appropriate code/type.

| improve this answer | |

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.