Use nested line items

Overview

This guide will show you how to use the nested line items in the storefront.

Prerequisites

As most guides, this guide is also built upon the Plugin base guide, but you don't necessarily need that. This guide will only extend views and shows how the Custom Product plugin handles this.

Make nested line item removable

If the nested line item should be removable in the cart, the removable property has to be set, either via view, or in an own controller action. Also, a form with an own path action has to be added:
1
{% block page_checkout_item_remove_icon %}
2
{% do nestedLineItem.setRemovable(true) %}
3
<form action="{{ path('/mycontroller/nested/remove', { 'id': nestedLineItem.id }) }}" method="post">
4
{{ parent() }}
5
</form>
6
{% endblock %}
Copied!

Make nested line item changeable

Most of the time, the root line item defines the nested line items, therefore there is a change button for its root line item in the cart. In the block of the change button, the variable isChangeable has to be set, and the button has to be surrounded with a link to the action like this:
1
{% block component_offcanvas_item_children_header_content_change_button %}
2
{% set isChangeable = true %}
3
{% set seo = seoUrl('frontend.detail.page', {
4
'productId': lineItem.children.first.referencedId,
5
'swagCustomizedProductsConfigurationEdit': lineItem.extensions.customizedProductConfiguration.id
6
})
7
%}
8
​
9
<a href="{{ seo }}" class="order-item-product-name" title="{{ label }}">
10
{{ parent() }}
11
</a>
12
{% endblock %}
Copied!

About extended functionality

Please notice: Nested line items can be implemented in various ways, so there's no telling what a default handling could be. Therefore, it is necessary to implement a change or remove handling by yourself.
Last modified 5mo ago