@scayle/storefront-promotions

2.2.0 • Public • Published

@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.

Other channels

Readme

Keywords

none

Package Sidebar

Install

npm i @scayle/storefront-promotions

Weekly Downloads

829

Version

2.2.0

License

MIT

Unpacked Size

37.7 kB

Total Files

28

Last publish

Collaborators

  • hector_gonzalez_ay
  • ay-henribeck
  • louisa_schmidt_ay
  • connor-pearson-ay
  • marcel-domke-ay
  • kyosifov
  • scayle-automation
  • cloud-panel-ay