PATRON.
Advanced Cart Setup
• 20 Minutes Setup

Multi-Product & Category-Specific Cart Discounts

Learn how to filter shopping cart items, identify perk-eligible product categories, and calculate itemized price reductions for complex e-commerce checkouts.

Select Tech Framework:

Step 1: Validate Member & Retrieve Active Perk Rules

Verify subscriber status using POST /api/merchant/qr-validate:

const res = await fetch('https://www.patron.com.ng/api/merchant/qr-validate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ptr_test_YOUR_API_KEY'
  },
  body: JSON.stringify({
    member_identifier: 'test.student@patron-sandbox.ng',
    perk_id: 'prk_student_20'
  })
});
const { perk } = await res.json();

Step 2: Iterate Cart Items & Calculate Itemized Discounts (JS)

Filter cart items by eligible category IDs and calculate item savings:

function processItemizedCart(cartItems, perk) {
  let totalDiscountNaira = 0;

  const processedItems = cartItems.map(item => {
    // Check if product category qualifies for perk
    const isCategoryEligible = perk.eligible_categories.includes(item.categoryId);
    
    if (isCategoryEligible) {
      const itemSubtotal = item.price * item.quantity;
      const itemDiscount = itemSubtotal * (perk.discount_percent / 100);
      totalDiscountNaira += itemDiscount;

      return {
        ...item,
        discountApplied: itemDiscount,
        finalItemTotal: itemSubtotal - itemDiscount
      };
    }
    
    return { ...item, discountApplied: 0, finalItemTotal: item.price * item.quantity };
  });

  return { processedItems, totalDiscountNaira };
}