shoop.front.basket package

Submodules

shoop.front.basket.command_dispatcher module

class shoop.front.basket.command_dispatcher.BasketCommandDispatcher(request, basket=None)[source]

Bases: object

BasketCommandDispatcher handles (usually AJAX) requests that somehow update the basket. You should never instantiate BasketCommandDispatcher yourself – instead use get_basket_command_dispatcher().

All handle_* methods are expected to accept **kwargs.

commands_module = <module 'shoop.front.basket.commands' from '/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/stable/doc/../shoop/front/basket/commands.py'>
get_command_handler(command)[source]
handle(command, kwargs=None)[source]

Dispatch and handle processing of the given command.

Parameters:
  • command (unicode) – Name of command to run
  • kwargs (dict) – Arguments to pass to the command handler. If empty, request.POST is used.
Returns:

response

Return type:

HttpResponse

preprocess_kwargs(command, kwargs)[source]

Preprocess kwargs before they are passed to the given command handler. Useful for subclassing. Must return the new kwargs, even if it wasn’t mutated.

Parameters:
  • command – The name of the command about to be run
  • kwargs – dict of arguments
Returns:

dict of arguments

postprocess_response(command, kwargs, response)[source]

Postprocess the response dictionary (not a HTTP response!) before it is either turned into JSON or otherwise processed (in the case of non-AJAX requests).

Parameters:
  • command – The command that was run.
  • kwargs – The actual kwargs the command was run with.
  • response – The response the command returned.
Returns:

The response to be processed and sent to the client.

shoop.front.basket.commands module

shoop.front.basket.commands.handle_add(request, basket, product_id, quantity=1, supplier_id=None, **kwargs)[source]

Handle adding a product to the basket.

Parameters:
  • product_id – product ID to add (or if child_product_id is truey, the parent ID)
  • quantity – quantity of products to add
  • child_product_id – child product ID to add (if truey)
  • supplier_id – The supplier ID for the new line. If None, the first supplier is used.
shoop.front.basket.commands.handle_add_var(request, basket, product_id, quantity=1, **kwargs)[source]

Handle adding a complex variable product into the basket by resolving the combination variables. This actually uses kwargs, expecting var_XXX=YYY to exist there, where XXX is the PK of a ProductVariationVariable and YYY is the PK of a ProductVariationVariableValue. Confused yet?

Parameters:
  • quantity – Quantity of the resolved variation to add.
  • kwargs – Expected to contain var_* values, see above.
shoop.front.basket.commands.handle_del(request, basket, line_id, **kwargs)[source]

Handle deleting a distinct order line from the basket given its unique line ID.

Parameters:line_id – The line ID to delete.
Returns:
shoop.front.basket.commands.handle_clear(request, basket, **kwargs)[source]

Handle fully clearing the basket.

shoop.front.basket.commands.handle_add_campaign_code(request, basket, code)[source]
shoop.front.basket.commands.handle_update(request, basket, **kwargs)[source]

Handle updating a basket, i.e. deleting some lines or updating quantities.

This dispatches further to whatever is declared by the SHOOP_BASKET_UPDATE_METHODS_SPEC configuration entry.

shoop.front.basket.objects module

class shoop.front.basket.objects.BasketLine(source=None, **kwargs)[source]

Bases: shoop.core.order_creator.SourceLine

shop_product

ShopProduct object of this line.

Return type:shoop.core.models.ShopProduct
cache_info(request)[source]
type
set_quantity(quantity)[source]
can_delete
can_change_quantity
class shoop.front.basket.objects.BaseBasket(request, basket_name='basket')[source]

Bases: shoop.core.order_creator.OrderSource

save()[source]

Persist any changes made into the basket to storage.

One does not usually need to directly call this; ShoopFrontMiddleware will usually take care of it.

delete()[source]

Clear and delete the basket data.

finalize()[source]

Mark the basket as “completed” (i.e. an order is created/a conversion made).

This will also clear the basket’s data.

clear_all()[source]

