Sylius SEO URL Plugin
Features
-
Remove
/taxons
from taxon URLs- Before:
https://localhost/en_US/taxons/t-shirts
- After:
https://localhost/en_US/t-shirts
- Before:
-
Remove
/products
from product URLs- Before:
https://localhost/en_US/products/t-shirt-banana
- After:
https://localhost/en_US/t-shirt-banana
- Before:
Combined with disabling localised URLs, URLs can even be shorter.
Installation
-
Require plugin with composer:
composer require stefandoorn/sylius-seo-url-plugin
-
Add plugin class to your
AppKernel
.$bundles = [ new \StefanDoorn\SyliusSeoUrlPlugin\SyliusSeoUrlPlugin(), ];
or to your
bundles.php
:return [ // ... StefanDoorn\SyliusSeoUrlPlugin\SyliusSeoUrlPlugin::class => ['all' => true], ];
-
Import routing (to override default shop routing):
sylius_seo_url_shop: prefix: /{_locale} resource: "@SyliusSeoUrlPlugin/Resources/config/shop_routing.yml"
Make sure it's imported after (because it overrides default Sylius routes):
sylius_shop: resource: "@SyliusShopBundle/Resources/config/routing.yml" prefix: /{_locale}
You can remove the prefix
/{_locale}
if you prefer url's without the prefix. In this case, the import looks like this:sylius_seo_url_shop: resource: "@SyliusSeoUrlPlugin/Resources/config/shop_routing.yml"
-
Import configuration:
- { resource: "@SyliusSeoUrlPlugin/Resources/config/config.yml" }
-
Import repository method:
The default
findOneByChannelAndSlug
for products is slow when used in a loop, therefore:-
Use the trait in your own Product Repository & add interface:
use StefanDoorn\SyliusSeoUrlPlugin\Repository\ProductExistsByChannelAndSlug; use StefanDoorn\SyliusSeoUrlPlugin\Repository\ProductExistsByChannelAndSlugAwareInterface; use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository as BaseProductRepository; final class ProductRepository extends BaseProductRepository implements ProductExistsByChannelAndSlugAwareInterface { use ProductExistsByChannelAndSlug; }
-
Or use the Product repository as provided, add to your config:
sylius_product: resources: product: classes: repository: StefanDoorn\SyliusSeoUrlPlugin\Repository\ProductRepository
-