npm package: @scayle/storefront-promotions
Description: Collection of essential composables and utilities to work with promotions.
Author: SCAYLE Commerce Engine
Latest version: 3.3.0

# @scayle/storefront-promotions

<div align="center">
  <img src="https://cdn-prod.scayle.com/public/media/general/SCAYLE-Commerce-Engine-header.png" />
</div>

<div align="center">
  <h1>@scayle/storefront-promotions</h1>
</div>

<div align="center">
  <h4><a href="https://www.scayle.com/">Website</a></h4>
</div>

<div align="center">
  Collection of essential composables and utilities to work with promotions.
</div>
<br/>
<div align="center">
  <a href="https://www.npmjs.com/package/@scayle/storefront-promotions"><img src="https://img.shields.io/npm/v/@scayle/storefront-promotions/latest.svg?style=flat&colorB=007ec6" /></a>
  <a href="https://www.npmjs.com/package/@scayle/storefront-promotions"><img src="https://img.shields.io/npm/dm/@scayle/storefront-promotions.svg?style=flat&colorB=007ec6" /></a>
  <a href="https://www.npmjs.com/package/@scayle/storefront-promotions"><img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a>
  <a href="https://nuxt.com"><img src="https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js" /></a>
</div>

## Installation

```bash
# Using pnpm
pnpm add @scayle/storefront-promotions

# Using yarn
yarn add @scayle/storefront-promotions

# Using npm
npm install @scayle/storefront-promotions
```

## Usage

```ts
export default defineNuxtConfig({
  modules: ['@scayle/storefront-promotions'],
  // Optional module options
  promotions: {
    autoImports: true,
  },
})
```

```ts
// 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](https://opensource.org/license/mit/)

## What is SCAYLE?

[SCAYLE](https://scayle.com) 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](https://scayle.dev/en/core-documentation/welcome-to-scayle/getting-started) and commerce modules in the Docs.

## Other channels

- [LinkedIn](https://www.linkedin.com/company/scaylecommerce/)
- [Jobs](https://careers.smartrecruiters.com/ABOUTYOUGmbH/scayle)