本文整理汇总了Python中carton.cart.Cart类的典型用法代码示例。如果您正苦于以下问题:Python Cart类的具体用法?Python Cart怎么用?Python Cart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
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: pago
def pago(request):
if request.method == "POST":
cart = Cart(request.session)
if not cart.is_empty:
#
# Guardo el pedido
# ===========================
# creo un pedido con los datos del cliente y el restaurante
restaurante =cart.items[0].product.restaurante
cliente = Cliente.objects.get(user=request.user) #falta el cliente
pedido = Pedido (restaurante=restaurante, cliente=cliente)
pedido.save()
#aado platos al pedido
for item in cart.items:
plato = item.product
Detalle_pedido(plato=plato, pedido=pedido, cantidad=item.quantity).save()
if request.POST.get('pago') == "Paypal":
return paypal_create(request)
elif request.POST.get('pago') == "Efectivo":
cart.clear() #Se vacia el carrito
return HttpResponseRedirect(reverse('pago_exitoso'))
示例3: empty_cart
def empty_cart(request):
cart = Cart(request.session)
cart.clear()
html = new_cart_html(request,1)
cart_contents_qty = cart_contents_empty(request)
payload = update_cart_status_and_prepare_payload(request, html, cart_contents_qty)
return HttpResponse(json.dumps(payload), content_type="application/json")
示例4: charge
def charge(request):
cart = Cart(request.session)
if cart.unique_count > 0:
if request.method == "POST":
form = SalePaymentForm(request.POST or None)
if form.is_valid(): # charges the card
template = get_template('tinbox/order-response-email.html')
context = Context({'cart': cart, 'total': cart.total, 'shipping_cost': form.cleaned_data.get("shipping"), 'name' : form.cleaned_data.get("name") })
content = template.render(context)
cart.clear()
form_email = form.cleaned_data.get("email")
form_name = form.cleaned_data.get("name")
subject = 'Tinbox Solutions - Order Successfully Processed'
from_email = settings.EMAIL_HOST_USER
to_email = [form_email]
msg = EmailMultiAlternatives(subject, "", from_email, to=to_email)
msg.attach_alternative(content, "text/html")
msg.send()
return HttpResponseRedirect('/shopping/thank-you')
else:
t = form.determineShippingFormField(1, cart.total)
return render_to_response("tinbox/charge.html", RequestContext( request, {'form': form, 'turnaround_cost' : t.turnaround_cost, 'turnaround' : t.turnaround} ) )
else:
form = SalePaymentForm()
t = form.determineShippingFormField(1, cart.total)
return render_to_response("tinbox/charge.html", RequestContext( request, {'form': form, 'turnaround_cost' : t.turnaround_cost, 'turnaround' : t.turnaround} ) )
else:
return render(request, 'tinbox/show-cart.html', {"empty": True})
示例5: add
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')
示例6: remove
def remove(request):
cart = Cart(request.session)
event = Event.objects.get(id=request.GET.get('id'))
cart.remove_single(event)
messages.success(request, "Event removed from basket")
return render(request, 'ticket/cart/basket.html')
示例7: add
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()
示例8: remove_single
def remove_single(request):
cart = Cart(request.session)
initial_count = cart.count
product = products[int(request.POST.get('product_id'))]
cart.remove_single(product)
after_rmv_count = cart.count
assert initial_count == after_rmv_count + 1
return HttpResponse()
示例9: remove
def remove(request):
"""
删除一个商品
"""
cart = Cart(request.session)
product = Product.objects.get(id=request.GET['id'])
cart.remove(product)
return HttpResponseRedirect('/cart/')
示例10: show
def show(request):
cart = Cart(request.session)
if request.method == 'POST':
quantitylist = request.POST.getlist('quantity[]')
for idx, item in enumerate(cart.products):
item = Item.objects.get(id=item.id)
cart.set_quantity(item, quantitylist[idx])
return redirect(reverse('checkout:page'))
return render(request, 'shopping/show-cart.html')
示例11: update_cart
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")
示例12: decrementar_quantidade
def decrementar_quantidade(request):
produto_id = request.POST['produto']
quantidade = request.POST['quantidade']
carrinho = Cart(request.session)
produto = Produto.objects.get(pk=produto_id)
carrinho.set_quantity(produto, quantity=quantidade)
template = loader.get_template('loja/carrinho.html')
context = RequestContext(request)
return HttpResponse(template.render(context))
示例13: carrinho_adicionar
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')
示例14: add_single
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);
示例15: show
def show(request):
cart = Cart(request.session)
if request.method == 'POST':
print 'mpike mesa sto post'
isbn = request.POST.get("book_isbn",'')
quant = request.POST.get("book_new_quant",'')
product = Book.objects.get(isbn=isbn)
cart.set_quantity(product, quantity=quant)
return render(request, 'shopping/show-cart.html')