asdoria/sylius-facet-filter-plugin

为Sylius提供的简单分面过滤器插件


README

Asdoria Lgoo

Asdoria 分面过滤器包

此插件允许您将分面链接到Sylius商店中的特定资源

Sylius提供了一个产品属性、选项和一些其他功能的系统。然而,没有原生的方法来仅使用它们在特定类别(税目)的产品上。当您想使用这些分面让用户过滤产品目录时,这可能会成为一个问题。我们的插件允许您将特定的属性、选项和其他分面链接到特定的税目。这样,您可以轻松决定要显示哪些过滤器以及在哪里显示。

功能

  • 创建分面组
  • 创建与特定产品特性相关的可定制分面过滤器
  • 轻松创建分面集合
  • 将分面过滤器附加到您的税目或其他资源

Example of a product's facets customization

安装

  1. 运行 composer require asdoria/sylius-facet-filter-plugin

  2. config/bundles.php 中添加捆绑包。您必须将其放在 SyliusGridBundle 之上。

Asdoria\SyliusFacetFilterPlugin\AsdoriaSyliusFacetFilterPlugin::class => ['all' => true],
[...]
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
  1. config/routes.yaml 中导入路由
asdoria_facet_filter:
    resource: "@AsdoriaSyliusFacetFilterPlugin/Resources/config/routing.yaml"
    prefix: /admin
  1. 将 facets_filters 过滤器添加到您的网格配置中,例如在 config/packages/grids/sylius_shop_product.yaml 中,但该网格已由捆绑包配置。
sylius_grid:
    grids:
        sylius_shop_product:
            filters:
                facets_filters:
                    type: facets_filters
                    label: false
                    options:
                        owner: taxon
 #                      filterBy: owner | funnel
 # this option "filterBy" is optional but if you specify funnel, the different filters will be filled with the rest of the filtered products.
 # this option "filterBy" is optional but if you specify owner, the different filters will be filled with the list of attributes of the category.
 # This option "filterBy" is optional but if you don't specify it, the different filters will be filled with the list of attributes of all shops.
  1. config/packages/_sylius.yaml 中导入插件配置,并为 sylius.shop.product.index.search 事件添加新配置。
imports:
    - { resource: "@AsdoriaSyliusFacetFilterPlugin/Resources/config/config.yaml"}
...
sylius_ui:
    events:
        sylius.shop.product.index.search:
            blocks:
                search:
                    template: "@SyliusUi/Block/_legacySonataEvent.html.twig"
                    priority: 30
                    context:
                        event: sylius.shop.product.index.disabled_search
  1. 在您的 Taxon 实体 App/Entity/Taxonomy/Taxon.php 中实现 Facet 接口和特性。
// ...

use Asdoria\SyliusFacetFilterPlugin\Model\Aware\FacetFilterCodeAwareInterface;
use Asdoria\SyliusFacetFilterPlugin\Traits\FacetFilterCodeTrait;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Taxon as BaseTaxon;
use Sylius\Component\Taxonomy\Model\TaxonTranslationInterface;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_taxon")
 */
class Taxon extends BaseTaxon implements FacetFilterCodeAwareInterface
{
    use FacetFilterCodeTrait;

    protected function createTranslation(): TaxonTranslationInterface
    {
        return new TaxonTranslation();
    }
}
  1. 覆盖或创建(如果尚未存在)Taxon 表单模板,在 templates/bundles/SyliusAdminBundle/Taxon/_form.html.twig 中。
{% from '@SyliusAdmin/Macro/translationForm.html.twig' import translationFormWithSlug %}

<div class="ui segment">
    {{ form_errors(form) }}
    <div class="three fields">
        {{ form_row(form.code) }}
        {{ form_row(form.parent) }}
        {{ form_row(form.facetFilterCode) }}
    </div>
    <div class="fields">
        {{ form_row(form.enabled) }}
    </div>
</div>
{{ translationFormWithSlug(form.translations, '@SyliusAdmin/Taxon/_slugField.html.twig', taxon) }}

{% include '@SyliusAdmin/Taxon/_media.html.twig' %}
  1. 覆盖或创建(如果尚未存在)产品索引模板,在 templates/bundles/SyliusShopBundle/Product/index.html.twig 中。
{% extends '@SyliusShop/layout.html.twig' %}

{% block content %}
{% include '@SyliusShop/Product/Index/_header.html.twig' %}
<div class="ui stackable grid">
    <div class="four wide column">
        {% include '@SyliusShop/Product/Index/_sidebar.html.twig' %}
        <div class="ui fluid vertical menu"></div>
        <div class="ui fluid vertical menu"></div>
        {% include '@SyliusShop/Product/Index/_search.html.twig' %}
    </div>
    <div class="twelve wide column">
        {% include '@SyliusShop/Product/Index/_main.html.twig' %}
    </div>
</div>
{% endblock %}
  1. 运行 php bin/console do:mi:mi 以更新数据库模式。

  2. 最后,在 config/packages/translation.yaml 中添加翻译。

framework:
    default_locale: '%locale%'
    translator:
        paths:
            - '%kernel.project_dir%/translations'
        fallbacks:
            - '%locale%'
            - 'en'

演示

您可以在以下位置看到用户界面的结果:[这里](https://demo-sylius.asdoria.fr/en_US/taxons/category/caps)。
如果您想尝试创建过滤器,请转到管理员认证页面并使用以下凭据连接:

登录: asdoria
密码: asdoria

然后转到后台的分面过滤器页面

注意,我们为Sylius开发了其他几个开源插件,其演示和文档列在[以下页面](https://asdoria.github.io/)上。

用法

  1. 在后台,在配置部分,转到分面过滤器

  2. 点击编辑组创建按钮,创建一个新的组。在表单中填写一个代码,该代码将标识您的分面组。当然,这不会是用户侧的名称:您可以在下面的表单中指定每个语言的名称。组将帮助您组织您的过滤器并在您的网站上分组显示。

  3. 返回到上一个页面后,点击与您的新分面组链接的配置子项。以相同的方式填写表单。

  4. 返回到分面过滤器页面,点击创建以初始化针对特定税目创建的过滤器。在代码输入中,输入您希望为其创建过滤器的税目代码。此代码可以在税目的编辑页面上的 {your-domain}/admin/taxons/{id}/edit 下的 Slug 中找到。

  5. 有趣的部分从这里开始。转到 面相过滤器 页面,点击与您新过滤器相关联的 编辑面相。有多种选择可供选择,选择 创建一个属性面相

Edit facts

您现在可以用一些酷的东西填写表格,例如

  • 要过滤的属性
  • 段,代表过滤器的组。显然,您可以为每种语言更改面相的名称,以根据国家适应您的内容。
  1. 转到“分类”管理页面,点击与您想要过滤的产品类别相邻的三个灰色圆点。然后,点击“编辑”按钮。

Taxon interface

您可以选择用于您产品的面相过滤器。

Taxon interface

  1. 最后,在您的商店的用户端查看结果!

Facet filter on taxon page