stefandoorn/sylius-seo-url-plugin

Sylius 的 SEO URL

安装次数: 71,218

依赖者: 0

建议者: 0

安全性: 0

星标: 21

关注者: 3

分支: 10

开放问题: 5

类型:sylius-plugin


README

License Version Build Status

功能

  • 从类目 URL 中移除 /taxons

    1. 之前: https://localhost/en_US/taxons/t-shirts
    2. 之后: https://localhost/en_US/t-shirts
  • 从产品 URL 中移除 /products

    1. 之前: https://localhost/en_US/products/t-shirt-banana
    2. 之后: https://localhost/en_US/t-shirt-banana

结合 禁用本地化 URL,URL 可以更短。

安装

  1. 使用 composer 安装插件

    composer require stefandoorn/sylius-seo-url-plugin
  2. 将插件类添加到您的 AppKernel

    $bundles = [
       new \StefanDoorn\SyliusSeoUrlPlugin\SyliusSeoUrlPlugin(),
    ];

    或添加到您的 bundles.php

    return [
       // ...
       StefanDoorn\SyliusSeoUrlPlugin\SyliusSeoUrlPlugin::class => ['all' => true],
    ];
  3. 导入路由(覆盖默认商店路由)

    sylius_seo_url_shop:
        prefix: /{_locale}
        resource: "@SyliusSeoUrlPlugin/Resources/config/shop_routing.yml"

    确保它在(因为它覆盖了默认 Sylius 路由)之后导入

    sylius_shop:
        resource: "@SyliusShopBundle/Resources/config/routing.yml"
        prefix: /{_locale}

    如果您更喜欢不带前缀的 URL,可以删除前缀 /{_locale}。在这种情况下,导入看起来像这样

        sylius_seo_url_shop:
            resource: "@SyliusSeoUrlPlugin/Resources/config/shop_routing.yml"
  4. 导入配置

    - { resource: "@SyliusSeoUrlPlugin/Resources/config/config.yml" }
  5. 导入仓库方法

    当在循环中使用时,默认的 findOneByChannelAndSlug 对产品是慢的,因此

    1. 在您的 Product Repository 中使用特性并添加接口

      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;
      }
    2. 或者使用提供的 Product repository,添加到您的配置中

      sylius_product:
          resources:
              product:
                  classes:
                      repository: StefanDoorn\SyliusSeoUrlPlugin\Repository\ProductRepository