CartShield Logo CartShield
Merchant Manual

CartShield Documentation

Detailed guide to rule configurations, server-side function architecture, and error handling.

1. Technical Architecture & Shopify Functions

CartShield uses Shopify's modern Checkout Validation API (purchase.validation.run). Unlike legacy script tag apps, checkout validation runs as a WebAssembly (Wasm) binary inside Shopify's core checkout pipeline.

⚡ Execution Speed: < 5 milliseconds (synchronous edge execution)
🔒 Security: 100% un-bypassable by Shop Pay, Apple Pay, PayPal, or Google Pay
📦 Zero Bloat: 0 KB added to store theme; 0 script tags injected

Why Client-Side Cart Blockers Fail (The Express Checkout Vulnerability)

Legacy cart validator apps inject frontend JavaScript onto the theme's /cart template to disable the checkout button. This design has critical security flaws:

❌ Legacy Frontend Cart Scripts
  • Bypassed via Express Checkout: 1-click Shop Pay, Apple Pay, Google Pay, and PayPal buttons bypass the cart page completely. Buyers place orders without triggering the script.
  • Client-Side Tampering: Tech-savvy buyers or bot scrapers can disable JavaScript in DevTools or edit the DOM to proceed.
  • Network Race Conditions: Slow 3G/4G connections allow buyers to click checkout before heavy scripts load.
  • Theme Speed Penalty: External script tags bloat storefront loading and hurt Google Lighthouse Core Web Vitals.
🛡️ CartShield Native Shopify Functions
  • 100% Server-Side & Un-Bypassable: Executes directly in Shopify's backend checkout engine before order creation or payment capture.
  • Enforced Across All Express Wallets: Shop Pay, Apple Pay, Google Pay, and PayPal checkouts are intercepted identically.
  • Zero Theme Code: Injects zero bytes of JavaScript or Liquid into store templates, keeping storefronts blazing fast.
  • Compiled WebAssembly: Validates full cart logic in ~2 milliseconds on Shopify's global edge infrastructure.

2. Core Validation Rule Engines

A. PO Box & Postal Locker Restriction

Interprets delivery address lines (Address 1, Address 2) using comprehensive regular expression patterns targeting variations of Post Office boxes, Army Post Offices (APO/FPO/DPO), and private parcel lockers.

Pattern Match: \b(P\.?O\.?\s*Box|Post\s*Office\s*Box|P\s*O\s*B|Box\s*[0-9]+|Locker|APO|FPO)\b/i

B. Add-on & Sample Kit Dependency

Protects sample items, swatch kits, or deeply discounted promotional gifts. Validates that if a restricted SKU is in the cart, at least one qualifying catalog item from an allowed collection is also present.

C. B2B / Wholesale Case Multiples

Guarantees wholesale orders conform to factory master carton counts. Evaluates the line item quantity with modulo arithmetic (qty % step === 0) and rejects arbitrary quantities.

D. Collection Minimum / Maximum Spend

Enforces subtotal thresholds on specific clearance, refrigerated, or export-only collections before allowing the order to complete.

3. Error Placement & Localization

CartShield delivers errors in two distinct targets depending on rule context:

  • Target Field Error ($.cart.deliveryGroups[0].deliveryAddress.address1): Highlighted directly under the buyer's shipping address field with red contextual feedback.
  • Page-Level Banner Error: Prominently displayed at the top of the checkout form for cart-level quantity or spending conditions.

Error copy is fully customizable in the CartShield admin and supports emoji indicators for clear customer guidance.

4. Shopify Metafield Storage Schema

To ensure sub-5ms evaluation without database roundtrips during checkout, all active rules are synced to the shop metafield:

Namespace: $app:cartshield_rules
Key: rules_config
Type: json