ec_cart v0.1.0 Ec.Cart
Module to handle Ec.Cart
structures.
Summary
Functions
Add and adjutmens to the adjustment list
Add a new item into the %Ec.Cart{} structure, if the item already exists on the structure, this function will update the quantity
Creates an empty %Ec.Cart{} 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 and adjutmens to the adjustment list.
## Examples
iex> Ec.Cart.Adjustment.new(“shipping”,”Shipping”,
iex> adj = Ec.Cart.Adjustment.new(“shipping”,”Shipping”,
fn(x) ->
sb = Ec.Cart.subtotal(x)
case sb do
sb when sb > 25 -> 0
_-> 10
end
end)
iex> Ec.Cart.add_adjustment(ec_cart,adj)
%Ec.Cart{adjustments: [%Ec.Cart.Adjustment{description: “Shipping”,
function: #Function<6.52032458/1 in :erl_eval.expr/5>, name: "shipping"}],
items: [%Ec.Cart.Item{attr: %{}, ec_price: 3, ec_qty: 10, ec_sku: "SU04"}]}
Add a new item into the %Ec.Cart{} structure, if the item already exists on the structure, this function will update the quantity.
## Examples
iex> Ec.Cart.add_item(ec_cart,%Ec.Cart.Item{ ec_sku: "SU04", ec_qty: 10, ec_price: 3 })
%Ec.Cart{adjustments: [],items: [%Ec.Cart.Item{attr: %{}, ec_price: 3, ec_qty: 10, ec_sku: "SU04"}]}
Creates an empty %Ec.Cart{} structure, this strucure has by default and empty list of items and and empty list of adjustments
##Example
iex> ec_cart = Ec.Cart.new
%Ec.Cart{adjustments: [], items: []}
Calculate the sum of the result of multiply the price of each item and its quantity
iex> Ec.Cart.subtotal(ec_cart)
30