Skip to content

Repository files navigation

Shopify Cart Transform API Template (July 2025)

A practical Shopify Node template for API development (July 2025) that demonstrates dynamic bundle creation using Cart Transform Functions and metafield-driven configuration.

This project is designed to help developers learn how to:

  • map a target product to a bundle product from an admin UI
  • store transformation rules in Shopify metafields
  • automatically expand cart line items at runtime via Shopify Functions

Key Features

  • Dynamic bundle creation at cart level (no fixed bundle products required)
  • Metafield-driven transform rules for flexible configuration
  • Admin product selection flow using Shopify App Bridge
  • Automatic cart transform creation when missing
  • Backend endpoints for reading and writing transform config
  • Shopify Function-based line expansion for performant checkout logic

Tech Stack

  • Frontend: React, Shopify Polaris, Shopify App Bridge
  • Backend: Node.js, Express
  • Shopify APIs: GraphQL Admin API, Metafields API, Cart Transform API
  • Runtime Logic: Shopify Functions (cartTransformRun)

Working Example

Scenario

You select:

  • Target product variant: Product A
  • Bundle product variant: Product B

The configuration is saved in metafield:

  • Namespace: app
  • Key: function-configs
  • Type: json

Input Cart

  • Product A (qty: 1)

Output Cart (After Transform)

  • Product A (qty: 1)
  • Product B (qty: 1)

Example Transform Payload

{
  "transform": [
    { "id": "target_variant_id", "title": "Target Product" },
    { "id": "bundle_variant_id", "title": "Bundle Product" }
  ]
}

Flow

  1. Product Selection (Frontend)

    • Admin picks target and bundle products from resource picker.
  2. Save Config (Backend + Metafield)

    • POST /api/cart/create-transform writes configuration using metafieldsSet.
  3. Resolve Transform (Backend)

    • GET /api/cart/transformations fetches existing transform and creates one if absent.
  4. Cart Runtime Execution (Shopify Function)

    • cartTransformRun(input) reads cart lines and metafield config.
    • If a target match is found, it expands the line with the mapped bundle variant.

Project Structure

/frontend
  ├── pages/HomePage.jsx
  ├── components/
/backend
  ├── index.js
  ├── shopify.js
  ├── product-creator.js
/functions
  ├── cartTransformRun.js
/graphql
  ├── CartTransformRunInput.query.graphql

License

This project is open source under the MIT License.


Author

StackWise Dev
Created for educational purpose to demonstrate Shopify Cart Transform API patterns with a Node template.

About

Dynamic bundle product system using Shopify Cart Transform API. Automatically expands cart items into bundled products using Shopify Functions and metafield-based configuration.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages