mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-17 02:18:01 +00:00
[Documentation] Taxons
This commit is contained in:
parent
e116e7847c
commit
49ef161db4
3 changed files with 79 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ The Book
|
|||
zones
|
||||
products
|
||||
attributes
|
||||
taxons
|
||||
addresses
|
||||
inventory
|
||||
orders
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
* :doc:`/book/zones`
|
||||
* :doc:`/book/products`
|
||||
* :doc:`/book/attributes`
|
||||
* :doc:`/book/taxons`
|
||||
* :doc:`/book/addresses`
|
||||
* :doc:`/book/inventory`
|
||||
* :doc:`/book/orders`
|
||||
|
|
|
|||
77
docs/book/taxons.rst
Normal file
77
docs/book/taxons.rst
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
.. index::
|
||||
single: Taxons
|
||||
|
||||
Taxons
|
||||
======
|
||||
|
||||
We understand Taxons in Sylius as you would normally define categories.
|
||||
Sylius gives you a possibility to categorize your products in a very flexible way, which is one of the most vital funtionalities
|
||||
of the modern e-commerce systems.
|
||||
The Taxons system in Sylius works in a hierarchical way.
|
||||
Let's see exemplary categories trees:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
Category
|
||||
|
|
||||
|\__ Clothes
|
||||
| \_ T-Shirts
|
||||
| \_ Shirts
|
||||
| \_ Dresses
|
||||
| \_ Shoes
|
||||
|
|
||||
\__ Books
|
||||
\_ Fantasy
|
||||
\_ Romance
|
||||
\_ Adventure
|
||||
\_ Other
|
||||
|
||||
Gender
|
||||
|
|
||||
\_ Male
|
||||
\_ Female
|
||||
|
||||
How to create a Taxon?
|
||||
----------------------
|
||||
|
||||
As always with Sylius resources, to create a new object you need a factory.
|
||||
If you want to create a single, not nested category:
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
/** @var FactoryInterface $taxonFactory */
|
||||
$taxonFactory = $this->get('sylius.factory.taxon');
|
||||
|
||||
/** @var TaxonInterface $taxon */
|
||||
$taxon = $taxonFactory->createNew();
|
||||
|
||||
$taxon->setCode('category');
|
||||
$taxon->setName('Category');
|
||||
|
||||
But if you want to have a tree of categories, create another taxon and add it as a **child** to the previously created one.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
/** @var TaxonInterface $childTaxon */
|
||||
$childTaxon = $taxonFactory->createNew();
|
||||
|
||||
$childTaxon->setCode('clothes');
|
||||
$childTaxon->setName('Clothes');
|
||||
|
||||
$childTaxon->setParent($taxon);
|
||||
$taxon->addChild($childTaxon);
|
||||
|
||||
Finally **the parent taxon** has to be added to the system using a repository, all its child taxons will be added with it.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
/** @var TaxonRepositoryInterface $taxonsRepository */
|
||||
$taxonRepository = $this->get('sylius.repository.taxon');
|
||||
|
||||
$taxonRepository->add($taxon);
|
||||
|
||||
Learn more
|
||||
----------
|
||||
|
||||
* :doc:`Taxonomy - Bundle Documentation </bundles/SyliusTaxonomyBundle/index>`
|
||||
* :doc:`taxonomy - Component Documentation </components/Taxonomy/index>`
|
||||
Loading…
Add table
Reference in a new issue