setono / sylius-geo-plugin
Setono为Sylius的示例插件。
v1.0.0-alpha.7
2023-09-01 07:34 UTC
Requires
- php: >=7.4
- doctrine/persistence: ^2.5 || ^3.2
- knplabs/knp-menu: ^3.3
- psr/log: ^1.1 || ^2.0 || ^3.0
- setono/bot-detection-bundle: ^1.11
- setono/composite-compiler-pass: ^1.1
- setono/doctrine-object-manager-trait: ^1.2
- sylius/channel: ^1.0
- sylius/channel-bundle: ^1.0
- sylius/core: ^1.0
- sylius/core-bundle: ^1.0
- sylius/grid-bundle: ^1.10
- sylius/locale: ^1.0
- sylius/locale-bundle: ^1.0
- sylius/resource-bundle: ^1.8
- sylius/ui-bundle: ^1.0
- symfony/config: ^5.4 || ^6.0
- symfony/dependency-injection: ^5.4 || ^6.0
- symfony/event-dispatcher: ^5.4 || ^6.0
- symfony/form: ^5.4 || ^6.0
- symfony/http-foundation: ^5.4 || ^6.0
- symfony/http-kernel: ^5.4 || ^6.0
- symfony/routing: ^5.4 || ^6.0
- twig/twig: ^2.15 || ^3.7
- webmozart/assert: ^1.11
Requires (Dev)
- api-platform/core: ^2.7
- behat/behat: ^3.13
- doctrine/orm: ~2.15.1
- lexik/jwt-authentication-bundle: ^2.19
- php-http/message-factory: ^1.1
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.6
- psalm/plugin-phpunit: ^0.18
- setono/code-quality-pack: ^2.4
- sylius/sylius: ~1.10.14
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/intl: ^5.4 || ^6.0
- symfony/property-info: ^5.4 || ^6.0
- symfony/serializer: ^5.4 || ^6.0
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- symfony/webpack-encore-bundle: ^1.17
This package is auto-updated.
Last update: 2024-09-04 07:57:30 UTC
README
此插件为您的商店添加地理相关功能。目前它包含以下两个功能
- 根据访客所在国家进行重定向
- 使用Twig函数输出
hreflang
链接标签,以帮助搜索引擎发现商店的区域版本
安装
步骤 1:下载插件
composer require setono/sylius-geo-plugin
步骤 2:启用插件
然后,通过将其添加到项目中config/bundles.php
文件中注册的插件/捆绑包列表,在SyliusGridBundle
之前(!)启用插件
<?php $bundles = [ Setono\SyliusGeoPlugin\SetonoSyliusGeoPlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], ];
步骤 3:配置插件
# config/packages/setono_sylius_geo.yaml imports: - { resource: "@SetonoSyliusGeoPlugin/Resources/config/app/config.yaml" }
步骤 4:导入路由
# config/routes/setono_sylius_geo.yaml setono_sylius_geo: resource: "@SetonoSyliusGeoPlugin/Resources/config/routes.yaml"
步骤 5:更新数据库模式
php bin/console doctrine:migrations:diff php bin/console doctrine:migrations:migrate
步骤 6:使用现有的国家代码提供者或创建一个新的提供者
该插件使用国家代码提供者来提供国家代码。插件自带一个基于请求头部的单个国家代码提供者。如果您想创建自己的提供者,只需实现CountryCodeProviderInterface即可。该服务将自动标记为setono_sylius_geo.country_code_provider
。
注意:如果您使用Cloudflare,只需在仪表板中转到规则 > 转换规则 > 管理转换
,并启用添加访客位置头部
即可。
用法
根据访客所在国家进行重定向
访问 https://your-store.com/admin/geo/rules/new 创建新规则。以下是一个示例
如您所见,我们的目标是重定向丹麦访客到我们的丹麦地区商店。我们排除了爬虫和我们的办公IP,这样爬虫可以自由爬取我们的国际商店,我们也能在丹麦之外浏览国际商店,而不会重定向。
输出hreflang
链接标签
将此Twig代码:{{ ssg_hreflang_tags() }}
添加到您的<head>
部分,它将输出<link rel="alternate" hreflang="..." href="...">
标签。