Example #1
0
 def get(self, request):
     if not (request.session.get('cart')):
         return redirect('cartEmpty')
     else:
         ids = list(request.session.get('cart').keys())
         products = Product.get_all_products_by_Id(ids)
         print(products)
         return render(request, 'cart.html', {'products': products})
Example #2
0
    def post(self, request):
        address = request.POST.get('address')
        phone = request.POST.get('phone')
        customer = request.session.get('customer_id')
        print(f"session cstme{customer}")
        cart = request.session.get('cart')
        products = Product.get_all_products_by_Id(list(cart.keys()))
        for product in products:
            order = Orders(
                product=product,
                customer=Customer(id=customer),
                quantity=cart.get(str(product.id)),
                price=product.price,
                address=address,
                phone=phone,
            )

        order.save()
        request.session['cart'] = {}
        return redirect('cart')