Esempio n. 1
0
def attCart(request):
    form = QtyForm(request.POST)

    if form.is_valid():
        product_id = form.cleaned_data['product_id']
        qty = form.cleaned_data['qty']

        cart = Cart(request)

        if qty == 0:
            cart.remove(product_id)
            totalPrice = 0.0

        else:
            cart.att(product_id, qty)
            totalPrice = cart.getTotalPrice(product_id)


#        qtyTotal = cart.getCartQty()

#        cartPrice = cart.getCartPrice

#        print('***** id do produto = ' + product_id +
#              '  quantidade = ' + str(qty) +
#              '  preço total do produto = ' + str(totalPrice))
#        print('***** qtd no carrinho = ' + str(qtyTotal) +
#              '  valor do carrinho = ' + str(cartPrice))

        return render(request, 'answerAjax.html', {
            'totalPrice': totalPrice,
        })

    else:
        raise ValueError(
            "Ocorreu um erro inesperado ao adicionar um produto no carrinho.")
Esempio n. 2
0
def listProduct(request, categorySlug=None):

    category = None

    products = Product.objects.filter(available=True).order_by('name')

    if categorySlug:
        category = get_object_or_404(Category, slug=categorySlug)
        products = Product.objects.filter(available=True,
                                          category=category).order_by('name')

    cart = Cart(request)

    formList = []

    for product in products:
        qty = cart.getTotalQty(product.id)
        formList.append(QtyForm(initial={
            'qty': qty,
            'product_id': product.id
        }))

    return render(request, 'cart/shoppingCart.html', {
        'list': zip(products, formList),
        'category': category
    })
Esempio n. 3
0
def showSpecificProduct(request, id, productSlug):
    product = get_object_or_404(Product, pk=id)
    request.session['product_id_del'] = id

    cart = Cart(request)
    qty = cart.getTotalQty(product.id)
    form = QtyForm(initial={'qty': qty, 'product_id': product.id})

    return render(request, 'products/specificProduct/specificProduct.html', {
        'product': product,
        'form': form
    })
Esempio n. 4
0
def index(request):
    bestSeller = Product.objects.filter(bestSeller=True).order_by('name')

    cart = Cart(request)

    formList = []

    for product in bestSeller:
        qty = cart.getTotalQty(product.id)
        formList.append(QtyForm(initial={
            'qty': qty,
            'product_id': product.id
        }))

    return render(request, 'index.html', {'list': zip(bestSeller, formList)})
Esempio n. 5
0
def nodachis(request):
    category = get_object_or_404(Category, name='Nodachi')
    print(category)
    nodachisList = Product.objects.filter(category=category).order_by('name')
    print(nodachisList)

    cart = Cart(request)

    formList = []

    for product in nodachisList:
        qty = cart.getTotalQty(product.id)
        formList.append(QtyForm(initial={
            'qty': qty,
            'product_id': product.id
        }))

    return render(request, 'products/productsPages.html', {
        "list": zip(nodachisList, formList),
        'category': category
    })
Esempio n. 6
0
def checkOut(request):
    cart = Cart(request)

    productsCart = cart.getProduct()

    cartPrice = cart.getCartPrice()

    formList = []

    for product in productsCart:
        print(product)
        qty = cart.getTotalQty(product['id'])
        formList.append(
            QtyForm(initial={
                'qty': qty,
                'product_id': product['id']
            }))

    return render(request, 'payment/checkout.html', {
        'products': zip(productsCart, formList),
        'cartPrice': cartPrice
    })