Collection of essential composables and utilities to work with promotions.
# Using pnpm
pnpm add @scayle/storefront-promotions
# Using yarn
yarn add @scayle/storefront-promotions
# Using npm
npm install @scayle/storefront-promotions
export default defineNuxtConfig({
modules: ['@scayle/storefront-promotions'],
// Optional module options
promotions: {
autoImports: true,
},
})
// Apply all possible promotion to the basket. Use default prioritization of promotions (by priority value)
const basket = useBasket()
const { applyPromotions } = useApplyPromotions()
await applyPromotions(basket.data)
// Apply all possible promotions to the basket with custom prioritization.
const sortByExpirationData = (promotions: ApplicablePromotion[]) => {
return promotions.toSorted(
(promotionA: ApplicablePromotion, promotionB: ApplicablePromotion) => {
return Date.parse(promotionA.promotion.schedule.to) -
Date.parse(promotionB.promotion.schedule.to)
},
)
}
const basket = useBasket()
const { applyPromotions } = useApplyPromotions({
getOrderedPromotions: sortByExpirationData,
})
await applyPromotions(basket.data)
You can configure the module by using the configuration key promotions
within nuxt.config.ts
. The following options are available:
-
autoImports
: Enables auto imports for composables and utilities. Default value:false
Licensed under the MIT License
SCAYLE is a full-featured e-commerce software solution that comes with flexible APIs. Within SCAYLE, you can manage all aspects of your shop, such as products, stocks, customers, and transactions.
Learn more about SCAYLE’s architecture and commerce modules in the Docs.