Skip to content

Conversation

@BC-AdamWard
Copy link
Contributor

What/Why?

Adds support for BigCommerce Stencil-style add-to-cart URLs via Next.js route handlers. This enables adding products to cart using query parameters, matching the behavior of Stencil stores for compatibility.

Changes

  • New route handlers:

    • /cart.php - Stencil compatibility route
    • /add-to-cart - Catalyst-native route
  • Shared handler logic:

    • Product lookup by product_id or sku
    • Quantity support via qty parameter
    • Coupon code application via couponcode parameter
    • Action-based redirects (add → cart, buy → checkout)

Features

✅ Product lookup by ID or SKU
✅ Quantity parameter support
✅ Coupon code application
✅ Action-based redirects (cart/checkout)
✅ Comprehensive error handling
✅ User-friendly error messages via server toasts
✅ Optimized SKU search (limited to 10 products, stops at first match)
✅ Verifies checkout exists before applying coupons

Supported URL Patterns

  • /cart.php?action=add&product_id=123
  • /cart.php?action=buy&sku=xlredtshirt
  • /add-to-cart?action=add&product_id=123&qty=3
  • /add-to-cart?action=add&product_id=123&couponcode=10off100

Implementation Details

  • Uses Next.js Route Handlers (optimal for GET requests and redirects)
  • Leverages existing Catalyst utilities (addToOrCreateCart, getCartId, applyCouponCode)
  • GraphQL queries for product lookup and validation
  • Error handling follows Catalyst patterns (matches checkout/route.ts)
  • SKU search uses searchProducts API (searches Name, SKU, and Description)

Testing

Manually tested with:

  • Product ID lookup
  • SKU lookup
  • Quantity parameter
  • Coupon code application
  • Both routes (/cart.php and /add-to-cart)
  • Error handling scenarios

Migration

Minor change - New files added to support legacy Stencil and new Catalyst style routes.

Implement route handlers to support BigCommerce Stencil add-to-cart URL
patterns. Enables adding products to cart using query parameters
(product_id, sku, qty, couponcode) with support for both 'add' (redirect
to cart) and 'buy' (redirect to checkout) actions.

- Add route handlers at /cart.php and /add-to-cart
- Support product lookup by ID or SKU
- Apply coupon codes when provided
- Comprehensive error handling with user-friendly messages
- Follows Catalyst patterns and contribution guidelines

Refs: https://developer.bigcommerce.com/docs/storefront/cart-checkout/guide/add-to-cart-urls
@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

🦋 Changeset detected

Latest commit: e1e2081

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Nov 19, 2025

@BC-AdamWard is attempting to deploy a commit to the BigCommerce Platform Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@chanceaclark chanceaclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @BC-AdamWard thanks for opening this, however I have concerns with this.

I am not entirely sure we want to expose more route handlers for this functionality. Reason being is that we exposed this in Stencil because merchants/devs didn't have access to the underlying code. In the case of Catalyst they should have full access to the codebase in which we supply a server action for this functionality addToOrCreateCart. Using server actions implicitly creates an API route that is bound to both server and client code which is better than maintaining than a manual Route handler. If there is a use-case I am forgetting about, let me know so we can explore what the best solution should be.

I am "Requesting Changes" here to make sure this doesn't accidently get merge in without have more a discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants