Basket

The basket app handles shopping baskets, which essentially are a collection of products that hopefully end up being ordered.

Abstract models

class oscar.apps.basket.abstract_models.AbstractBasket(*args, **kwargs)[source]

Basket object

add(product, quantity=1, options=None)

Add a product to the basket

‘stock_info’ is the price and availability data returned from a partner strategy class.

The ‘options’ list should contains dicts with keys ‘option’ and ‘value’ which link the relevant product.Option model and string value respectively.

Returns (line, created).
line: the matching basket line created: whether the line was created or updated
add_product(product, quantity=1, options=None)[source]

Add a product to the basket

‘stock_info’ is the price and availability data returned from a partner strategy class.

The ‘options’ list should contains dicts with keys ‘option’ and ‘value’ which link the relevant product.Option model and string value respectively.

Returns (line, created).
line: the matching basket line created: whether the line was created or updated
all_lines()[source]

Return a cached set of basket lines.

This is important for offers as they alter the line models and you don’t want to reload them from the DB as that information would be lost.

applied_offers()[source]

Return a dict of offers successfully applied to the basket.

This is used to compare offers before and after a basket change to see if there is a difference.

can_be_edited[source]

Test if a basket can be edited

contains_voucher(code)[source]

Test whether the basket contains a voucher with a given code

flush()[source]

Remove all lines from basket.

freeze()[source]

Freezes the basket so it cannot be modified.

grouped_voucher_discounts[source]

Return discounts from vouchers but grouped so that a voucher which links to multiple offers is aggregated into one object.

is_empty[source]

Test if this basket is empty

is_quantity_allowed(qty)[source]

Test whether the passed quantity of items can be added to the basket

is_shipping_required()[source]

Test whether the basket contains physical products that require shipping.

is_tax_known[source]

Test if tax values are known for this basket

line_quantity(product, stockrecord, options=None)[source]

Return the current quantity of a specific product and options

merge(basket, add_quantities=True)[source]

Merges another basket with this one.

Basket:The basket to merge into this one.
Add_quantities:Whether to add line quantities when they are merged.
merge_line(line, add_quantities=True)[source]

For transferring a line from another basket to this one.

This is used with the “Saved” basket functionality.

num_items[source]

Return number of items

num_lines[source]

Return number of lines

offer_discounts[source]

Return basket discounts from non-voucher sources. Does not include shipping discounts.

post_order_actions[source]

Return discounts from vouchers

product_quantity(product)[source]

Return the quantity of a product in the basket

The basket can contain multiple lines with the same product, but different options and stockrecords. Those quantities are summed up.

reset_offer_applications()[source]

Remove any discounts so they get recalculated

set_as_submitted()

Mark this basket as submitted

shipping_discounts[source]

Return discounts from vouchers

submit()[source]

Mark this basket as submitted

thaw()[source]

Unfreezes a basket so it can be modified again

total_excl_tax[source]

Return total line price excluding tax

total_excl_tax_excl_discounts[source]

Return total price excluding tax and discounts

total_incl_tax[source]

Return total price inclusive of tax and discounts

total_incl_tax_excl_discounts[source]

Return total price inclusive of tax but exclusive discounts

total_tax[source]

Return total tax for a line

voucher_discounts[source]

Return discounts from vouchers

class oscar.apps.basket.abstract_models.AbstractLine(*args, **kwargs)[source]

A line of a basket (product and a quantity)

clear_discount()[source]

Remove any discounts from this line.

consume(quantity)[source]

Mark all or part of the line as ‘consumed’

Consumed items are no longer available to be used in offers.

discount(discount_value, affected_quantity, incl_tax=True)[source]

Apply a discount to this line

get_price_breakdown()[source]

Return a breakdown of line prices after discounts have been applied.

Returns a list of (unit_price_incl_tax, unit_price_excl_tax, quantity) tuples.

get_warning()[source]

Return a warning message about this basket line if one is applicable

This could be things like the price has changed

purchase_info[source]

Return the stock/price info

unit_effective_price[source]

The price to use for offer calculations

class oscar.apps.basket.abstract_models.AbstractLineAttribute(*args, **kwargs)[source]

An attribute of a basket line

Views

class oscar.apps.basket.views.BasketAddView(**kwargs)[source]

Handles the add-to-basket submissions, which are triggered from various parts of the site. The add-to-basket form is loaded into templates using a templatetag from module basket_tags.py.

product_model

alias of Product

oscar.apps.basket.views.apply_messages(request, offers_before)[source]

Set flash messages triggered by changes to the basket

oscar.apps.basket.views.get_messages(basket, offers_before, offers_after, include_buttons=True)[source]

Return the messages about offer changes