3.4.2 • Published 3d ago
@scayle/storefront-promotions
Licence
MIT
Version
3.4.2
Deps
0
Size
53 kB
Vulns
0
Weekly
0
@scayle/storefront-promotions
@scayle/storefront-promotions
Collection of essential composables and utilities to work with promotions.
Installation
# Using pnpm
pnpm add @scayle/storefront-promotions
# Using yarn
yarn add @scayle/storefront-promotions
# Using npm
npm install @scayle/storefront-promotions
Usage
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)
Module Configuration
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
License
Licensed under the MIT License
What is SCAYLE?
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.