示例#1
0
文件: tests.py 项目: n3n/django-cart
 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)
示例#2
0
文件: tests.py 项目: n3n/django-cart
 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)
示例#3
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)
示例#4
0
文件: app.py 项目: jpsca/monolith
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(),
    )
示例#5
0
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))
示例#6
0
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))
示例#7
0
def add_to_cart(request, decal_id, quantity):
    decal = Decal.objects.get(id=decal_id)
    cart = Cart(request)
    cart.add(decal, decal.price, quantity)