product

Get the price for chosen options, search and list products, and handle offers, gifting, size guides and back-in-stock alerts.

Use Salla.product for product actions in the browser. To load products for a page, use the product API module in a loader instead.

The product page's price updates through this module: when an option changes, getPrice asks the store for the new price. The useProduct hook listens to the result, so most themes never call it directly.

// the price for the options the customer picked
const { data } = await Salla.product.getPrice({
  id: 1234,
  quantity: 2,
  options: { 117414452: 11232214 },
});

Price and details

MethodParametersReturns
getPrice{ id, quantity?, options? } or FormDataThe price for that quantity and those options
getDetailsid, with?The product. with adds related data, such as ['images', 'sold_quantity', 'category'].
getSizeGuidesidThe product's size guides
offersidThe special offers on the product
MethodParametersReturns
fetch{ source, source_value?, ... }A list of products. See the sources below.
searchquery or { query, ... }Products that match the text
categoriesid?The product categories, or one category when you pass its id
fetchOptionsids, { with? }The options of several products at once

fetch takes a source and, for most sources, a source_value:

sourcesource_value
categories, brands, tags, selectedAn array of ids
searchThe search text
relatedOne product id
offers, latest, sales, wishlist, top-rated, reorderNone
const { data } = await Salla.product.fetch({ source: 'categories', source_value: [12, 15] });

Back in stock

MethodParametersDoes
availabilitySubscribeid, or { id, email }, or { id, country_code, mobile }Asks to tell the customer when the product is back. A guest passes an email or mobile.
isSubscribedToAvailabilityidtrue when this browser already subscribed. No request.
getAvailabilityChannelsnoneThe channels the store uses: 'email', 'sms' or both, comma-separated

Gifting

MethodParametersDoes
getGiftProductDetailsidThe gift options of a product: images and texts the customer can choose
uploadGiftImageFormDataUploads an image for the gift card
addProductGiftToCartid, payload, withRedirect?Adds the product as a gift. With withRedirect, goes to the address in the response.

Events

EventFires whenArguments
product::price.updated / product::price.updated.failedgetPriceresponse or error, product id
product::detail.fetched / product::detail.failedgetDetailsresponse or error, product id
product::size-guide.fetched / product::size-guide.failedgetSizeGuidesresponse or error, product id
product::offers.fetched / product::fetch.offers.failedoffersresponse or error, product id
product::offer.existedA cart response carries an offer for the added productthe offer
product::fetch.succeeded / product::fetch.failedfetchresponse or error
product::search.results / product::search.failedsearchresponse or error, query
product::categories.fetched / product::categories.failedcategoriesresponse or error
product::options.fetched / product::options.not.fetchedfetchOptionsresponse or error
product::availability.subscribed / product::availability.subscribe.failedavailabilitySubscriberesponse or error, product id
product::gift.fetched / product::gift.failedgetGiftProductDetailsresponse or error, product id
product::gift.image-upload.succeeded / product::gift.image-upload.faileduploadGiftImageresponse or error
product::gift.add-to-cart.succeeded / product::gift.add-to-cart.failedaddProductGiftToCartresponse or error, product id

Gotchas

  • search rejects a query that is the same as the one before it, so a double submit sends one request.
  • fetch checks source_value before sending: a missing array for categories or a non-number for related rejects at once.
  • fetch shows no messages, even on failure. Handle the rejected promise.
  • Pass offers the id as a number. An object such as { id } is not read and the call fails.
  • When getDetails fails on the server, the SDK fires product::availability.subscribe.failed, not detail.failed. Handle the promise instead of the event.

See also

On this page