Views

shopkit.core.views

class shopkit.core.views.CartAddBase(**kwargs)

Bases: django.views.generic.base.TemplateResponseMixin, shopkit.core.views.CartAddFormMixin, django.views.generic.edit.BaseFormView

View for processing POST requests adding items to the shopping cart. Process flow is as follows:

  1. User is on a product detail page.
  2. User clicks ‘Add to cart’ and (optionally) selects a quantity. This initiates a POST request to the current view.
  3. The current view fetches the cart, checks for the current product in there.
    1. If it does, it adds the given quantity to CartItem which has been found.
    2. If it does not, a new CartItem should be created and added to the users Cart.
  4. Redirect to the cart view.

Todo

Graceously handle errors instead of form_invalid noting that render_to_response was not found.

form_valid(form)

Form data was valid: add a CartItem to the Cart or increase the number.

..todo::
Refactor this!
get_form_class()

Simply wrap the get_cart_form_class from CartMixin.

get_success_url()

The URL to return to after the form was processed succesfully. This function should be overridden.

Todo

Decide whether or not to make the default success url a configuration value or not.

class shopkit.core.views.CartAddFormMixin

Bases: object

Mixin providing a basic form class for adding items to the shopping cart. It will be added to the context as cartaddform.

get_cart_form_class()

Simply return the form for adding Items to a Cart.

get_context_data(**kwargs)

Add a cart add form under the name cartaddform to the context, if and only if an object is available and is a product.

If this is not the case, we should fail silently (perhaps) logging a debug message.

Todo

Make an API hook allowing us to check whether a product available for adding it to a cart.

class shopkit.core.views.InShopViewMixin

Bases: object

Mixin using the in_shop manager rather than the default objects, so that it only uses objects which are actually enabled in the frontend of the shop.

get_queryset()

Return in_shop.all() for the model.