Exemplo n.º 1
0
def cart_quantity(request):
    """
    Change given item's quantity in shopping cart.
    """
    if request.method == 'POST':
        try:
            product_slug = request.POST.get('slug', False)
            quantity = int(request.POST.get('quantity', 1))
            if quantity > 0:
                product = Product.published.get(slug=product_slug)
                cart = Cart(request)
                cart.change_quantity(product, quantity)
        except:
            pass
    return conditional_redirect(request, reverse('show_cart'))
Exemplo n.º 2
0
def cart_quantity(request):
    """
    Change given item's quantity in shopping cart.
    """
    if request.method == 'POST':
        try:
            product_slug = request.POST.get('slug', False)
            quantity = int(request.POST.get('quantity', 1))
            if quantity > 0:
                product = Product.published.get(slug=product_slug)
                cart = Cart(request)
                cart.change_quantity(product, quantity)
        except:
            pass
    return conditional_redirect(request, reverse('show_cart'))
Exemplo n.º 3
0
def change_quantity(request):
    cart = Cart(request)
    product_id = int(request.GET.get('product_id'))
    product = Product.objects.get(id=product_id)
    quantity = int(request.GET.get('quantity'))
    cart.change_quantity(product=product, quantity=quantity)

    cost = int(cart.cart[str(product.id)]['cost'])

    context = {
        'cart_len': len(cart),
        'total_price': cart.get_total_price(),
        'cost': cost,
    }

    return JsonResponse(context)