本文整理汇总了Python中carton.cart.Cart.add方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.add方法的具体用法?Python Cart.add怎么用?Python Cart.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类carton.cart.Cart
的用法示例。
在下文中一共展示了Cart.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add(request):
cart = Cart(request.session)
selitem_id = request.GET.get('id')
selitem_qty = request.GET.get('quantity')
selitem = Item.objects.get(id=selitem_id)
cart.add(selitem, selitem_qty, price=selitem.price)
return redirect(reverse('store') + "#No{}Card".format(selitem.product.id))
示例2: add
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add(request):
cart = Cart(request.session)
event = Event.objects.get(id=request.GET.get('id'))
cart.add(event, price=event.price)
messages.success(request, "Event added to basket")
return render(request, 'ticket/cart/basket.html')
示例3: add
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add(request):
cart = Cart(request.session)
product = Product.objects.get(pk=request.POST.get('product_id'))
quantity = request.POST.get('quantity', 1)
discount = request.POST.get('discount', 0)
price = product.price - float(discount)
cart.add(product, price, quantity)
return HttpResponse()
示例4: update_cart
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def update_cart(request):
cart = Cart(request.session)
for product in cart.products:
print product.name
qty = int(request.POST.get("product_" + str(product.id)))
if qty > 0 and qty < 100:
cart.remove(product)
cart.add(product, price=product.price, quantity=qty)
return redirect("pos:cart")
示例5: carrinho_adicionar
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def carrinho_adicionar(request):
if request.method == 'POST':
carrinho = Cart(request.session)
produto = Produto.objects.get(pk=request.POST.get('id'))
carrinho.add(produto, price=produto.preco, quantity=request.POST.get('quantidade'))
data = json.dumps({'itens': str(len(carrinho.items)), 'total': str(carrinho.total)})
return HttpResponse(data, content_type='application/json')
else:
return HttpResponse('404')
示例6: add_single
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add_single(request):
cart = Cart(request.session)
plato = Plato.objects.get(id=request.GET.get('product_id'))
if cart.products:
if plato.restaurante.id != cart.products[0].restaurante.id:
cart.clear()
cart.add(plato, price=plato.precio)
return platilla_cesta(request);
示例7: add_product
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add_product(request, product_id):
cart = Cart(request.session)
product = Product.objects.get(pk=product_id)
cart.add(product, price=product.price_ukr())
result = {'products_in_cart': len(cart.items),
'cart_total_sum': int(cart.total)}
json_response = json.dumps(result)
return HttpResponse(json_response, content_type="application/json")
示例8: add
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add(request):
cart = Cart(request.session)
product = Product.objects.get(id=request.POST.get('id'))
cart.add(product, price=product.price, quantity=request.POST.get('qty'))
recent_product = dict(name=product.productName, image=product.image.url, price=product.price, total=cart.total,
items=cart.count)
return HttpResponse(
json.dumps(recent_product, use_decimal=True),
content_type="application/json"
)
示例9: add
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add(request, product_id):
cart = Cart(request.session)
if Item2.objects.filter(product_id=product_id):
product = Item2.objects.get(product_id=product_id)
elif Item3.objects.filter(product_id=product_id):
product = Item3.objects.get(product_id=product_id)
else:
product = Item4.objects.get(product_id=product_id)
cart.add(product, price=product.price)
return HttpResponseRedirect('/tohfa/show')
示例10: add
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add(request):
"""
向购物车内增加商品
"""
print request.GET
print request.POST
cart = Cart(request.session)
product = Product.objects.get(id=request.GET['id'])
quantity = request.POST['quantity']
cart.add(product, price=product.price, quantity=quantity)
return HttpResponseRedirect('/cart/')
示例11: post
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def post(self, request):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
cart = Cart(request.session)
product = get_object_or_404(Product, id=serializer.data['product_id'])
cart.add(product, price=product.price)
response_data = {
'detail': 'Product was added to cart.'
}
response_status = status.HTTP_201_CREATED
return Response(response_data, status=response_status)
示例12: add_to_cart
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add_to_cart(request, slug):
if request.is_ajax():
cart = Cart(request.session)
product = get_object_or_404(Product, slug=slug)
cart.add(product, price=product.price)
return render_to_response('mcat_order/cart.html',
{'product' : product},
context_instance=RequestContext(request),
content_type="application/xhtml+xml"
)
else:
if settings.DEBUG:
print("Not ajax request")
raise Http404
示例13: add
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add(request):
cart = Cart(request.session)
product = Product.objects.get(id=request.GET.get('id'))
try:
product_stock = ProductStock.objects.get(product=product)
except ObjectDoesNotExist:
product_stock = None
####ir buscar preco correcto
cart.add(product, price=2)
html = new_cart_html(request,0)
cart_contents_qty = cart_contents_payload(request)
payload = update_cart_status_and_prepare_payload(request, html, cart_contents_qty, True)
return HttpResponse(json.dumps(payload), content_type="application/json")
示例14: inventory
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def inventory(request):
if request.method == 'GET':
i = Item.objects.all()
items = []
for item in i:
print item.name, item.description
items.append(item)
return HttpResponse(render_template(request, 'SecuCart/inventory.html', { 'items': items }))
elif request.method == 'POST':
print 'item_number:', request.POST.get('item_number')
for i in request.POST:
if i != 'item_number':
item = Item.objects.get(name=i)
print 'item:', i, item.name, item.quantity, item.price
item.quantity = item.quantity - int(request.POST.get('item_number'))
item.save()
cart = Cart(request.session)
cart.add(item, price=1.0, quantity=request.POST.get('item_number'))
return HttpResponse(render_template(request, 'SecuCart/shopping_cart.html', {}))
示例15: add
# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import add [as 别名]
def add(request, product_id):
product = Product.objects.get(id=product_id)
if request.method == "POST":
cart = Cart(request.session)
form = CartItemForm(request.POST or None)
if form.is_valid():
item = form.save()
item.final_cost = item.calculateFinalCost()
c = item.final_cost
print "Final "+str(item.final_cost)
if item.rounded:
if product.rounded_cost is None:
item.final_cost = c + product.category.rounded_cost
else:
item.final_cost = c + product.rounded_cost
cart.add(item, price=item.final_cost)
return HttpResponseRedirect("/shopping/cart/")
else:
print form.errors
else:
form = CartItemForm(initial={'id':product_id})
token = {}
token['form'] = form
token['quantities'] = product.quantities.all
token['colors'] = product.colors.all
token['finishes'] = product.finishes.all
token['product'] = product
if product.category.rounded and product.rounded:
token['can_be_round'] = True
token['rounded_cost'] = product.rounded_cost
if product.rounded_cost is None:
token['rounded_cost'] = product.category.rounded_cost
else:
token['can_be_round'] = False
token.update(csrf(request))
return render_to_response('tinbox/order.html', token)