コード例 #1
0
ファイル: forms.py プロジェクト: szkolasa/Django-WebStore
    def save(self, cart):
        first_name = self.cleaned_data.get('first_name')
        last_name = self.cleaned_data.get('last_name')
        street = self.cleaned_data.get('street')
        house_number = self.cleaned_data.get('house_number')
        flat_number = self.cleaned_data.get('flat_number')
        zip_code = self.cleaned_data.get('zip_code')
        phone_number = self.cleaned_data.get('phone_number')
        city = self.cleaned_data.get('city')

        order = Order()
        order.first_name = first_name
        order.last_name = last_name
        order.street = street
        order.house_number = house_number
        order.flat_number = flat_number
        order.zip_code = zip_code
        order.phone_number = phone_number
        order.city = city
        order.user = self.user
        order.save()

        for item in cart:
            order_item = OrderItem()
            order_item.order = order
            order_item.product = item['product']
            order_item.price = item['price']
            order_item.quantity = item['quantity']
            order_item.save()
コード例 #2
0
def completeOrder(request):
    request.session.set_expiry(0)
    cart = request.session['cart']
    order = Order()
    order.first_name = request.POST['first_name']
    order.last_name = request.POST['last_name']
    order.address = request.POST['address']
    order.city = request.POST['city']
    order.payment_method = request.POST['payment']
    order.payment_data = request.POST['payment_data']
    order.save()
    order.items = genItemsList(cart)
    request.session['cart'] = []
    return render(request, "complete_order.html", None)
コード例 #3
0
ファイル: views.py プロジェクト: mukeshadhikari118/django
def completeOrder(request):
    request.session.set_expiry(0)
    cart = request.session['cart']
    ctx = {'cart': cart}
    order = Order()
    order.first_name = request.POST['first_name']
    order.last_name = request.POST['last_name']
    order.address = request.POST['address']
    order.city = request.POST['city']
    order.payment_method = request.POST['payment']
    order.payment_data = request.POST['payment_data']
    order.items = genItemsList(cart)
    order.fulfilled = False
    order.save()
    request.session['cart'] = []
    return render(request, 'store/complete_order.html', ctx)
コード例 #4
0
ファイル: views.py プロジェクト: vigneshwarane89/simpleStore
def completeOrder(request):
    cart = request.session['cart']
    request.session.set_expiry(0)
    ctx = {
        'cart': cart,
        'cart_size': len(cart),
        'cart_items': cartItems(cart),
        'total_price': priceCart(cart)
    }
    order = Order()
    order.items = genItemsList(cart)
    order.first_name = request.POST['first_name']
    order.last_name = request.POST['last_name']
    order.address = request.POST['address']
    order.city = request.POST['city']
    order.payment_data = request.POST['payment_data']
    order.fulfill = False
    order.payment_method = request.POST['payment']
    order.save()
    request.session['cart'] = []
    return render(request, "complete_order.html", ctx)
コード例 #5
0
ファイル: views.py プロジェクト: reefvov/E-com-Project
def checkOutView(request, coupon_id):
    total = 0
    counter = 0
    cart_items = None
    discount_price = None
    new_total = None
    add_coupon = False
    coupon = None

    try:
        cart = Cart.objects.get(cart_id=_cart_id(request))  #ดึงตะกร้า
        cart_items = CartItem.objects.filter(
            cart=cart, active=True)  #ดึงข้อมูลสินค้าในตะกร้า
        for item in cart_items:
            total += (item.product.price * item.quantity)
            counter += (item.quantity)
    except Exception as e:
        pass

    form = CheckOutForm(request.POST)

    if request.method == 'POST':

        if 'confirm' in request.POST:
            print('Uppppppppppppppppppppppppppppppppp')
            if coupon_id == 0:
                new_total = total

            else:
                coupon = Coupon.objects.get(id=coupon_id)
                new_total = total - coupon.discount
                add_coupon = True

        else:
            print('Downnnnnnnnnnnnnnnnnnnnnnnnnnnnnn')
            if coupon_id == 0:
                new_total = total

            else:
                coupon = Coupon.objects.get(id=coupon_id)
                new_total = total - coupon.discount
                add_coupon = True
            form = CheckOutForm(request.POST)
            if form.is_valid():
                now = timezone.now()
                data = Order()

                data.first_name = form.cleaned_data['first_name']
                data.last_name = form.cleaned_data['last_name']
                data.phone = form.cleaned_data['phone']
                data.user_id = request.user.username
                data.address = form.cleaned_data.get('address')
                data.city = form.cleaned_data.get('city')
                data.district = form.cleaned_data.get('district')
                data.subdistrict = form.cleaned_data.get('subdistrict')
                data.postcode = form.cleaned_data.get('postcode')
                data.total = new_total
                data.status = 'รอชำระเงิน'
                if coupon_id != 0:
                    data.code = coupon.code
                data.save()

                for item in cart_items:
                    order_item = OrderItem.objects.create(
                        product=item.product.name,
                        quantity=item.quantity,
                        price=item.product.price,
                        order=data)
                    order_item.save()
                    #ลดจำนวนstock
                    product = Product.objects.get(id=item.product.id)
                    product.stock = int(item.product.stock -
                                        order_item.quantity)
                    product.save()
                    item.delete()
                order = Order.objects.get(id=data.id)
                return redirect(order.get_url())

    else:
        form = CheckOutForm()
        new_total = total

    return render(
        request, "checkout.html",
        dict(cart_items=cart_items,
             total=total,
             counter=counter,
             form=form,
             new_total=new_total,
             coupon=coupon,
             add_coupon=add_coupon,
             coupon_id=coupon_id))