nordcode.io / sylius-taxon-filter-plugin
Taxon filter plugin for Sylius.
Requires
- php: ^7.4
- gedmo/doctrine-extensions: ^2.4.12
- sylius/sylius: ^1.6
This package is not auto-updated.
Last update: 2024-04-24 01:29:21 UTC
README
This plugin allows linking specific facets to specific taxons in Sylius.
Sylius has a notion of Product Attributes, Product Options and the like. However, there is no built-in way to make these attributes or options only relevant to products in specific categories. This may be a problem if/when you want to allow visitors to filter product catalogue using these facets. This plugin makes it possible to link specific Attributes, Options and other facets to Taxons, thus making it easier for you to decide which filters to show where.
Installation
- Install the package via composer:
$ composer require nordcode.io/sylius-taxon-filter-plugin
Update
config/bundles.php
:<?php return [ ... Nordcode\SyliusTaxonFilterPlugin\NordcodeSyliusTaxonFilterPlugin::class => ['all' => true], ]
Update your
Taxon
model class to implement ourTaxonInterface
:... use Nordcode\SyliusTaxonFilterPlugin\Entity\TaxonInterface; use Nordcode\SyliusTaxonFilterPlugin\Entity\TaxonTrait; ... class Taxon extends BaseTaxon implements TaxonInterface { use TaxonTrait; ... }
- Extend the TaxonFilter model class found in this package and specify it as your resource class in
config/packages/_sylius.yaml
:... sylius_resource: resources: ... nordcode_sylius_taxon_filter_plugin.taxon_filter: classes: model: App\Entity\Taxonomy\TaxonFilter ...
- Include plugin configuration file in
config/packages/_sylius.yaml
:imports: ... - { resource: "@NordcodeSyliusTaxonFilterPlugin/Resources/config/config.yml" } ...
- Enable Gedmo Sortable Doctrine extension in
config/packages/stof_doctrine_extensions.yaml
:stof_doctrine_extensions: ... orm: default: sortable: true
- Include plugin routes in your route configuration (e.g.
config/routes.yaml
):nordcode_taxon_filter_admin: resource: "@NordcodeSyliusTaxonFilterPlugin/Resources/config/admin_routing.yaml" prefix: /admin
- Copy and execute the migrations from
src/Migrations/
:$ cp vendor/nordcode.io/sylius-taxon-filter-plugin/src/Migrations/* src/Migrations/ $ bin/console doctrine:migrations:migrate
Note: If you are running it on production, add the
-e prod
flag to this command.
Usage
The plugin provides an interface for the administrator to view, generate and enable/disable filters.
A console command is also provided. It may be especially useful should taxon filter generation take longer than your server or PHP settings allow. The command may be called as follows:
$ bin/console nordcode:taxon-filter:generate
Four types of taxon filters are generated by default:
- Child Taxon
- Price
- Product Attributes (one entry per Taxon per Attribute)
- Product Options (one entry per Option per Attribute)
Each of these types may be disabled by setting a parameter which matches its service name to false, for example, setting the following parameters in services.yaml
will cause only attribute filters to be generated:
parameters:
nordcode_sylius_taxon_filter_plugin.generator.category: false
nordcode_sylius_taxon_filter_plugin.generator.price: false
nordcode_sylius_taxon_filter_plugin.generator.product_attribute: true
nordcode_sylius_taxon_filter_plugin.generator.product_option: false
The application may implement additional generators. Each generator must implement Nordcode\SyliusTaxonFilterPlugin\Service\Generator\TaxonFilterGeneratorInteface
(and tagged with nordcode_sylius_taxon_filter_plugin.generator
if autoconfigration is off).
Please note that a custom generator will also not be used if a parameter with a name matching its service name is found and equals false
.