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 },
});
Method Parameters Returns 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
Method Parameters Returns 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_valuecategories, 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 ] });
Method Parameters Does 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.getAvailabilityChannelsnone The channels the store uses: 'email', 'sms' or both, comma-separated
Method Parameters Does 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.
Event Fires when Arguments 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 product the 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
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.