Shopping list design¶
To integrate the shopping list features to your own online store design, you can
- look at the default shopping list templates for the
standardtheme invendor/ibexa/shopping-list/src/bundle/Resources/views/themes/standard/shopping_list/directory - look at their overrides and complements in the
storefronttheme atvendor/ibexa/storefront/src/bundle/Resources/views/themes/storefront/shopping_list/
"Add to shopping list" widget¶
This widget contains a list of shopping lists indicating whether a product belongs to given list and allows to create a new shopping list on the fly.
It's used in the storefront theme in several places, embedded within a drop-down menu or a modal.

You can use the following Twig and TypeScript components to insert an "Add to shopping list" widget for a product into your storefront:
vendor/ibexa/shopping-list/src/bundle/Resources/views/themes/standard/shopping_list/component/add_to_shopping_list/add_to_shopping_list.html.twigdisplays a list of shopping lists preceded with checkboxes showing if the product is in it.vendor/ibexa/shopping-list/src/bundle/Resources/public/js/component/add.to.shopping.list.tshandles the interaction with the list of shopping lists' checkboxes and the new shopping list creation on the fly.vendor/ibexa/shopping-list/src/bundle/Resources/public/js/component/shopping.list.tshandles the REST API calls.vendor/ibexa/shopping-list/src/bundle/Resources/public/js/component/shopping.lists.list.tshandles the list of shopping lists.
The following example shows the setup of an "Add to shopping list" widget on a product full view page in the standard theme without implying the storefront theme.
For a base product, the variants are listed with an instance of the widget to demonstrate that it can be used several time on the same page.
Create an assets/js/add-to-shopping-list.ts that initializes the ShoppingList object and imports the script handling the widget interactions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Edit the webpack.config.js to enable TypeScript, set the aliases used in add-to-shopping-list.ts, and create an entry for it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Then, you can use the component in your template as in the following example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
To have a more complete example, let's continue with a product full view template which could work on a fresh installation.
In src/Controller/ProductViewController.php, create a new controller to add the variants to the product view:
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 | |
In templates/themes/standard/full/product.html.twig, create a template to render the product in full view:
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
In config/packages/views.yaml, configure the controller and template used to render the product full view:
1 2 3 4 5 6 7 8 9 10 | |

