# View Source ExCart.Cart(ex_cart v1.0.0)

Module to handle `ExCart` structures.

# Summary

## Functions

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

Clear the Cart.

Clear items from the Cart.

Creates an empty %ExCart.Cart{} structure, this structure 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

View Source

## Examples

``````  iex> ex_cart = ExCart.Cart.new
...> fn(x) ->
...> sb = ExCart.Cart.subtotal(x)
...>  case sb do
...>    sb when sb > 25 -> 0
...>    _-> 10
...>   end
iex> end)
1``````

View Source

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

## Examples

``````  iex> ex_cart = ExCart.Cart.new
iex> ExCart.Cart.add_item(ex_cart,%ExCart.Item{ sku: "SU04", qty: 10, price: 3 })
%ExCart.Cart{adjustments: [],items: [%ExCart.Item{attr: %{}, price: 3, qty: 10, sku: "SU04"}]}``````

View Source

Clear the Cart.

View Source

# clear_items(cart)

View Source

Clear items from the Cart.

View Source

View Source

# new()

View Source

Creates an empty %ExCart.Cart{} structure, this structure has by default and empty list of items and and empty list of adjustments

## Examples

``````  iex> ExCart.Cart.new

View Source

## Examples

iex> excart = ExCart.Cart.new iex> adj = ExCart.Adjustment.new("shipping","Shipping", ...> fn(x) -> ...> sb = ExCart.Cart.subtotal(x) ...> case sb do ...> sb when sb > 25 -> 0 ...> -> 10 ...> end iex> end) iex> ex_cart = ExCart.Cart.add_adjustment(ex_cart, adj) iex> length ex_cart.adjustments 1 iex> ex_cart = ExCart.Cart.remove_adjustment(ex_cart, "shipping") iex> length ex_cart.adjustments 0

# subtotal(cart)

View Source

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

## Examples

``````  iex> ex_cart = ExCart.Cart.new
iex> ex_cart = ExCart.Cart.add_item(ex_cart,%ExCart.Item{ sku: "SU04", qty: 10, price: 2 })
iex> ExCart.Cart.subtotal(ex_cart)
20``````

# total(cart)

View Source

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

## Examples

``````iex> ex_cart = ExCart.Cart.new
iex> ex_cart = ExCart.Cart.add_item(ex_cart,%ExCart.Item{ sku: "SU04", qty: 5, price: 3 })