shuup.core.basket package¶
Submodules¶
shuup.core.basket.command_dispatcher module¶
-
class
shuup.core.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 'shuup.core.basket.commands' from '/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/doc/../shuup/core/basket/commands.py'>¶
-
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 newkwargs
, 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.
-
shuup.core.basket.command_middleware module¶
-
class
shuup.core.basket.command_middleware.
BaseBasketCommandMiddleware
[source]¶ Bases:
object
A basket command middleware to pre-process the kwargs and post-process the response.
shuup.core.basket.commands module¶
-
shuup.core.basket.commands.
handle_add
(request, basket, product_id, quantity=1, unit_type='internal', 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.
- product_id – product ID to add (or if
-
shuup.core.basket.commands.
handle_add_var
(request, basket, product_id, quantity=1, unit_type='internal', **kwargs)[source]¶ Handle adding a complex variable product into the basket by resolving the combination variables. This actually uses
kwargs
, expectingvar_XXX=YYY
to exist there, whereXXX
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.
-
shuup.core.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:
shuup.core.basket.objects module¶
-
class
shuup.core.basket.objects.
BasketLine
(source=None, **kwargs)[source]¶ Bases:
shuup.core.order_creator.SourceLine
-
shop_product
¶ ShopProduct object of this line.
Return type: shuup.core.models.ShopProduct
-
type
¶
-
can_delete
¶
-
can_change_quantity
¶
-
-
class
shuup.core.basket.objects.
BaseBasket
(request, basket_name='basket', shop=None, **kwargs)[source]¶ Bases:
shuup.core.order_creator.OrderSource
-
save
()[source]¶ Persist any changes made into the basket to storage.
One does not usually need to directly call this;
ShuupFrontMiddleware
will usually take care of it.
-
finalize
()[source]¶ Mark the basket as “completed” (i.e. an order is created/a conversion made).
This will also clear the basket’s data.
-
customer
¶
-
orderer
¶
-
shipping_address
¶
-
billing_address
¶
-
shipping_method
¶
-
payment_method
¶
-
customer_comment
¶
-
extra_data
¶
-
shipping_data
¶
-
payment_data
¶
-
is_empty
¶
-
add_product
(supplier, shop, product, quantity, force_new_line=False, extra=None, parent_line=None)[source]¶
-
get_basket_line
(line_id)[source]¶ Get basket line by line id.
Return type: BasketLine
-
find_lines_by_parent_line_id
(parent_line_id)[source]¶ Find basket data lines by parent line id.
Return type: Iterable[dict]
-
orderable
¶
-
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]
-
shuup.core.basket.order_creator module¶
-
class
shuup.core.basket.order_creator.
BasketOrderCreator
(request=None)[source]¶ Bases:
shuup.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.
shuup.core.basket.storage module¶
-
class
shuup.core.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.
Rtype str: Returns: The unique identifier of the basket just created
-
-
class
shuup.core.basket.storage.
BaseDatabaseBasketStorage
[source]¶ Bases:
shuup.core.basket.storage.BasketStorage
-
model
¶ alias of
Basket
-
-
shuup.core.basket.storage.
get_storage
()[source]¶ Retrieve a basket storage object.
Returns: A basket storage object. Return type: BasketStorage
shuup.core.basket.update_methods module¶
-
class
shuup.core.basket.update_methods.
BasketUpdateMethods
(request, basket)[source]¶ Bases:
object
Initialize.
-
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. (Seeupdate_quantity
ordelete_line
for examples.)
-
Module contents¶
-
shuup.core.basket.
get_basket_command_dispatcher
(request)[source]¶ Return type: shuup.front.basket.command_dispatcher.BasketCommandDispatcher
-
shuup.core.basket.
get_basket
(request, basket_name='basket', basket_class=None)[source]¶ Get the basket cached in the request or create and cache a new one.
The basket_class is used when creating a new basket, i.e. when the request doesn’t already have a basket cached with the given name. If no basket_class is given, will load a class using the
SHUUP_BASKET_CLASS_SPEC
setting.Return type: shuup.front.basket.objects.BaseBasket