nordcode.io/sylius-taxon-filter-plugin

Taxon filter plugin for Sylius.

dev-master / 1.6.x-dev 2020-04-27 10:26 UTC

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

  1. Install the package via composer:
     $ composer require nordcode.io/sylius-taxon-filter-plugin
    
  2. Update config/bundles.php:

     <?php
        
     return [
        
     ...
        
     Nordcode\SyliusTaxonFilterPlugin\NordcodeSyliusTaxonFilterPlugin::class => ['all' => true],
     ]
    
  3. Update your Taxon model class to implement our TaxonInterface:

     ...
     use Nordcode\SyliusTaxonFilterPlugin\Entity\TaxonInterface;
     use Nordcode\SyliusTaxonFilterPlugin\Entity\TaxonTrait;
       
     ...
        
     class Taxon extends BaseTaxon implements TaxonInterface
     {
         use TaxonTrait;
        
        ...
     }
    
  4. 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
     ...
    
  5. Include plugin configuration file in config/packages/_sylius.yaml:
     imports:
     ...
         - { resource: "@NordcodeSyliusTaxonFilterPlugin/Resources/config/config.yml" }
     ...
    
  6. Enable Gedmo Sortable Doctrine extension in config/packages/stof_doctrine_extensions.yaml:
     stof_doctrine_extensions:
     ...
         orm:
             default:
                 sortable: true
    
  7. 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
    
  8. 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.