I’m using the Shopify Bundles App, and I need to get the list of products included in a bundle along with their quantities using Liquid. How can I retrieve this data? Does Shopify store this information in Metafields, Line Item Properties, or another format? Any guidance or example Liquid code would be appreciated!
In the Shopify Bundles App, the list of products inside a bundle, along with their quantities, is stored in Line Item Properties when the bundle is added to the cart. You can access this data using Liquid in the cart or order summary.
How to Retrieve Bundle Products in Liquid
You can loop through cart items and check their line item properties like this:
{% for item in cart.items %}
<p><strong>Bundle Name:</strong> {{ item.product.title }}</p>
{% if item.properties %}
<ul>
{% for property in item.properties %}
{% if property.last != blank %}
<li>{{ property.first }}: {{ property.last }}</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endfor %}
Where Is the Bundle Data Stored?
- Line Item Properties: The Bundles App stores individual product details here when a bundle is added to the cart.
- Metafields (Sometimes): Some third-party bundle apps use metafields at the product level, but Shopify’s Bundles App primarily uses line item properties.
- Cart Attributes (Less Common): Used in custom implementations.
Thank you but I want this data in product page? is there any way or api that can do that?
The data is not available, you’ll need to link it yourself in a metafield for example, if you want to access it on the product page.
Also @Sam_Tim where did you get that information from?
To access the components of a line item within the cart you can use the item_components
property against line_item
.
Yes, @Luke Shopify’s Bundles API does provide item_components
for bundle breakdowns in the cart, but when using Shopify’s Bundles App, the bundle details are stored in Line Item Properties when added to the cart.
If you need to access bundle data outside the cart (e.g., on the product page), then yes, storing it in metafields would be necessary.
I got this information from working with Shopify’s Bundles App and its behavior in Liquid. Let me know if you need further clarification!
@Adam_Smith To display bundle details on the product page using metafields, follow these steps:
1. Store Bundle Data in Metafields
You need to manually add bundle component details to each parent product using Shopify’s Metafields. You can do this:
- Via Shopify Admin → Go to Products → Open a product → Scroll down to Metafields → Add a metafield for bundle components.
- Via Shopify GraphQL Admin API to store structured data.
Example Metafield Setup:
- Namespace:
custom.bundle
- Key:
components
- Type: JSON (to store multiple products)
- Value (Example JSON format):
json
[
{ "title": "Product A", "id": 123456789, "quantity": 2 },
{ "title": "Product B", "id": 987654321, "quantity": 1 }
]
2. Retrieve Metafields in Liquid
On the product page (product.liquid
or a section like main-product.liquid
), use this Liquid code:
{% if product.metafields.custom.bundle != blank %}
<h3>Bundle Includes:</h3>
<ul>
{% for item in product.metafields.custom.bundle.value %}
<li>{{ item.title }} (Qty: {{ item.quantity }})</li>
{% endfor %}
</ul>
{% endif %}
3. Optional: Display Linked Products
If you want to link the bundle components, modify the loop:
liquid
{% for item in product.metafields.custom.bundle.value %}
<li>
<a href="{{ shop.url }}/products/{{ item.id }}">{{ item.title }}</a>
(Qty: {{ item.quantity }})
</li>
{% endfor %}
This method allows you to display bundle components on the product page dynamically. Let me know if you need further details!
Can you please share the documentation which states the bundle details are stored in line item properties?
Hi @Adam_Smith @Luke ,
Shopify’s official documentation does not explicitly state that bundle details are stored in line item properties by default. However, line item properties are commonly used in custom development to store additional information about a product, such as bundle components, customizations, or other metadata.
How It Works:
When you create a bundle (a collection of multiple products sold as one), you can use metafields to store the bundle details (e.g., the individual products and their quantities). Then, when the bundle is added to the cart, you can programmatically include the bundle components as line item properties. This allows the bundle details to be visible in the cart, during checkout, and in the order details.
Example:
Here’s how you can achieve this:
- Store Bundle Data in Metafields:
Use metafields to store the bundle components as JSON. For example:
[
{ "title": "Product A", "id": 123456789, "quantity": 2 },
{ "title": "Product B", "id": 987654321, "quantity": 1 }
]
- Add Bundle Details to Line Item Properties :
Modify the Add to Cart form to include the bundle components as line item properties:
<form action="/cart/add" method="post">
<input type="hidden" name="id" value="{{ product.variants.first.id }}">
{% if product.metafields.custom.bundle != blank %}
{% for item in product.metafields.custom.bundle.value %}
<input type="hidden" name="properties[{{ item.title }}]" value="Qty: {{ item.quantity }}">
{% endfor %}
{% endif %}
<button type="submit">Add to Cart</button>
</form>
3 Result :
When the bundle is added to the cart, the bundle components will appear as line item properties, like this:
Product A: Qty: 2
Product B: Qty: 1
Documentation Reference:
While Shopify doesn’t specifically document this use case for bundles, you can refer to the official documentation on line item properties to understand how they work. Line item properties are designed to store additional information about a product, and developers often use them for custom functionality like bundles.
Please be very careful providing information to people then as you stated originally this information was available in line item properties, when it is not.
No, it is not possible as already mentioned.
Thanks for clarifying! I appreciate the help.