salla-offer-modal

A popup (built on salla-modal) that shows the special offer attached to a product: the offer name and message, the products, categories, brands or tags the customer gets the discount on (or a quantity

A popup (built on salla-modal) that shows the special offer attached to a product: the offer name and message, the products, categories, brands or tags the customer gets the discount on (or a quantity discount table), and the offer conditions. Put one instance on pages where offers can appear (usually once in the theme layout); it opens itself when the product API reports an existing offer (unless the customer ticked "remember my choice" for that offer), or when you call open(productId) or emit the offer-modal::open event with a product id. Nothing opens if the product has no offers. It emits the global promotion::viewed and promotion::clicked events for analytics.

Use it

In HTML or JSX, use the tag <salla-offer-modal> with the Attribute names below. In React, the wrapper takes the Property names (camelCase).

import { SallaOfferModal } from '@salla.sa/twilight-components-react/offer-modal';

Client-only. On the server this wrapper renders a placeholder (a skeleton, or nothing), and the real component mounts in the browser. Do not rely on it for content that search engines must see.

Example

import { useEffect } from 'react';
import { SallaOfferModal } from '@salla.sa/twilight-components-react/offer-modal';

export function Example() {
  useEffect(() => {
    document.querySelector('salla-offer-modal').open(123456);
  }, []);

  return (
    <SallaOfferModal />
  );
}

Methods

Call these on the element or a React ref.

open(product_id: number) => Promise<any>

Fetches the offers for a product and opens the modal showing the first one. If the product has no offers the modal is not opened; if the request fails, the modal opens with the error message.

ParameterTypeDescription
product_idnumberThe id of the product to look up offers for.

Returns Promise<any>: Promise that resolves when the request has finished (it has no meaningful value).

showOffer(offer: any) => Promise<void>

Renders the given offer inside the modal and emits promotion::viewed. It does not open the modal itself, so use open() unless the modal is already open.

ParameterTypeDescription
offeranyAn offer object as returned by the product offers API, with id, name, message, buy and get (get holds the discounted products, categories, brands, tags or a discounts_table).

Slots

SlotDescription
categoryReplaces the category badge markup for categories in the offer. Read once from the element's initial children; the text {name} and {url} are replaced with the category's values, and {tagIcon} with the tag icon.

Renders: <salla-button>, <salla-products-slider>, <salla-slider>, <salla-modal>, <salla-skeleton>, <salla-placeholder>.

On this page