def remove_from_cart(request, product_id): product = Product.objects.get(Productid=product_id) cart = Cart(request) try: cart.remove(product) except ItemDoesNotExist: pass return HttpResponseRedirect('/bookstore/cart/view')
def add_to_cart(request, product_id): product = Product.objects.get(Productid=product_id) cart = Cart(request) try: quantity = int(request.POST['quantity']) or 1 cart.add(product, product.price, quantity) except ItemAlreadyExists: pass return HttpResponseRedirect('/bookstore/cart/view')
def clear_cart(request): cart = Cart(request) try: cart.clear() except Exception, exc: pass