Add support for Stencil-style add-to-cart URLs #2728
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 routeShared handler logic:
product_idorskuqtyparametercouponcodeparameteradd→ 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=10off100Implementation Details
addToOrCreateCart,getCartId,applyCouponCode)checkout/route.ts)searchProductsAPI (searches Name, SKU, and Description)Testing
Manually tested with:
/cart.phpand/add-to-cart)Migration
Minor change - New files added to support legacy Stencil and new Catalyst style routes.