def post(self, *args, **kwargs): cart = Cart(self.request) item = get_object_or_404(Item, id=kwargs['pk']) form = CartAddForm(self.request.POST) if form.is_valid(): cd = form.cleaned_data cart.add(item=item, quantity=cd['quantity'], update_quantity=cd['update']) return redirect("ordersummary")
def decrease_quantity(request, pk): cart = Cart(request) item = get_object_or_404(Item, id=pk) item_id = str(item.id) print(cart.__dict__) if cart.cart[item_id]['quantity'] > 1: cart.add(item=item, quantity=-1) else: cart.remove(item) return redirect("ordersummary")
def get(request): product_id = int(request.GET.get('product_id')) price = int(request.GET.get('price').replace(' ', '')) quantity = int(request.GET.get('quantity')) max_q = int(request.GET.get('max_q')) bar_type = request.GET.get('bar_type') product = get_object_or_404(Product, id=product_id) cart = Cart(request) cart.add(product, price, quantity, max_q, bar_type) context = { 'cart_len': len(cart), } return JsonResponse(context)
def get(self, request): cart = Cart(request) product_id = request.GET.get('product') color_id = request.GET.get('color') or None size_id = request.GET.get('size') or None cup_id = request.GET.get('cup') or None offer = get_object_or_404(Offer.objects.select_related( 'color', 'size', 'cup'), product__id=product_id, is_active=True, color=color_id, size=size_id, cup=cup_id) cart.add(offer.id) return redirect(request.META.get('HTTP_REFERER'))
def get(self, *args, **kwargs): cart = Cart(self.request) item = get_object_or_404(Item, id=kwargs['pk']) cart.add(item=item) return redirect("ordersummary")