Skip to content

Commit f8796bc

Browse files
authored
Merge pull request #631 from Shopify/05-12-add_price_per_component_rust_example
Add bundle price per component rust example
2 parents 899ceeb + b10514a commit f8796bc

File tree

11 files changed

+4688
-0
lines changed

11 files changed

+4688
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "cart-transform-3-rust"
3+
version = "1.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
serde = { version = "1.0.13", features = ["derive"] }
8+
serde_json = "1.0"
9+
shopify_function = "0.8.1"
10+
graphql_client = "0.14.0"
11+
12+
[profile.release]
13+
lto = true
14+
opt-level = 'z'
15+
strip = true
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Cart Transform # LLM prompt for the example
3+
api_name: cart_transform
4+
api_version: 2025-01
5+
url: https://shopify.dev/docs/api/functions/2025-01/cart-transform
6+
example_name: Cart Transform Expand Operation Bundle Expansion
7+
example_description: This function implements a bundle expansion using the cart transform expand operation.
8+
---
9+
10+
# Cart Transform Expand Operation Example: Bundle Expansion
11+
12+
This example demonstrates how to implement a bundle expansion using the Cart Transform expand operation. When a customer adds a bundle product to their cart, it's automatically expanded into its individual components. For example, a "Holiday Package" bundle could be expanded into three separate products, each with its own price.
13+
14+
## How it Works
15+
16+
1. A customer adds a bundle product to their cart (e.g., "Holiday Package")
17+
2. The cart transform function reads the bundle configuration from the product's metafields
18+
3. The single cart line is expanded to show all component products with their respective prices
19+
20+
## Implementation Details
21+
22+
The function works by:
23+
1. Checking each cart line for bundle configuration in the product's metafields
24+
2. When found, it expands the cart line to include all component products
25+
3. Each component is added as a separate line item with its specified price
26+
4. The prices are adjusted according to the presentment currency rate
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "cart-transform-3-rust",
3+
"description": "cart-transform-3-rust"
4+
}

0 commit comments

Comments
 (0)