View Source BasicECommerce.SpecialOffer (Basic e-commerce v0.1.0)

Defines a special offer.

This module defines a BasicECommerce.SpecialOffer describing a special offer.

fields

Fields

  • description - a human-friendly description of the special offer
  • trigger_number - the number of matching products needed to trigger this special offer
  • discount_type - the type of discount (percentage on the price of the product or a fixed amount)
  • discount_value - the value of the discount, either a percentage as an integer between 0-100, or an amount in cents
  • apply_discount_to_all - if this is set, the discount is applyed to ALL product on which this discount applies, otherwise only maximum nb_discounted_items are discounted
  • nb_discounted_items - the maximum number of discounted items using this special offer (ignored if apply_discount_to_all is set)

Link to this section Summary

Types

(This type is managed by TypeCheck, which allows checking values against the type at runtime.)

(This type is managed by TypeCheck, which allows checking values against the type at runtime.)

t()

(This type is managed by TypeCheck, which allows checking values against the type at runtime.)

Functions

Compute the discounted price of a single unit of a product, applying the given BasicECommerce.SpecialOffer

Check if an offer is applicable to an BasicECommerce.OrderLine.

Link to this section Types

@type order_line() :: BasicECommerce.OrderLine.t()

(This type is managed by TypeCheck, which allows checking values against the type at runtime.)

Full definition:

order_line :: BasicECommerce.OrderLine.t()
@type product() :: BasicECommerce.Product.t()

(This type is managed by TypeCheck, which allows checking values against the type at runtime.)

Full definition:

product :: BasicECommerce.Product.t()
@type t() :: %BasicECommerce.SpecialOffer{
  applicable_sku: atom(),
  apply_discount_to_all: boolean(),
  description: String.t(),
  discount_type: :percentage | :fixed_amount,
  discount_value: integer(),
  nb_discounted_items: integer() | nil,
  trigger_number: integer()
}

(This type is managed by TypeCheck, which allows checking values against the type at runtime.)

Full definition:

t :: %BasicECommerce.SpecialOffer{
  applicable_sku: atom(),
  description: String.t(),
  trigger_number: integer(),
  discount_type: :percentage | :fixed_amount,
  discount_value: integer(),
  apply_discount_to_all: boolean(),
  nb_discounted_items: integer() | nil
}

Link to this section Functions

Link to this function

compute_total_price(offer, line)

View Source
@spec compute_total_price(offer :: t(), line :: order_line()) :: integer()

Compute the price of an BasicECommerce.OrderLine using the given BasicECommerce.SpecialOffer.

Link to this function

discounted_unit_price(offer, product)

View Source
@spec discounted_unit_price(offer :: t(), product :: product()) :: integer()

Compute the discounted price of a single unit of a product, applying the given BasicECommerce.SpecialOffer

Link to this function

is_applicable?(offer, line)

View Source
@spec is_applicable?(offer :: t(), line :: order_line()) :: boolean()

Check if an offer is applicable to an BasicECommerce.OrderLine.