List products in catalog¶
To list products from a specific catalog, you can either use the Content query Field, or a custom controller.
List products with Content query Field¶
To list products from a catalog in a Content query Field, add this Field to a Content Type definition.
Select the "Catalog" Query type. In parameters, provide the identifier of the catalog.
Save the Content Type definition and create a Content item based on it. The contents of the catalog are rendered automatically in the Field.
See Content query Field for more information.
List products with custom controller¶
You can also customize the rendering of products from a selected catalog with a custom controller and render it in a custom route.
In this example, create a custom controller for a promo catalog in
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
The controller uses
CatalogService to get the selected catalog by its identifier,
desk_promo (line 26).
The catalog provides a query, based on the filters you configured.
You can get the query with
$catalog->getQuery() and use it as criteria in product query (lines 27-29).
Next, add a route for rendering the promo content which points to the controller:
1 2 3 4
Finally, add a template to render a table with the products covered by the promo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
You can now preview the
<youdomain>/promo page and view the products
in the catalog.
The anonymous user does not have permission to view products and catalogs.
To view the catalog and its products, you need to either log in,
or give the anonymous user the