opengento / module-country-store-redirect
This module will redirect the customers regarding their country of origin, on their first visit session.
Fund package maintenance!
www.helloasso.com/associations/opengento/formulaires/1
Installs: 3 157
Dependents: 0
Suggesters: 3
Security: 0
Stars: 5
Watchers: 3
Forks: 2
Open Issues: 0
Type:magento2-module
Requires
- php: ^7.4||^8.0
- magento/framework: *
- magento/module-config: *
- magento/module-store: *
- opengento/module-country-store: ^1.0.0
- psr/log: *
Requires (Dev)
- magento/magento-coding-standard: ^5
- magento/marketplace-eqp: ^4.0
- roave/security-advisories: dev-master
Suggests
- opengento/module-country-store-phone: This module add the phone number field to the country data object.
- opengento/module-country-store-redirect-magegefan: This module add the country store resolver from Magefan GeoIp module.
- opengento/module-country-store-redirect-magepal: This module add the country store resolver from MagePal GeoIp module.
- opengento/module-country-store-redirect-mageplaza: This module add the country store resolver from Mageplaza GeoIP module.
- opengento/module-country-store-redirect-mooore: This module add the country store resolver from Mooore Digital GeoIp module.
- opengento/module-country-store-switcher: This module will allows the customers to switch of store by country instead of name/language.
README
This module will redirect the customers regarding their country of origin, on their first visit session.
Setup
Magento 2 Open Source or Commerce edition is required.
Composer installation
Run the following composer command:
composer require opengento/module-country-store-redirect
Setup the module
Run the following magento command:
bin/magento setup:upgrade
If you are in production mode, do not forget to recompile and redeploy the static resources.
Varnish Usage
Update the varnish vcl with the following instruction:
# Bypass first visit and redirect
if (req.http.cookie !~ "PHPSESSID=") {
return (pass);
}
Features
First Session Redirect
Redirect the visitor on its first session visit, depending on its country. This feature can be disabled by store view scope, so the first redirect is only enabled on your main domain for example.
This feature can have non desirable behavior, for example for robots crawling your website. That's why you can set a list of user agents to ignore and to not process the redirection in this case. Moreover, a list of controller actions to ignore is also configurable.
Now you can select which visitor's country resolver to use, the available resolvers are:
- Default Session Country (the country already set in session, or the default for the current store view).
- CloudFare GEO-IP Country (use visitor'scountry available in the HTTP header value). CloudFare Country GEO-IP must be enabled, see more.
Any third party developers can add its own country resolver. Please read the developer section for further details.
Country to store mapping
Define the country to store relation. This configuration will allows Magento to redirect the visitor to the correct store view depending of the visitor's country. Multiple countries can be assigned to a single store view.
Settings
The configuration for this module is available in Stores > Configuration > General > Country Redirect
.
Documentation
How to add a country resolver
Create a new final class and implement the following interface: Opengento\CountryStoreRedirect\Model\Country\ResolverInterface
.
The method public function getCountryCode(): string
should returns the visitor's country code of origin. The country
should be compliant to ISO 3166-1 alpha-2 format.
Register the new country resolver in the method factory, Vendor/Module/etc/di.xml
:
<type name="Opengento\CountryStore\Model\Resolver\ResolverFactory"> <arguments> <argument name="resolvers" xsi:type="array"> <item name="customCountryResolver" xsi:type="string">Vendor\Module\Model\Country\Resolver\CustomCountryResolver</item> </argument> </arguments> </type>
If you want the resolver ba available in settings, register it in the resolver list Vendor/Module/etc/di.xml
:
<virtualType name="Opengento\CountryStore\Model\Config\Source\CountryResolver"> <arguments> <argument name="options" xsi:type="array"> <item name="customCountryResolver" xsi:type="array"> <item name="label" xsi:type="string" translatable="true">Custom Country Resolver</item> <item name="value" xsi:type="const">Vendor\Module\Model\Country\Resolver\CustomCountryResolver::RESOLVER_CODE</item> </item> </argument> </arguments> </virtualType>
The country resolver is ready to use.
SEO and Performance
We strongly discourage you to use the first visit redirect as it is considered harmful and bad practice. Instead show a
dialog to allow the visitor to select the country of its preference.
This feature is available in our module Opengento_CountryStoreSwitcher opengento/module-country-store-switcher
.
Support
Raise a new request to the issue tracker.
Authors
License
This project is licensed under the MIT License - see the LICENSE details.
That's all folks!