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

Defines a line of an order.

This module defines a BasicECommerce.OrderLine describing a line of an order.

fields

Fields

  • sku - the SKU of the product described on this line
  • quantity - the number of product in this line

Link to this section Summary

Types

(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

Apply the best applicable offer to a given line.

Returns the total price of the given line without any applicable special offer

Link to this section Types

@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 special_offer() :: BasicECommerce.SpecialOffer.t()
@type t() :: %BasicECommerce.OrderLine{product: product(), quantity: integer()}

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

Full definition:

t :: %BasicECommerce.OrderLine{product: product(), quantity: integer()}

Link to this section Functions

Link to this function

apply_offers(line, applicable_special_offers)

View Source
@spec apply_offers(t(), [special_offer()]) :: {nil | special_offer(), integer()}

Apply the best applicable offer to a given line.

Returns a tuple with

  • the first element being the applied BasicECommerce.SpecialOffer or nil if no offer was applied
  • the second element being the total price after the special offer was applied
@spec raw_total(t()) :: integer()

Returns the total price of the given line without any applicable special offer