Taxons

In Sylius, Taxons work similarly to categories in other eCommerce systems. They allow you to organize and categorize your products in a highly flexible way, which is essential for modern eCommerce. The Taxon system is hierarchical, meaning you can create parent categories with nested subcategories.

Example of a Category Tree:

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.

Creating a Single (Non-Nested) Taxon:

Creating a Nested Taxon (Category Tree):

To create a tree of categories, first create the parent taxon. Then, create child taxons and add them as children to the parent.

Saving the Taxon:

Once the parent taxon is added to the system, all its child taxons will be saved automatically.

How to assign a Taxon to a Product?

To categorize your products, you need to assign them to taxons using the addProductTaxon() method.

Example: Assigning a Taxon to a Product

What is the mainTaxon of a Product?

The mainTaxon field in the product entity is used to designate the primary taxon for a product. It is especially useful for generating breadcrumbs or for custom logic like link generation.

To set the mainTaxon on a product, use the setMainTaxon() method.

Last updated

Was this helpful?