def test_add_cart_quantity_equals_zero(self): user = self._create_user_in_database() cart = Cart(self.request) cart.new(self.request) cart.add(product=user, quantity=1, unit_price=100) self.assertEquals(cart.item_count(), 1) cart.add(product=user, quantity=-1, unit_price=100) self.assertEquals(cart.item_count(), 0)
def test_update_cart(self): user = self._create_user_in_database() cart = Cart(self.request) cart.new(self.request) cart.add(product=user, quantity=3, unit_price=100) cart.update(product=user, quantity=2, unit_price=200) self.assertEquals(cart.summary(), 400) self.assertEquals(cart.count(), 2)
def cart_add(): product_id = request.args.get("product_id", type=int) product = Product.first(id=product_id) if not product: return "" Cart.add(product) return render_update( "cart/add.html", counter=Cart.count(), )
def add2Cart(request, cuisineID): # FIXME: 如果餐厅在“打烊”状态,应该无法添加到购物车,返回错误 cart = request.session.get('cart', None) if cart is None: cart = Cart() res = {'size':cart.add(int(cuisineID))} request.session['cart'] = cart return HttpResponse(json.dumps(res))
def add2Cart(request, cuisineID): # FIXME: 如果餐厅在“打烊”状态,应该无法添加到购物车,返回错误 cart = request.session.get('cart', None) if cart is None: cart = Cart() res = {'size': cart.add(int(cuisineID))} request.session['cart'] = cart return HttpResponse(json.dumps(res))
def add_to_cart(request, decal_id, quantity): decal = Decal.objects.get(id=decal_id) cart = Cart(request) cart.add(decal, decal.price, quantity)