This plugin adds geo related functionality to your store. Right now it comes with these two features:
- Redirect visitors based on their country
- Output
hreflang
link tags with a Twig function to help search engines discover regional versions of your store
composer require setono/sylius-geo-plugin
Then, enable the plugin by adding it to the list of registered plugins/bundles
in config/bundles.php
file of your project before (!) SyliusGridBundle
:
<?php
$bundles = [
Setono\SyliusGeoPlugin\SetonoSyliusGeoPlugin::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
];
# config/packages/setono_sylius_geo.yaml
imports:
- { resource: "@SetonoSyliusGeoPlugin/Resources/config/app/config.yaml" }
# config/routes/setono_sylius_geo.yaml
setono_sylius_geo:
resource: "@SetonoSyliusGeoPlugin/Resources/config/routes.yaml"
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
The plugin uses country code providers to provide the country code. The plugin comes with a single
country code provider which is based on request headers. If you want to create your own provider, all you have to do
is implement the CountryCodeProviderInterface. The service will be
automatically tagged as setono_sylius_geo.country_code_provider
.
NOTE: If you are using Cloudflare all you have to do is within your dashboard go to
Rules > Transform Rules > Managed Transforms
and enable the Add visitor location headers
.
Go to https://your-store.com/admin/geo/rules/new to create a new rule. Here is an example:
As you can see our goal is to redirect Danish visitors to our locale Danish store. We have excluded bots and our office IP so that bots can freely crawl our international store, and we are able to browse the international store without being redirected, although we are based in Denmark.
Add this twig code: {{ ssg_hreflang_tags() }}
to your <head>
section and it will output
<link rel="alternate" hreflang="..." href="...">
tags.