ShoppingList JS class and ibexaShoppingList global¶
The ShoppingList class is responsible for handling the shopping lists data and interactions with the REST API.
An object of this class contains the shopping lists and their entries, and has methods to manipulate the shopping lists.
An object of this class can be initialized with the shoppingList.init() function only once.
This initialization creates the window.ibexaShoppingList global variable pointing to the object.
If you have several scripts needing an instance of ShoppingList class, window.ibexaShoppingList is the indicator if it has been initialized already and it points to the object you should use.
Preferably initialize an object of class ShoppingList on the top of the script, then use window.ibexaShoppingList in the next lines.
It has the following methods:
createShoppingList(name)creates a new shopping list, updates the localwindow.ibexaShoppingList.shoppingListsproperty, and returns aPromiseresolving to an array with- at index 0, the created shopping list
- at index 1, the whole
ShoppingListobject with all the user's shopping lists
getShoppingLists()returns the localwindow.ibexaShoppingList.shoppingListspropertyloadShoppingLists()loads the shopping lists from the server, then updates the localwindow.ibexaShoppingList.shoppingListsproperty, and returns itloadShoppingList(list_identifier: string)returns aPromisefor the shopping list with the given identifieraddShoppingListEntries(list_identifier: string, product_codes: string[])adds entries to the given shopping list for the given product codes, and returns aPromisefor theResponseremoveShoppingListEntries(list_identifier: string, entry_identifiers: string[])remove from the given shopping list the given entries, and returns aPromiseresolving to aResponse
window.ibexaShoppingList.shoppingLists has the following data structure:
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 36 37 38 39 40 41 42 43 44 45 46 | |
ShoppingList object like the window.ibexaShoppingList has its data updated by the ShoppingList.createShoppingList and ShoppingList.loadShoppingLists methods.
The following script creates a shopping list, adds a product to it, then refreshes the local window.ibexaShoppingList.shoppingLists (as addShoppingListEntries method doesn't do it):
1 2 3 4 5 6 7 8 9 10 | |
If the "Add to shopping list" widget is used, it could be updated with the following addition to the previous script:
1 2 3 4 5 6 7 8 9 | |
JavaScript events¶
Shopping lists data changed event¶
The ibexa-shopping-list:shopping-lists-data-changed event is dispatched by the document.body
- on
ShoppingList.init()(and thewindow.ibexaShoppingListglobal variable is set) - on
ShoppingList.createShoppingList()(and thewindow.ibexaShoppingListglobal variable is updated) - on
ShoppingList.addShoppingListEntries() - on
ShoppingList.removeShoppingListEntries()
1 2 3 | |
Prepare request event¶
The ibexa-shopping-list:prepare-request event is dispatched by the document before each REST API call,
with the request details in the event's detail property.
1 2 3 | |
Built-in views¶
Some routes lead to views (when used with GET method) through controllers from the \Ibexa\Bundle\ShoppingList\Controller namespace.
Each uses a template which receives one or several variables, including forms to handle user interactions.
| Route path, name, and controller |
Template | Available variables | Description |
|---|---|---|---|
GET /shopping-listibexa.shopping_list.listShoppingListListController |
@ibexadesign/shopping_list/list.html.twig |
shopping_lists (Pagerfanta),bulk_delete_form,filter_form |
List of shopping lists |
GET /shopping-list/createibexa.shopping_list.createShoppingListCreateController |
@ibexadesign/shopping_list/create.html.twig |
form |
Form to create a new shopping list |
GET /shopping-list/{identifier}ibexa.shopping_list.viewShoppingListViewController |
@ibexadesign/shopping_list/view.html.twig |
move_entries_form,remove_entries_form,clear_form,delete_form |
Shopping list display |
GET /shopping-list/{identifier}/updateibexa.shopping_list.updateShoppingListUpdateController |
@ibexadesign/shopping_list/update.html.twig |
shopping_list,form |
Form to rename a shopping list |
GET /shopping-list/addibexa.shopping_list.addAddProductToShoppingListController |
@ibexadesign/shopping_list/add.html.twig |
products (ProductListInterface),forms (associative array of forms indexed on product code) |
List of products with for each the form to add it to a shopping list |
For all those templates (except add.html.twig), you'll find two implementations:
- a generic one for the
standardtheme invendor/ibexa/shopping-list/src/bundle/Resources/views/themes/standard/ - a more advanced demo one for the
storefronttheme invendor/ibexa/storefront/src/bundle/Resources/views/themes/storefront/
Instead of using the add route, you should consider using the "Add to shopping list" widget first.
The following example shows how to link to the shopping list listing page, using a heart icon:
1 2 3 | |
The \Ibexa\Bundle\Storefront\EventSubscriber\ShoppingList\DetailsViewSubscriber passes an additional selected_entries_form variable to the template.
This form allows to have "Add to cart" button for selected entries on top of the shopping list view in storefront theme
through vendor/ibexa/storefront/src/bundle/Resources/views/themes/storefront/shopping_list/view.html.twig.
User menu¶
The \Ibexa\Bundle\Storefront\EventSubscriber\ShoppingList\UserMenuSubscriber is responsible for
adding the "Shopping lists" item between "Orders" and "Change password" to the user menu
previously initiated by the \Ibexa\Bundle\Storefront\Menu\Builder\UserMenuBuilder.
You can look at how this subscriber tests that the user isn't anonymous
and then has the shopping_list/view policy (\Ibexa\Contracts\ShoppingList\Permission\Policy\ShoppingList\View)
before adding the "Shopping lists" item.