Clear all data for this basket.

add_line(**kwargs)[source]
create_line(**kwargs)[source]
add_code(code)[source]
clear_codes()[source]
remove_code(code)[source]
get_lines()[source]
clean_empty_lines()[source]
add_product(supplier, shop, product, quantity, force_new_line=False, extra=None, parent_line=None)[source]
update_line(data_line, **kwargs)[source]
add_product_with_child_product(supplier, shop, product, child_product, quantity)[source]
delete_line(line_id)[source]
find_line_by_line_id(line_id)[source]
find_lines_by_parent_line_id(parent_line_id)[source]
orderable
get_validation_errors()[source]
get_product_ids_and_quantities()[source]
get_available_shipping_methods()[source]

Get available shipping methods.

Return type:list[ShippingMethod]
get_available_payment_methods()[source]

Get available payment methods.

Return type:list[PaymentMethod]

shoop.front.basket.order_creator module

class shoop.front.basket.order_creator.BasketOrderCreator(request=None)[source]

Bases: shoop.core.order_creator.OrderCreator

Initialize order creator.

Parameters:request (django.http.HttpRequest|None) – Optional request object for backward compatibility. Passing non-None value is DEPRECATED.

shoop.front.basket.storage module

exception shoop.front.basket.storage.BasketCompatibilityError[source]

Bases: Exception

exception shoop.front.basket.storage.ShopMismatchBasketCompatibilityError[source]

Bases: shoop.front.basket.storage.BasketCompatibilityError

exception shoop.front.basket.storage.PriceUnitMismatchBasketCompatibilityError[source]

Bases: shoop.front.basket.storage.BasketCompatibilityError

class shoop.front.basket.storage.BasketStorage[source]

Bases: object

load(basket)[source]

Load the given basket’s data dictionary from the storage.

Return type:dict
Raises:BasketCompatibilityError if basket loaded from the storage is not compatible with the requested basket.
save(basket, data)[source]

Save the given data dictionary into the storage for the given basket.

delete(basket)[source]

Delete the basket from storage.

finalize(basket)[source]

Mark the basket as “finalized” (i.e. completed) in the storage.

The actual semantics of what finalization does are up to each backend.

class shoop.front.basket.storage.DirectSessionBasketStorage[source]

Bases: shoop.front.basket.storage.BasketStorage

save(basket, data)[source]
delete(basket)[source]
class shoop.front.basket.storage.DictStoredBasket(id, shop_id, currency, prices_include_tax, data)[source]

Bases: object

classmethod from_basket_and_data(basket, data)[source]
classmethod from_dict(mapping)[source]
as_dict()[source]
class shoop.front.basket.storage.DatabaseBasketStorage[source]

Bases: shoop.front.basket.storage.BasketStorage

save(basket, data)[source]
delete(basket)[source]
finalize(basket)[source]
shoop.front.basket.storage.get_storage()[source]

Retrieve a basket storage object.

Returns:A basket storage object
Return type:BasketStorage

shoop.front.basket.update_methods module

class shoop.front.basket.update_methods.BasketUpdateMethods(request, basket)[source]

Bases: object

get_prefix_to_method_map()[source]

Override this method to link prefixes with their associated methods to call.

Format of the dictionary is: { FIELD_NAME_PREFIX: METHOD }.

METHOD is a function which accepts the keyword arguments given in update_basket_contents. It should perform the necessary changes to the basket_line and then return whether the value had changed or not. (See update_quantity or delete_line for examples.)

delete_line(line, **kwargs)[source]
update_quantity(line, value, **kwargs)[source]

Module contents

shoop.front.basket.get_basket_order_creator(request=None)[source]
shoop.front.basket.get_basket_view()[source]
shoop.front.basket.get_basket_command_dispatcher(request)[source]
Return type:shoop.front.basket.command_dispatcher.BasketCommandDispatcher
shoop.front.basket.get_basket(request)[source]
Return type:shoop.front.basket.objects.BaseBasket