Exemple #1
0
def make_reservation(request):
    cart = Cart(request)
    user = User.objects.get(username=request.user)
    customer = Customer.objects.get(user=user)

    #예약하기 위해서는 수량을 체크해야됨
    #주문할려는 상품의 갯수가 현재 잔고보다 많은 경우 주문이 안되고 에러메세지를 출력해야됨
    for inventory in cart:
        if inventory['inventory'].rentalproduct.stock < inventory['quantity']:
            return HttpResponse('[Error] 예약수량이 기존상품보다 많습니다')

    for inventory in cart:
        stock = inventory['inventory'].rentalproduct.stock - inventory[
            'quantity']
        inventory['inventory'].rentalproduct.stock = stock
        inventory['inventory'].rentalproduct.save()

        Reservation.objects.create(customer=customer,
                                   inventory=inventory['inventory'],
                                   in_date=timezone.now(),
                                   out_date=timezone.now(),
                                   status=0,
                                   stock=inventory['quantity'])

        #주문이 완료되면 장바구니에서 삭제한다.
        cart.remove(inventory['inventory'])

    return HttpResponseRedirect(reverse('account:mypage'))
Exemple #2
0
def api_checkout(request):
    data = json.loads(request.body)
    cart = Cart(request)
    jsonresponse = {'success': True}

    first_name = data['first_name']
    last_name = data['last_name']
    email = data['email']
    address = data['address']
    zipcode = data['zipcode']
    city = data['city']

    orderId = checkout(request, first_name, last_name, email, address, zipcode, city)

    paid = True

    if paid == True:
        order = Order.objects.get(pk=orderId)
        order.paid = True
        order.paid_amount = cart.get_total_cost()

        order.save()
        cart.clear()

    return JsonResponse(jsonresponse)
Exemple #3
0
def order_create(request):

    cart = Cart(request)

    if request.method == 'POST':

        form = OrderCreateForm(request.POST)

        if form.is_valid():

            order = form.save()

            for item in cart:
                OrderItem.objects.create(
                	order = order, product = item['product'], price = item['price'], quantity = item['quantity'])

            # очистка корзины
            cart.clear()

            return render(request, 'Order/Created.html', {'order': order})

    else:
        form = OrderCreateForm

    data = {'cart': cart, 'form': form}

    return render(request, 'Order/Create.html', context =  data)
Exemple #4
0
def api_remove_from_cart(request):
    data = json.loads(request.body)
    jsonresponse = {'success': True}

    product_id = str(data['product_id'])

    cart = Cart(request)

    cart.remove(product_id)

    return JsonResponse(jsonresponse)
Exemple #5
0
def checkout(request, first_name, last_name, email, address, zipcode, city):
    order = Order(first_name=first_name,
                  last_name=last_name,
                  email=email,
                  address=address,
                  zipcode=zipcode,
                  city=city)
    if request.user.is_authenticated:
        order.user = request.user
    order.save()

    cart = Cart(request)

    for item in cart:
        if item['sale_price']:
            OrderItems.objects.create(order=order,
                                      product=item['product'],
                                      sale_price=item['sale_price'],
                                      quantity=item['quantity'])
        else:
            OrderItems.objects.create(order=order,
                                      product=item['product'],
                                      market_price=item['market_price'],
                                      quantity=item['quantity'])
    return order.id
Exemple #6
0
def order_create(request):
    template = '.html'
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save()
            for item in cart:
                OrderItem.objects.create(order=order,
                                         item=item['item'],
                                         unit_price=item['unit_price'],
                                         quantity=item['quantity'])
            cart.clear()
            return render(request, template, {'order': order})
    else:
        form = OrderCreateForm()

    return render(request, template, {'cart': cart, 'form': form})
Exemple #7
0
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save()
            for item in cart:
                OrderItem.objects.create(order=order,
                                         product=item['product'],
                                         price=item['price'],
                                         quantity=item['quantity'])
            cart.clear()
            order_created.delay(order.id)
            request.session['order_id'] = order.id
            return redirect(reverse('payment:process'))
    else:
        form = OrderCreateForm()
    return render(request, 'orders/order/create.html', {'form': form})
Exemple #8
0
def checkout(request, first_name, last_name, email, address, zipcode, place):
    order = Order(first_name=first_name, last_name=last_name, email=email, address=address, zipcode=zipcode, place=place)
    
    order.save()
    
    cart = Cart(request)
    
    for item in cart:
        OrderItems.objects.create(order=order, product=item['product'], price = item['price'], quantity=item['quantity'])
    
    return order.id
Exemple #9
0
def list_storeRentalProduct(request):
    form = SigunguForm(request.GET)
    cart_product_form = AddCartForm()
    cart = Cart(request)

    if form.is_valid():
        sido_name = form.cleaned_data['sido']
        sigungu_name = form.cleaned_data['sigungu']

        #예외처리
        #도중에 아무것도 없을 경우 None을 리턴
        try:
            sigungu = Sigungu.objects.filter(sido=sido_name, name=sigungu_name)
            address = Address.objects.filter(Sigungu=sigungu)
            store = Store.objects.filter(address__in=address)
            #인벤토리 검색
            inventory = Rentalinventory.objects.filter(store__in=store)
            # paginator = Paginator(inventory, 1)
            # page = request.GET.get('page')
            #
            # print page
            # try:
            #     inventory = paginator.page(page)
            # except PageNotAnInteger:
            #     inventory = paginator.page(1)
            # except EmptyPage:
            #     inventory = paginator.page(paginator.num_pages)

            for item in inventory:
                #상점의 상품 수량
                quantity = RentalProduct.objects.get(rentalproduct=item).stock
                cart_product_form = AddCartForm(initial={'quantity': quantity})

        except ObjectDoesNotExist:
            inventory = None

        return render(
            request, 'rental/list.html', {
                'inventory': inventory,
                'cart_product_form': cart_product_form,
                'address': address[0].get_name()
            })
Exemple #10
0
def api_add_to_cart(request):
    data = json.loads(request.body)
    jsonresponse = {'success': True}

    product_id = data['product_id']
    update = data['update']
    quantity = data['quantity']

    cart = Cart(request)

    product = get_object_or_404(Product, pk=product_id)

    if not update:
        cart.add(product=product, updated_quantity=False, quantity=1)
    else:
        cart.add(product=product, updated_quantity=True, quantity=quantity)

    return JsonResponse(jsonresponse)