Beispiel #1
0
    def post(self, request):
        address = request.POST.get('address')
        phone = request.POST.get('phone')
        uid = request.session.get('uid')
        cart = request.session.get('cart')
        products = Product.get_products_by_ids(list(cart.keys()))

        for product in products:
            order = Order(product_id=product.id,
                          user_id=uid,
                          address=address,
                          phone=phone,
                          quantity=cart.get(str(product.id)),
                          price=product.price)
            order.create_order()
        request.session['cart'] = {}
        return redirect('cart')
Beispiel #2
0
    def post(self, request):
        address = request.POST.get('address')
        city = request.POST.get('city')
        state = request.POST.get('state')
        zip_code = request.POST.get('zip_code')
        phone = request.POST.get('phone')
        customer = request.session.get('customer')
        cart = request.session.get('cart')
        products = Product.get_products_by_ids(list(cart.keys()))
        print(address, phone, city, state, zip_code, phone, customer, cart,
              products)

        for product in products:
            print(cart.get(str(product.id)))
            order = Order(customer=Customer(id=customer),
                          product=product,
                          price=product.price,
                          address=address,
                          phone=phone,
                          quantity=cart.get(str(product.id)))
            order.save()
        request.session['cart'] = {}

        return redirect('cart')
Beispiel #3
0
 def get(self, request):
     ids = list(request.session.get('cart').keys())
     products = Product.get_products_by_ids(ids)
     print(products)
     return render(request, 'cart.html', {'products': products})