Cart Object

class shoppingCart.cart.Cart(site=None, customer=None)[source]

Collection of CartItem objects.

add_item(product, price=0.0, quantity=1, taxes=[], options={})[source]

To add or update product, price, quantity, taxes and options in CartItem object.

Parameters:
  • product – Unique id or name of Product object or instance of Product.
  • price – Product price.
  • quantity – Product quantity(default 1).
  • taxes – Taxes of the product(default []).
  • options – Options of the product(default {}).
update_item(product, quantity, option_values=[])[source]

To update CartItem object quantity.

Parameters:
  • product – Unique id or name of Product object or instance of Product.
  • quantity – Updated quantity.
  • option_values – Option values of the product(default []).
remove_item(product, option_values=[])[source]

To remove existing CartItem object related to product.

Parameters:
  • product – Unique id or name of Product object or instance of Product.
  • option_values – Option values of the product(default []).
remove_items()[source]

To remove all existing CartItem objects.

find_item(product, option_values=[])[source]

To find CartItem object related to product.

Parameters:
  • product – Unique id or name of Product object or instance of Product.
  • option_values – Option values of the product(default []).
Returns:

CartItem object if cart item is exist else None.

get_items()[source]
Returns:List of CartItem objects.
add_discount(amount, type='percentage')[source]

To apply discount.

Parameters:
  • amount – Discount amount.
  • type – Discount type like ‘percentage’ or ‘amount’(default amount).
remove_discounts()[source]

To remove all applied discounts.

get_discounts()[source]
Returns:List of applied discounts.
add_tax(amount, type='percentage')[source]

To apply taxes.

Parameters:
  • tax – Tax amount according to country region.
  • type – Tax type like ‘percentage’ or ‘fixed’(default percentage).
Returns:

True if tax is applied and tax is already exist then False.

remove_tax(amount, type='percentage')[source]

To remove existing tax.

Parameters:
  • amount – Tax amount according to country region.
  • type – Tax type like ‘percentage’ or ‘fixed’(defualt percentage).
remove_taxes()[source]

To remove all applied taxes.

find_tax(amount, type='percentage')[source]

To find applied tax.

Parameters:
  • amount – Tax amount according to country region.
  • type – Tax type like ‘percentage’ or ‘fixed’(defualt percentage).
Returns:

True if tax is exist else False.

get_taxes()[source]
Returns:list of applied taxes.
sub_total()[source]
Returns:Total cart amount(without discount deduction).
total_discount()[source]
Returns:Total discount amount.
total_untaxed_amount()[source]
Returns:Untaxed amount after deducating discount amount.
total_tax()[source]
Returns:Total tax amount.
total()[source]
Returns:Total amount(tax excluded or tax included) by adding total untaxed amount, total tax and shipping charge.
count()[source]
Returns:Total quantity.
clear()[source]

To clean Cart Object.

is_empty
Returns:True if cart has an item else False.
is_discount_applied
Returns:True if discount is applied else False.
has_taxes
Returns:True if tax is applied else False.
shipping_charge
Returns:Shipping charge.