Skip to content

Discounts API Examples ​

This page demonstrates usage of some of the discount classes provided Quasar.

PercentageDiscount ​

Definition ​

typescript
declare class PercentageDiscount {
    amount: number;

    constructor(amount: number);
    getDiscount(): { percentage: { value: number } };
}

Usage ​

The PercentageDiscount class is used to create a discount based on a percentage.

Parameters: ​

  • amount: The percentage amount of the discount.

Example: ​

javascript
const discount = new PercentageDiscount(10);
const discountDetails = discount.getDiscount();
console.log(discountDetails); // { percentage: { value: 10 } }

FixedPriceDiscount ​

Definition ​

typescript
declare class FixedPriceDiscount {
    amount: number;
    appliesToEachItem: boolean;

    constructor(amount: number, appliesToEachItem?: boolean);
    getDiscount(): { fixedAmount: { amount: number, appliesToEachItem?: boolean } };
}

Usage ​

The FixedPriceDiscount class is used to create a discount based on a fixed price.

Parameters: ​

  • amount: The fixed amount of the discount.
  • appliesToEachItem: Optional boolean to specify if the discount applies to each item.

Example: ​

javascript
const discount = new FixedPriceDiscount(5, true);
const discountDetails = discount.getDiscount();
console.log(discountDetails); // { fixedAmount: { amount: 5, appliesToEachItem: true } }