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/runner/work/shuup/shuup/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.
- 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:
SourceLine
Initialize SourceLine with a given source and data.
- Parameters:
source (OrderSource) – The
OrderSource
thisSourceLine
belongs to.kwargs – Data for the
SourceLine
.
- __init__(source=None, **kwargs)[source]
Initialize SourceLine with a given source and data.
- Parameters:
source (OrderSource) – The
OrderSource
thisSourceLine
belongs to.kwargs – Data for the
SourceLine
.
- property shop_product
ShopProduct object of this line.
- Return type:
- property type
- property can_delete
- property can_change_quantity
- class shuup.core.basket.objects.BaseBasket(request, basket_name='basket', shop=None, **kwargs)[source]
Bases:
OrderSource
- uncache()[source]
Uncache processed lines.
Should be called after changing the contents and before (re)accessing lines with
get_final_lines
.
- 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.
- property customer
- property orderer
- property shipping_address
- property billing_address
- property shipping_method
- property payment_method
- property customer_comment
- extra_data
- shipping_data
- payment_data
- add_code(code)[source]
Add a code to this OrderSource.
At this point it is expected that the customers permission to use the code has already been checked by the caller.
The code will be converted to text.
- clear_codes()[source]
Remove all codes from this OrderSource.
- Returns:
True if there were any codes before clearing.
- Return type:
- property is_empty
- add_product(supplier, shop, product, quantity, force_new_line=False, extra=None, parent_line=None)[source]
- find_lines_by_parent_line_id(parent_line_id)[source]
Find basket data lines by parent line id.
- Return type:
Iterable[dict]
- property orderable
- class shuup.core.basket.objects.Basket(request, basket_name='basket', shop=None, **kwargs)[source]
Bases:
BaseBasket
shuup.core.basket.order_creator module
- class shuup.core.basket.order_creator.BasketOrderCreator(request=None)[source]
Bases:
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:
- Raises:
BasketCompatibilityError
if basket loaded from the storage is not compatible with the requested basket.
- abstractmethod 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:
BasketStorage
- class shuup.core.basket.storage.DatabaseBasketStorage[source]
Bases:
BaseDatabaseBasketStorage
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: