SyliusCon 2025
Early Bird Deal
LogoLogo
🛣️ Roadmap💻 Sylius Demo💬 Community Slack
  • Sylius Documentation
  • Sylius Plugins
  • Sylius Stack
  • 📖Sylius 2.0 Documentation
    • Organization
      • Release Cycle
      • Backwards Compatibility Promise
      • Sylius Team
      • Sylius Roadmap
  • Getting Started with Sylius
    • Installation
    • Basic Configuration
    • Shipping & Payment
    • First Product
    • Customizing the Shop
    • Customizing Business Logic
    • Using API
    • Installing Plugins
    • Deployment
    • Summary
  • The Book
    • Introduction to Sylius
    • Installation
      • System Requirements
      • Sylius CE Installation
        • Sylius CE Installation with Docker
      • ➕Sylius Plus Installation
      • Upgrading Sylius CE
      • Upgrading Sylius Plus
    • Architecture
      • Architecture Overview
      • Architectural Drivers
      • Resource Layer
      • State Machine
      • Translations
      • E-Mails
      • Contact
      • Fixtures
      • Events
    • Configuration
      • Channels
      • Locales
      • Currencies
    • Customers
      • Customer & ShopUser
      • ➕Customer Pools
      • AdminUser
      • Addresses
        • Countries
        • Zones
        • Addresses
        • Address Book
    • Products
      • Products
      • Product Reviews
      • Product Associations
      • Attributes
      • Pricing
      • Catalog Promotions
      • Taxons
      • Inventory
      • ➕Multi-Source Inventory
      • Search
    • Carts & Orders
      • Orders
      • Cart flow
      • Taxation
      • Adjustments
      • Cart Promotions
      • Coupons
      • Payments
      • 🧩Invoices
      • Shipments
    • Support
    • Contributing
      • Contributing Code
        • Submitting a Patch
        • ⚠️Security Issues
        • Coding Standards
        • Conventions
        • Sylius License and Trademark
      • Contributing Translations
      • Key Contributors
  • The Customization Guide
    • Customizing Models
      • How to add a custom model?
      • How to add a custom translatable model?
    • Customizing Forms
      • How to add a live form for a custom model?
    • Customizing Styles
    • Customizing Validation
    • Customizing Menus
    • Customizing Templates
    • Customizing Translations
    • Customizing Flashes
    • Customizing State Machines
    • Customizing Grids
    • Customizing Fixtures
    • Customizing API
    • Customizing Serialization of API
    • Customizing Payments
      • How to integrate a Payment Gateway as a Plugin?
  • 🧑‍🍳The Cookbook
  • How to resize images?
  • How to add one image to an entity?
  • How to add multiple images to an entity?
  • Sylius 1.X Documentation
    • 📓Sylius 1.x Documentation
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2025 Sylius. All Rights Reserved

On this page
  • How to create a Taxon?
  • How to assign a Taxon to a Product?
  • What is the mainTaxon of a Product?

Was this helpful?

Edit on GitHub
  1. The Book
  2. Products

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:

/** @var FactoryInterface $taxonFactory */
$taxonFactory = $this->get('sylius.factory.taxon');

/** @var TaxonInterface $taxon */
$taxon = $taxonFactory->createNew();

$taxon->setCode('category');
$taxon->setName('Category');

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.

/** @var TaxonInterface $childTaxon */
$childTaxon = $taxonFactory->createNew();

$childTaxon->setCode('clothes');
$childTaxon->setName('Clothes');

$taxon->addChild($childTaxon);

Saving the Taxon:

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

/** @var TaxonRepositoryInterface $taxonRepository */
$taxonRepository = $this->get('sylius.repository.taxon');

$taxonRepository->add($taxon);

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

/** @var ProductInterface $product */
$product = $this->container->get('sylius.factory.product')->createNew();
$product->setCode('product_test');
$product->setName('Test');

/** @var TaxonInterface $taxon */
$taxon = $this->container->get('sylius.factory.taxon')->createNew();
$taxon->setCode('food');
$taxon->setName('Food');

/** @var RepositoryInterface $taxonRepository */
$taxonRepository = $this->container->get('sylius.repository.taxon');
$taxonRepository->add($taxon);


/** @var ProductTaxonInterface $productTaxon */
$productTaxon = $this->container->get('sylius.factory.product_taxon')->createNew();
$productTaxon->setTaxon($taxon);
$productTaxon->setProduct($product);

$product->addProductTaxon($productTaxon);

/** @var EntityManagerInterface $productManager */
$productManager = $this->container->get('sylius.manager.product');

$productManager->persist($product);
$productManager->flush();

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.

PreviousCatalog PromotionsNextInventory

Last updated 8 months ago

Was this helpful?