Skip to content

Catalog API

To get information about product catalogs and manage them, use CatalogServiceInterface.

Get catalog

To get a single catalog, use Ibexa\Contracts\ProductCatalog\CatalogServiceInterface::getCatalog() and provide it with catalog ID, or CatalogServiceInterface::getCatalogByIdentifier() and pass the identifier:

1
2
        $catalog = $this->catalogService->getCatalogByIdentifier($catalogIdentifier);
        $output->writeln($catalog->getName());

Get products in catalog

To get products from a catalog, request the product query from the catalog object with Ibexa\Contracts\ProductCatalog\Values\CatalogInterface::getQuery(). Then, create a new ProductQuery based on it and run a product search with ProductServiceInterface::findProduct():

1
2
3
4
5
6
        $productQuery = new ProductQuery(null, $catalog->getQuery());
        $products = $this->productService->findProducts($productQuery);

        foreach ($products as $product) {
            $output->writeln($product->getName());
        }

Create catalog

To create a catalog, you need to prepare a CatalogCreateStruct that contains: identifier, name, description and Criteria for filtering products. Then, pass this struct to CatalogServiceInterface::createCatalog():

1
2
3
4
5
6
7
8
        $catalogCreateStruct = new CatalogCreateStruct(
            $catalogIdentifier,
            $catalogCriterion,
            ['eng-GB' => 'Desk promo'],
            ['eng-GB' => 'Desk promo description'],
        );

        $this->catalogService->createCatalog($catalogCreateStruct);

Update catalog

Use CatalogServiceInterface::updateCatalog() to update an existing catalog. You must pass the catalog object and a CatalogUpdateStruct to the method. In the following example, you update the catalog to publish it:

1
2
3
4
        $catalogUpdateStruct = new CatalogUpdateStruct($catalog->getId());
        $catalogUpdateStruct->setTransition(Status::PUBLISH_TRANSITION);

        $this->catalogService->updateCatalog($catalog, $catalogUpdateStruct);