Custom recommendation rendering¶
You can use existing controllers to render recommendations outside the Page Builder. The controllers responsible for rendering block recommendations on the front-end are independent and can be used to render recommendations for specific strategies.
Each controller can be used to retrieve and display recommendations within a Twig template as follows:
1 2 3 4 5 | |
The controllers are placed in the Ibexa\Bundle\ConnectorRaptor\Controller\Block namespace.
Each controller always requires these two parameters:
- limit – the number of recommendations to render
- template – the path to the template
Any other required parameters are specific to each controller and are detailed in the Parameters column of the table below:
| Block name | Controller | Parameters | Recommendation item type |
|---|---|---|---|
| Content that have been seen along with the item category | ContentBasedOnProductCategoryBlockController::showAction() |
categoryId (integer),limit (integer),template (string) |
Content |
| Most popular content | PopularContentBlockController::showAction() |
limit (integer),template (string) |
Content |
| Most popular products | PopularItemsBlockController::showAction() |
showInStock (boolean),limit (integer),template (string) |
Product |
| Most popular products in category | PopularItemsInCategoryBlockController::showAction() |
categoryId (integer),showInStock (boolean),limit (integer),template (string) |
Product |
| Other customers have also seen | SimilarItemsBlockController::showAction() |
productCode (string),showInStock (boolean),limit (integer),template (string) |
Product |
| Other customers have also seen this content | SimilarContentBlockController::showAction() |
contentId (integer),limit (integer),template (string) |
Content |
| Other Customers Have also Purchased block | OtherCustomersAlsoPurchasedBlockController::showAction() |
productCode (string),limit (integer),template (string) |
Product |
| Personalized content recommendations | UserContentRecommendationsBlockController::showAction() |
limit (integer),template (string) |
Content |
| The Personal Shopping Assistant | UserItemRecommendationsBlockController::showAction() |
productCode (string),showInStock (boolean),limit (integer),template (string) |
Product |
| User's item history | UserItemHistoryBlockController::showAction() |
showInStock (boolean),limit (integer),template (string) |
Product |
Each template receives a recommendations Twig variable, which is a list containing either Ibexa\Contracts\ProductCatalog\Values\ProductInterface instances for product recommendations or Ibexa\Contracts\Core\Repository\Values\Content\Content instances for content recommendations.
Two generic templates are provided and can be used in ./templates/themes/<theme> directory:
@ibexadesign/ibexa/recommendations/_content_list.html.twigfor content items:
1 2 3 4 5 6 7 8 9 10 | |
@ibexadesign/ibexa/recommendations/_product_list.html.twigfor products:
1 2 3 4 5 6 7 | |
To fetch recommendations for the remaining modules, you need to create a custom controller and use a method from Ibexa\Contracts\ConnectorRaptor\Recommendations\RecommendationsServiceInterface.
Using this method, recommendations can be displayed on any page, for example on a specific product page, as shown below:
