opengento / module-country-store-redirect
此模块将在客户首次访问会话时根据他们的国家重定向客户。
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
此模块将在客户首次访问会话时根据他们的国家重定向客户。
设置
需要 Magento 2 开源版或 Commerce 版。
Composer 安装
运行以下 composer 命令
composer require opengento/module-country-store-redirect
设置模块
运行以下 magento 命令
bin/magento setup:upgrade
如果在生产模式中,不要忘记重新编译和重新部署静态资源。
Varnish 使用
使用以下指令更新 varnish vcl
# Bypass first visit and redirect
if (req.http.cookie !~ "PHPSESSID=") {
return (pass);
}
功能
首次会话重定向
根据访问者的国家重定向访问者在其首次会话访问中。此功能可以通过商店视图作用域禁用,因此首次重定向仅启用在主域名上,例如。
此功能可能有不可接受的行为,例如对于爬取您网站的机器人。这就是为什么您可以设置要忽略的用户代理列表以及在这种情况下不处理重定向的原因。此外,还可以配置要忽略的控制器动作列表。
现在您可以选择要使用的访问者国家解析器,可用的解析器包括
- 默认会话国家(已设置在会话中的国家或当前商店视图的默认值)。
- CloudFare GEO-IP 国家(使用 HTTP 头中的访问者国家)。必须启用 CloudFare 国家 GEO-IP,了解更多。
任何第三方开发者都可以添加自己的国家解析器。请参阅开发人员部分以获取更多信息。
国家到商店映射
定义国家到商店的关系。此配置将允许 Magento 根据访问者的国家将访问者重定向到正确的商店视图。可以将多个国家分配给单个商店视图。
设置
此模块的配置可在 商店 > 配置 > 一般 > 国家重定向
中找到。
文档
如何添加国家解析器
创建一个新的最终类并实现以下接口:Opengento\CountryStoreRedirect\Model\Country\ResolverInterface
。方法 public function getCountryCode(): string
应返回访问者的国家代码。国家应符合 ISO 3166-1 alpha-2 格式。
在工厂方法中注册新的国家解析器,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>
如果要在设置中可用解析器,请将其注册到解析器列表 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>
国家解析器已准备好使用。
SEO 和性能
我们强烈建议您不要使用首次访问重定向,因为这被认为是有害的,并且是不良做法。相反,显示一个对话框以允许访问者选择他们偏好的国家。
此功能在我们的模块Opengento_CountryStoreSwitcher opengento/module-country-store-switcher
中可用。
支持
向问题跟踪器提出新的请求。
作者
许可协议
本项目采用 MIT 许可证 - 请参阅LICENSE详细信息。
以上就是所有内容!