opengento/module-country-store-redirect
Composer 安装命令:
composer require opengento/module-country-store-redirect
包简介
This module will redirect the customers regarding their country of origin, on their first visit session.
README 文档
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!
opengento/module-country-store-redirect 适用场景与选型建议
opengento/module-country-store-redirect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.07k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 08 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「geoip」 「redirect」 「location」 「country」 「magento」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 opengento/module-country-store-redirect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 opengento/module-country-store-redirect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 opengento/module-country-store-redirect 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A GeoIP decorator/processor for monolog
Redirects TYPO3 visitors automatic or with a suggestlink to another language and/or root page.
Advanced TYPO3 redirect management for sys_redirect with regex and host/language-aware matching, CSV/.htaccess import/export, categories and priority, automatic slug redirect workflows, plus hit/log analytics.
PHP GeoIP client
SmartResponse simplifies consistent response handling in Laravel: supports Blade, redirect with messages, and JSON format.
This ConcreteCMS/concrete5 addon installs a block type that when added to a page allows you to redirect visitors to this page to another page that you specify or an external URL.
统计信息
- 总下载量: 4.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-01