Skip to content

Qualifiers API Examples

This page demonstrates usage of some of the qualifiers provided Quasar.

CustomerTagQualifier

Definition

typescript
declare class CustomerTagQualifier {
    comparisonType: 'does' | 'does_not';
    operationType: 'match_one' | 'contains_one' | 'starts_with' | 'ends_with';
    tags: string[];

    constructor(comparisonType: 'does' | 'does_not', operationType: 'match_one' | 'contains_one' | 'starts_with' | 'ends_with', tags: string[]);
    qualifies(cart: any): boolean;
}

Usage

The CustomerTagQualifier class is used to check if a customer's tags meet certain criteria.

Parameters:

  • comparisonType: Specifies whether the tags should match ('does') or not match ('does_not').
  • operationType: Specifies the type of operation ('match_one', 'contains_one', 'starts_with', 'ends_with').
  • tags: An array of tags to compare against.

Example:

javascript
const qualifier = new CustomerTagQualifier('does', 'match_one', ['VIP', 'LOYAL']);
const isQualified = qualifier.qualifies(cart);

CartAmountQualifier

Definition

typescript
declare class CartAmountQualifier extends QualifierBase {
    amountLimit: number;

    constructor(comparisonType: 'less_than' | 'less_than_or_equal' | 'greater_than' | 'greater_than_or_equal' | 'equal_to' | 'is' | 'is_not', amountLimit: number);
    qualifies(cart: any): boolean;
}

Usage

The CartAmountQualifier class is used to check if the total amount in the cart meets certain criteria.

Parameters:

  • comparisonType: Specifies the type of comparison ('less_than', 'less_than_or_equal', 'greater_than', 'greater_than_or_equal', 'equal_to', 'is', 'is_not').
  • amountLimit: The amount to compare against.

Example:

javascript
const qualifier = new CartAmountQualifier('greater_than', 100);
const isQualified = qualifier.qualifies(cart);

TotalWeightQualifier

Definition

typescript
declare class TotalWeightQualifier extends QualifierBase {
    weightLimit: number;
    weightUnit: 'GRAMS' | 'LB' | 'POUNDS' | 'KG' | 'KILOGRAMS';

    constructor(comparisonType: 'less_than' | 'less_than_or_equal' | 'greater_than' | 'greater_than_or_equal' | 'equal_to' | 'is' | 'is_not', weightLimit: number, weightUnit: string);
    qualifies(cart: any): boolean;
}

Usage

The TotalWeightQualifier class is used to check if the total weight of items in the cart meets certain criteria.

Parameters:

  • comparisonType: Specifies the type of comparison ('less_than', 'less_than_or_equal', 'greater_than', 'greater_than_or_equal', 'equal_to', 'is', 'is_not').
  • weightLimit: The weight to compare against.
  • weightUnit: The unit of weight ('GRAMS', 'LB', 'POUNDS', 'KG', 'KILOGRAMS').

Example:

javascript
const qualifier = new TotalWeightQualifier('less_than', 10, 'KG');
const isQualified = qualifier.qualifies(cart);

CountryAndProvinceQualifier

Definition

typescript
declare class CountryAndProvinceQualifier {
    comparisonType: 'is_one' | 'is_not_one';
    validCountryAndProvinces: { [key: string]: string[] };

    constructor(comparisonType: 'is_one' | 'is_not_one', validCountryAndProvinces: { [key: string]: string[] });
    qualifies(cart: any): boolean;
}

Usage

The CountryAndProvinceQualifier class is used to check if the delivery address's country and province meet certain criteria.

Parameters:

  • comparisonType: Specifies whether the country and province should match ('is_one') or not match ('is_not_one').
  • validCountryAndProvinces: An object where keys are country codes and values are arrays of valid province codes.

Example:

javascript
const validRegions = { 'US': ['CA', 'NY'], 'CA': ['ON', 'BC'] };
const qualifier = new CountryAndProvinceQualifier('is_one', validRegions);
const isQualified = qualifier.qualifies(cart);

CountryCodeQualifier

Definition

typescript
declare class CountryCodeQualifier extends QualifierBase {
    validCountryCodes: string[];

    constructor(comparisonType: 'is_one' | 'is_not_one', validCountryCodes: string[]);
    qualifies(cart: any): boolean;
}

Usage

The CountryCodeQualifier class is used to check if the delivery address's country code meets certain criteria.

Parameters:

  • comparisonType: Specifies whether the country code should match ('is_one') or not match ('is_not_one').
  • validCountryCodes: An array of valid country codes.

Example:

javascript
const qualifier = new CountryCodeQualifier('is_one', ['US', 'CA']);
const isQualified = qualifier.qualifies(cart);

ShippingAddress1Qualifier

Definition

typescript
declare class ShippingAddress1Qualifier extends QualifierBase {
    address: string[];

    constructor(comparisonType: 'contains' | 'not_contains' | 'is_one' | 'is_not_one', address: string | string[], checkCase?: boolean);
    qualifies(cart: any): boolean;
}

Usage

The ShippingAddress1Qualifier class is used to check if the first line of the shipping address meets certain criteria.

Parameters:

  • comparisonType: Specifies the type of comparison ('contains', 'not_contains', 'is_one', 'is_not_one').
  • address: A string or array of strings to compare against.
  • checkCase: Optional boolean to specify if the comparison should be case-sensitive.

Example:

javascript
const qualifier = new ShippingAddress1Qualifier('contains', '123 Main St', true);
const isQualified = qualifier.qualifies(cart);