Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.shopi.lk/llms.txt

Use this file to discover all available pages before exploring further.

shop.getDiscounts()

Returns currently active discounts — both shop-wide and product-specific. Use these to display sale badges, banners, and strikethrough prices.
const { shop_wide, product_specific } = await shop.getDiscounts();

Response

{
  shop_wide: Discount[];
  product_specific: Discount[];
}

Discount type

{
  id: string;
  name: string;
  discount_percentage: number;
  applies_to: string;
  product_id: string | null;
  start_date: string;
  end_date: string;
}
Only discounts where start_date <= now <= end_date are returned.

Example — Sale banner

const { shop_wide } = await shop.getDiscounts();

if (shop_wide.length > 0) {
  const topDeal = shop_wide[0];
  saleBanner.textContent = `${topDeal.name}${topDeal.discount_percentage}% off everything!`;
  saleBanner.style.display = 'block';
}

Example — Product sale badge

const { product_specific } = await shop.getDiscounts();

// Build a map of product_id → discount
const discountMap = new Map(
  product_specific.map(d => [d.product_id, d])
);

// Apply to product cards
products.forEach(product => {
  const discount = discountMap.get(product.id);
  if (discount) {
    const badge = document.createElement('span');
    badge.className = 'sale-badge';
    badge.textContent = `${discount.discount_percentage}% OFF`;
    productCard.appendChild(badge);
  }
});