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

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

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

is_empty

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

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

Return number of items

num_lines

Return number of lines

offer_discounts

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

post_order_actions

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

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

Return total line price excluding tax

total_excl_tax_excl_discounts

Return total price excluding tax and discounts

total_incl_tax

Return total price inclusive of tax and discounts

total_incl_tax_excl_discounts

Return total price inclusive of tax but exclusive discounts

total_tax

Return total tax for a line

voucher_discounts

Return discounts from vouchers

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

A line of a basket (product and a quantity)

Common approaches on ordering basket lines: a) First added at top. That’s the history-like approach; new items are

added to the bottom of the list. Changing quantities doesn’t impact position. Oscar does this by default. It just sorts by Line.pk, which is guaranteed to increment after each creation.
  1. Last modified at top. That means items move to the top when you add another one, and new items are added to the top as well. Amazon mostly does this, but doesn’t change the position when you update the quantity in the basket view. To get this behaviour, add a date_updated field, change Meta.ordering and optionally do something similar on wishlist lines. Order lines should already be created in the order of the basket lines, and are sorted by their primary key, so no changes should be necessary there.
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

Return the stock/price info

unit_effective_price

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