ec_cart v0.1.3 EcCart

Module to handle EcCart structures.

Summary

Functions

Add and adjutmens to the adjustment list

Add a new item into the %EcCart{} structure, if the item already exists on the structure, this function will update the quantity

Creates an empty %EcCart{} structure, this strucure has by default and empty list of items and and empty list of adjustments

Calculate the sum of the result of multiply the price of each item and its quantity

Calculates the total of the cart that include: subtotal + adjustments

Functions

add_adjustment(ec_cart, ec_cart_adjustment)

Add and adjutmens to the adjustment list.

## Examples

iex> ec_cart = EcCart.new
  iex> adj = EcCart.Adjustment.new("shipping","Shipping", 
  ...> fn(x) -> 
  ...> sb = EcCart.subtotal(x)
  ...>  case sb do
  ...>    sb when sb > 25 -> 0
  ...>    _-> 10
  ...>   end
  iex> end)
  iex> ec_cart = EcCart.add_adjustment(ec_cart,adj)
  iex> length ec_cart.adjustments
  1
add_item(ec_cart, ec_cart_item)

Add a new item into the %EcCart{} structure, if the item already exists on the structure, this function will update the quantity.

## Examples

iex> ec_cart = EcCart.new
  iex> EcCart.add_item(ec_cart,%EcCart.Item{ ec_sku: "SU04", ec_qty: 10, ec_price: 3 })
  %EcCart{adjustments: [],items: [%EcCart.Item{attr: %{}, ec_price: 3, ec_qty: 10, ec_sku: "SU04"}]}
new()

Creates an empty %EcCart{} structure, this strucure has by default and empty list of items and and empty list of adjustments

## Examples

iex> EcCart.new
  %EcCart{adjustments: [], items: []}
subtotal(ec_cart)

Calculate the sum of the result of multiply the price of each item and its quantity

## Examples

iex> ec_cart = EcCart.new
  iex> ec_cart = EcCart.add_item(ec_cart,%EcCart.Item{ ec_sku: "SU04", ec_qty: 10, ec_price: 2 })
  iex> EcCart.subtotal(ec_cart)
  20
total(ec_cart)

Calculates the total of the cart that include: subtotal + adjustments

## Examples

iex> ec_cart = EcCart.new
iex> ec_cart = EcCart.add_item(ec_cart,%EcCart.Item{ ec_sku: "SU04", ec_qty: 5, ec_price: 3 })
iex> adj = EcCart.Adjustment.new("shipping","Shipping", 
...> fn(x) -> 
...> sb = EcCart.subtotal(x)
...>case sb do
...>  sb when sb > 25 -> 0
...>  _-> 10
...>end
...>end)
iex> ec_cart = EcCart.add_adjustment(ec_cart,adj)
iex> EcCart.total(ec_cart)
25