예제 #1
0
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save(commit=False)
            if cart.coupon:
                order.coupon = cart.coupon
                order.discount = cart.coupon.discount
            order.save()
            for item in cart:
                OrderItem.objects.create(order=order,
                                         product=item['product'],
                                         price=item['price'],
                                         quantity=item['quantity'])
            # clear the cart
            cart.clear()
            # launch asynchronous task
            order_created.delay(order.id)
            # set the order in the session
            request.session['order_id'] = order.id
            # redirect to the payment
            return redirect(reverse('payment:process'))
    else:
        form = OrderCreateForm()
    return render(request, 'orders/order/create.html', {'cart': cart,
                                                        'form': form})
예제 #2
0
class TestShow(TestCase):
    def setUp(self):
        rf = RequestFactory()
        request = rf.get(reverse('cart-show'))
        add_session_to_request(request)
        self.cart = Cart(request)
        product = ProductFactory()
        self.cart.add(product, product.price, 1)
        self.client = Client()
        engine = import_module(settings.SESSION_ENGINE)
        store = engine.SessionStore()
        store.save()
        self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key


    def test_get(self):
        # store cart id in session
        session = self.client.session
        session['CART-ID'] = self.cart.cart.pk
        session.save()
        resp = self.client.get(reverse('cart-show'))
        self.assertEqual(resp.status_code, 200)
        self.assertTemplateUsed(resp, 'check/cart.html')

    def test_post(self):
        data = {}
        for item in self.cart:
            data['%s-quantity' % item.product.pk] = 2
        # store cart id in session
        session = self.client.session
        session['CART-ID'] = self.cart.cart.pk
        session.save()
        resp = self.client.post(reverse('cart-show'), data=data)
        self.assertRedirects(resp, reverse('cart-check-in'), status_code=302, target_status_code=200)
예제 #3
0
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save(commit=False)
            if cart.coupon:
                order.coupon = cart.coupon
                order.discount = cart.coupon.discount
            order.save()
            for item in cart:
                OrderItem.objects.create(order=order,
                                        product=item['product'],
                                        price=item['price'],
                                        quantity=item['quantity'])
            # Usunięcie zawartości koszyka na zakupy.
            cart.clear()
            # Uruchomienie zadania asynchronicznego.
            order_created.delay(order.id) # Umieszczenie zamówienia w sesji.
            request.session['order_id'] = order.id # Przekierowanie do płatności.
            return redirect(reverse('payment:process'))

    else:
        form = OrderCreateForm()
    return render(request,
                  'orders/order/create.html',
                  {'cart': cart, 'form': form})
예제 #4
0
파일: views.py 프로젝트: REBradley/Blatts
def add_sandwich(request, base):
    cart = Cart(request.session)
    
    sand_base = get_object_or_404(Base, pk=base)
    form = SandwichForm(request.POST, initial={'base': base})
    form2 = QuantityForm(request.POST)
    
    if form.is_valid() and form2.is_valid():
        bread = form.cleaned_data['bread']
        toppings = form.cleaned_data['toppings']
        condiments = form.cleaned_data['condiments']
        cheeses = form.cleaned_data['cheeses']
        side= form.cleaned_data['side']
        
        quantity = form2.cleaned_data['quantity']
        
        sandwich = Sandwich()
        sandwich.base= sand_base
        sandwich.bread= bread
        sandwich.save()
        
        sandwich.side= side
        sandwich.toppings= toppings
        sandwich.condiments= condiments
        sandwich.cheeses= cheeses
        sandwich.save()
        
        product = sandwich 
        cart.add(product, price=sandwich.price, quantity=quantity)
        return HttpResponseRedirect(reverse('cart:show_cart'))
    
    return render(request, 'sandwich_builder/sandwich_constructor.html',
                  {'base': sand_base, 'form':form})
예제 #5
0
파일: views.py 프로젝트: mazulo/myshop
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']
                )
            # clear the cart
            cart.clear()
            # launch asynchronous task
            order_created.delay(order.id)
            return render(
                request,
                'orders/order/created.html',
                {'order': order}
            )
    else:
        form = OrderCreateForm()
    return render(
        request,
        'orders/order/create.html',
        {
            'cart': cart,
            'form': form
        }
    )
예제 #6
0
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save(commit=False)
            if cart.coupon:
                order.coupon = cart.coupon
                order.discount = cart.coupon.discount
                order.save()
            try:
                for item in cart:
                    OrderItem.objects.create(order=order,
                                             product=item['product'],
                                             price=item['price'],
                                             qty=item['qty'])
            except Exception as exp:
                return HttpResponseBadRequest(str(exp))

            # clear the cart
            cart.clear()
            # send email asynchronously
            order_created.delay(order.id)
            # set the order in the session
            request.session['order_id'] = order.id
            # redirect for payment
            return redirect(reverse('payment:process'))
    else:
        form = OrderCreateForm()
    return render(request,
                  'orders/order/create.html',
                  {'form': form, 'cart': cart})
예제 #7
0
 def create_order(self, client):
     cart = Cart(self.client)
     cart.create_cart()
     cart = cart.cart
     order = Order(client=client, cart=cart)
     order.save()
     return order
예제 #8
0
def order_create(request):
    # получаем текущую корзину из request.session
    cart = Cart(request)

    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():

            # создание экземпляра Order
            order = form.save(commit=False)
            # добавление инфорации о купоне
            if cart.coupon:
                order.coupon = cart.coupon
                order.discount = cart.coupon.discount
            order.save()

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

            # вызов celery task
            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', {'cart': cart,
                                                        'form': form})
예제 #9
0
파일: views.py 프로젝트: GonzaloAvilez/kaay
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'])
			
			# clear the cart
			cart.clear()
			#levantar una excepcion si cart esta vacío para informar que 
			#no hay productos seleccionados o ya fue generada una orden
			# launch asynchronous task
			#order_created.delay(order.id)
			order_created(order.id)
			request.session['order_id'] = order.id 
			return redirect(reverse('payment:process'))

	else:
		form = OrderCreateForm()
	return render(request,
				'orders/order/create.html',
				{'cart': cart, 'form': form})
예제 #10
0
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save(commit=False)
            if cart.coupon:
                order.coupon = cart.coupon
                order.discount = cart.coupon.discount
            order.save()
            for item in cart:
                OrderItem.objects.create(order=order,
                                         product=item['product'],
                                         price=item['price'],
                                         quantity=item['quantity'])
            # clear the cart
            cart.clear()
            # launch asynchronous task
            order_created.delay(order.id)
            # set the order in the session
            request.session['order_id'] = order.id
            # Increment the score of each product id contained in the order.
            # The score represents the times another product has been bought
            # together with the given product.
            Recommender().products_bought(item['product'] for item in cart)
            # redirect ot the payment
            return redirect(reverse('payment:process'))
    else:
        form = OrderCreateForm()
    return render(request,
                  'orders/order/create.html',
                  {'cart': cart, 'form': form})
예제 #11
0
파일: order.py 프로젝트: acidjunk/funder
 def add_project_to_cart(self, request, *args, **kwargs):
     project = ProjectPage.objects.get(id=request.POST.get('project_id'))
     cart = Cart(request)
     cart.add(project, request.POST.get('amount'), 1)
     request.session['funder_name']=request.POST.get('name')
     request.session['funder_organisation']=request.POST.get('organisation')
     return redirect('/order/checkout')
예제 #12
0
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrdenCreateForm(request.POST)
        if form.is_valid():
            order = form.save(commit=False)
            if cart.coupon:
                order.coupon = cart.coupon
                order.discount = cart.coupon.discount
                order.save()
            for item in cart:
                OrderItem.objects.create(
                                        orden=order,
                                        product=item['product'],
                                        precio=item['price'],
                                        cantidad=item['quantity'],
                )
            #limpiamos l carro
            cart.clear()
            #lanzamos el proceso asincrono
            order_created.delay(order.id)
            #set the order in the session
            request.session['order_id'] = order.id
            #redirect to the payment
            return redirect(reverse('payment:process'))

    else:
        form = OrdenCreateForm()
    return render(request, 'orders/order/created.html', {'cart':cart, 'form':form})
예제 #13
0
파일: views.py 프로젝트: janusnic/dj-21v
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            #order = form.save()
            order = form.save(commit=False)
            if cart.coupon:
                order.coupon = cart.coupon
                order.discount = cart.coupon.discount
            order.save()
            for item in cart:
                OrderItem.objects.create(order=order,
                                         product=item['product'],
                                         price=item['price'],
                                         quantity=item['quantity'])
            # clear the cart
            cart.clear()
            # launch task
            order_created(order.id)
            return render(request, 'shop/orders/created.html', {'order': order})
    else:
        form = OrderCreateForm()
    return render(request, 'shop/orders/create.html', {'cart': cart,
                                                        'form': form})
예제 #14
0
def add_to_cart(request):
    product_id = request.POST.get('product_id')[0]   
    product = Product.objects.get(pk=product_id)
    cart = Cart(request)
    quantity = 1
    cart.add(product, product.price, quantity)
    return HttpResponse(cart.summary())
예제 #15
0
def order_create(request):
    '''get the product in cart of session and generate an order'''
    cart=Cart(request)  #get the cart information as a dictionary
    if request.method=='POST':
        form=OrderCreateForm(request.POST) #get the user input information
        if form.is_valid():
            order=form.save()  #save the input information into database 
            for item in cart:  #save the products in cart into database
                OrderItem.objects.create(order=order,product=item['product'],price=item['price'],quantity=item['quantity'])
            # Clear the cart information in session
            cart.clear()
            # Launch asynchronous task
            # Call delay() method of hte task to execute it asynchronously. The task will be added to the queue and will be executed by a worker as soon as possible.
            order_created.delay(order.id) 
            
            #set the order in the session    
            request.session['order_id']=order.id   
            #return render(request, 'orders/order/created.html',{'order':order})
            
            #redirect to the payment
            return redirect(reverse('payment:process'))
            
    else:
        form=OrderCreateForm()
    return render(request, 'orders/order/create.html',{'cart':cart,'form':form})
예제 #16
0
파일: views.py 프로젝트: HectorBlisS/namuh
	def post(self,request):
		cart=Cart(request)
		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'])
			# Borrar el carrito
			cart.clear()
			# Lanzamos la tarea asincrona
			# order_created.delay(order.id)
			# Mandamos email sin tarea asincrona
			# seteamos la orden en la sesion para paypal
			request.session['order_id']=order.id
			# redireccionamos hacia el cobro
			return redirect(reverse('payment:process'))
			# template='orders/order/created.html'
			# context={
			# 'order':order
			# }
			# return render(request,template,context)
		else:
			cart=Cart(request)
			form=OrderCreateForm(request.POST)
			template='orders/order/create.html'
			context={
			'cart':cart,
			'form':form
			}
			return render(request,template,context)
예제 #17
0
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save(commit=False)
            order.account_id = request.user
            order.first_name = request.user.first_name
            order.last_name = request.user.last_name
            order.address = request.user.profile.address
            order.phone = request.user.profile.cellphone
            order.shipment_cost = cart.get_shipment_cost()
            order.books_cost = cart.get_book_price()
            order.save()
            for item in cart:
                OrderList.objects.create(order_id=order,
                                         book_id=item['book'],
                                         book_quantity=item['quantity'],
                                         price=item['price'],
                                         discount=item['discount'])
            cart.clear()
            order_created(request, order.id)
            request.session['order_id'] = order.id
            messages.success(request,
                             'Your order was successfully placed!Please Check your email!')
            return redirect('IB:book_list')
        else:
            messages.error(request, 'Your order got somthing wrong!')
    else:
        form = OrderCreateForm()
    return render(request,
                  'createOrder.html',
                  {'cart': cart,
                   'form': form})
예제 #18
0
파일: views.py 프로젝트: zshuangyan/syan
def order_create(request):
    cart = Cart(request)
    user = request.user
    if request.method == 'POST':
        form= OrderForm(user,request.POST)
        order = form.save(commit = False)
        order.user = user
        order.save()
        for item in cart:
            OrderItem.objects.create(order= order, book = item.book , quantity= item.quantity)
        cart.clear()
        return redirect('order:order_detail', order_id = order.order_id)
    else:
        form = OrderForm(user)
        categories =[]
        for item in cart:
            category = item.book.category
            if category not in categories:
                categories.append(category)
        if categories:
            related_books = Book.objects.filter(category = categories[0])
            if len(categories)>1:
                for category in categories[1:]:
                    related_books= related_books|(Book.objects.filter(category = category))
        related_books = related_books[:5]
        return render(request,'order/order_form.html',{'cart':cart, 'form':form,'related_books':related_books})
예제 #19
0
파일: views.py 프로젝트: lubart2517/shop
def order_create(request):
	cart = Cart(request)
	if request.method == 'POST':
		form = OrderCreateForm(request.POST)
		if form.is_valid():
			order = form.save(commit=False)
			if cart.coupon:
				order.coupon = cart.coupon
				order.discount = cart.coupon.discount
			order.save()
			products_for_redis=[]
			for item in cart:
				OrderItem.objects.create(order=order,
				product=item['product'],
				price=item['price'],
				quantity=item['quantity'])
				products_for_redis.append(item['product'])
				# clear the cart
			r=Recommender()
			r.products_bought(products_for_redis)
			cart.clear()
			# launch asynchronous task
			current_lang=translation.get_language()
			order_created.delay( order.id, current_lang)
			return render(request,
			'orders/order/created.html',
			{'order': order})
	else:
		form = OrderCreateForm()
	return render(request,
	'orders/order/create.html',
	{'cart': cart, 'form': form})
예제 #20
0
 def post(self, request, *args, **kwargs):
     cart = Cart(self.request)
     for item in cart:
         quantity = request.POST.get('q_'+str(item.product.id), None)
         if quantity is not None:
             cart.update(item.product, quantity, item.product.price)
     return redirect("cart")
예제 #21
0
def remove_from_cart(request):
    product_id = request.POST.get('product_id')[0]
    print(product_id)
    product = Product.objects.get(pk=product_id)
    cart = Cart(request)
    cart.remove(product)
    return HttpResponse(cart.summary())
예제 #22
0
파일: views.py 프로젝트: Dzhakhar/myblog
def remove_from_cart(request, pk):
    cart = Cart(request)
    product = Post.objects.get(id=pk)
    cart.remove(product)
    if request.user.is_authenticated():
        request.user.remove_from_product_list(product)

    return render(request, 'blog/cart.html', {'removed_product': product})
예제 #23
0
파일: context.py 프로젝트: Dzhakhar/myblog
def cart_count(request):
    if not request.user.is_anonymous():
        a = request.user.post_set.all().count()
        return {'cart_count': a}

    else:
        c = Cart(request)
        return {'cart_count': c.count()}
예제 #24
0
def order_create(request,total=None):
    cart = Cart(request)
    if request.method == 'POST':
        if request.POST.get('deliver_btn') is not None:
            addid=request.POST.get('optradio')
            addresses=Address.objects.filter(id=addid)

            for address in addresses:
                form = OrderCreateForm(request.POST)
                if form.is_valid():
                    form.save()
                    order = form.save()
                    order.user_id=request.user.id
                    order.fullname=address.fullname
                    order.mobile=address.mobile
                    order.town=address.town
                    order.pincode=address.pincode
                    order.state=address.state
                    order.house=address.house
                    order.area=address.area
                    order.landmark=address.landmark
                    order.save()
            tot=0
            for item in cart:
                if item['product'].stock != 0 :
                    OrderItem.objects.create(
                        order=order,
                        product=item['product'],
                        price=item['price'],
                        quantity=item['quantity'],
                        user_id=request.user.id,
                    )
                    tot=tot+item['price']
                    old_stock=Product.objects.filter(id=item['product'].id)
                    quantity=item['quantity']
                    for old in old_stock:
                        new_stock=int(old.stock)-int(quantity)
                        old.stock=new_stock
                        old.save()
            print(tot)
            cart.clear()
            request.session['order_id']=order.id
            request.session['total']=int(tot)*int(100)
            us=User.objects.filter(id=request.user.id)
            for u in us:
                request.session['mail']=u.email
            return redirect('orders:homeview')
           # return render(request, 'orders/order/created.html',{'order':order})
    else:
        
        form = OrderCreateForm()
        addresses=Address.objects.filter(user_id=request.user.id)
        context={
            'form': form,
            'addresses':addresses,
            'total':total
            }        
        return render(request, 'orders/order/create.html',context)
예제 #25
0
파일: views.py 프로젝트: simple0426/mysite
def cart_add(request, product_id):
    cart = Cart(request)
    product = get_object_or_404(Product, id=product_id)
    form = CartAddProductForm(request.POST)
    if form.is_valid():
        cd = form.cleaned_data
        cart.add(product=product, quantity=cd['quantity'],
            update_quantity=cd['update'])
    return redirect('cart:cart_detail')
예제 #26
0
 def get(self, request, **kwargs):
     if request.is_ajax:
         cart = Cart(request)
         try:
             product = Product.objects.get(id=kwargs['id'])
             quantity = 1
             cart.add(product, product.price, quantity)
             return HttpResponse(json.dumps({'count': cart.count()}))
         except:
             return HttpResponse(json.dumps({'count': cart.count()}))
예제 #27
0
파일: views.py 프로젝트: zshuangyan/syan
def show_cart(request):
    cart = Cart(request)
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            item_id = postdata['item_id']
            cart.remove(item_id = item_id)
        if postdata['submit'] == 'Update':
            item_id = postdata['item_id']
            quantity = postdata['quantity']
            cart.update(item_id = item_id, quantity=quantity)    
    return render(request, 'cart/cart.html',{'cart':cart})
예제 #28
0
파일: views.py 프로젝트: dsalaj/hotpot_at
def add_to_cart(request, product_id, quantity):
    if int(quantity) > 0:
        product = MenuItem.objects.get(id=product_id)
        cart = Cart(request)
        batch_item = Menu.get_current_menu().itembatch_set.get(item=product)
        if batch_item.amount >= int(quantity) + int(cart.get_qty(product)):
            cart.add(product, product.retailer_price(request.session['user']), quantity)
            request.session['quantity_error'] = None
            request.session['quantity_error_item'] = None
            return JsonResponse({"return": "ok"})
        else:
            request.session['quantity_error'] = batch_item.amount
            request.session['quantity_error_item'] = product.name
            return JsonResponse({"return": "fail"})
예제 #29
0
파일: views.py 프로젝트: Dzhakhar/myblog
def add_to_cart(request, pk, q):
    product = Post.objects.get(id=pk)
    product.q = q
    cart = Cart(request)
    added_product = product
    product_user = 0;
    if request.user.is_authenticated():
        product.q = q
        request.user.post_set.add(product)
        product_user = request.user.post_set
        request.products = request.user.post_set.filter(user=request.user)
    else:
        cart.add(product, product.price, q)

    return redirect('blog.views.get_cart')
예제 #30
0
    def form_valid(self, form):
        self.order = form.save()
        cart = Cart(self.request)
        for item in cart:
            OrderItem.objects.create(order=self.order, product=item['product'], price=item['price'],
                                     quantity=item['quantity'])
        cart.clear()

        # launch asynchronous task, only work if worker is running
        order_created.delay(self.order.id)  # set the order in the session

        # return render(self.request, 'orders/order/created.html', {'order': self.order})

        # redirect to the payment (paypal)
        self.request.session['order_id'] = self.order.id
        return redirect(reverse('payment:process'))
예제 #31
0
파일: views.py 프로젝트: belyaev-pa/u-sport
def cart_decr(request, item_id):
  quantity = int(-1)
  product = Product.objects.get(id=item_id)
  cart = Cart(request)
  cart.add(product, product.price, quantity)
  return HttpResponseRedirect(reverse('main:cart_show',)) 
예제 #32
0
파일: views.py 프로젝트: belyaev-pa/u-sport
def cart_show(request):
  setting = Setting.objects.get(pk=1)
  cart = Cart(request)    
예제 #33
0
파일: views.py 프로젝트: Inoxevious/aycii
def remove_from_cart(request, product_id):
    product = Product.objects.get(id=product_id)
    cart = Cart(request)
    cart.remove(product)
    return render(request, 'unify/products/cart.html', {'cart': Cart(request)})
예제 #34
0
파일: views.py 프로젝트: Sumitpande/buyzu
def order_create(request):
    cart = Cart(request)
    addrs = ShippingAddress.objects.filter(user=request.user)
    addrs_form = AddressForm(user=request.user)
    if request.method == 'POST':
        # print(request.POST)
        if 'shipping_address' in request.POST:
            form = AddressForm(request.POST)

        else:
            form = OrderCreateForm(request.POST)
        if form.is_valid():

            if 'shipping_address' in request.POST:

                aid = int(request.POST['shipping_address'])

                ship_addr = ShippingAddress.objects.get(id=aid)
                order = Order(
                    first_name=ship_addr.first_name,
                    last_name=ship_addr.last_name,
                    mobile=ship_addr.mobile,
                    email=ship_addr.user.email,
                    state=ship_addr.state,
                    address=ship_addr.address,
                    postal_code=ship_addr.postal_code,
                    city=ship_addr.city,
                )
            else:
                order = form.save(commit=False)

            if cart.coupon:
                order.coupon = cart.coupon
                order.discount = cart.coupon.discount
            order.save()
            for item in cart:
                OrderItem.objects.create(order=order,
                                         product=item['product'],
                                         price=item['price'],
                                         quantity=item['quantity'])
            # clear the cart
            cart.clear()
            # launch asynchronous task
            order_created(order.id)
            # order_created.delay(order.id)
            # set the order in the session
            request.session['order_id'] = order.id
            # redirect for payment

            return redirect(reverse('payment:process'))

            return render(request, 'orders/created.html', {'order': order})
    else:
        form = OrderCreateForm()
        # coupon_apply_form = CouponApplyForm()

    return render(
        request,
        'orders/create.html',
        {
            'cart': cart,
            'form': form,
            #  'coupon_apply_form':coupon_apply_form,
            'addrs': addrs,
            'addrs_form': addrs_form,
        })
예제 #35
0
def cart(request):
    return {'cart': Cart(request)}
예제 #36
0
파일: views.py 프로젝트: tuchang/myDjango
def add_to_cart(request, product_id, quantity):
    product = models.Product.objects.get(id=product_id)
    cart = Cart(request)
    cart.add(product, product.price, quantity)
    return redirect('/')
예제 #37
0
def item_decrement(request, id):
    cart = Cart(request)
    product = Product.objects.get(id=id)
    cart.decrement(product=product)
    return redirect("cart_detail")
예제 #38
0
 def form_valid(self, form, *args, **kwargs):
     cart = Cart(self.request)
     book = get_object_or_404(Book, id=self.kwargs['book_id'])
     if form.is_valid():
         cart.add(book=book)
     return super(CardAdd, self).form_valid(form)
예제 #39
0
def cart_detail(request):
    cart = Cart(request)
    for item in cart:
        item['update_quantity_form'] = CartAddBookForm(initial={'quantity': item['quantity'],
                                                                'update': True})
    return render(request, 'cart/detail.html', {'cart': cart})
예제 #40
0
 def get_context_data(self, *, object_list=None, **kwargs):
     context = super().get_context_data(**kwargs)
     cart = Cart(self.request)
     context['count'] = cart.count()
     return context
예제 #41
0
파일: views.py 프로젝트: shimaa3434/Wally
def remove_from_cart(request, product_id):
    product = Product.objects.get(id=product_id)
    cart = Cart(request)
    cart.remove(product)
예제 #42
0
파일: views.py 프로젝트: shimaa3434/Wally
def add_to_cart(request, product_id, quantity):
    product = Product.objects.get(id=product_id)
    cart = Cart(request)
    cart.add(product, product.price, quantity)
예제 #43
0
def payment_card(request, token_id):

    profile = Profile.objects.get(user=request.user)
    shipping_address = ShippingAddress.objects.get(user=request.user)

    items = []
    cart = Cart(request)
    try:
        customer = conekta.Customer.create({
            'name':
            profile.name,
            'email':
            request.user.email,
            'phone':
            shipping_address.phone_number,
            'payment_sources': [{
                'type': 'card',
                'token_id': token_id
            }]
        })
    except conekta.ConektaError as e:
        print(e.message)

    for item in cart:
        # Create the list of articles to pass to conekta
        cart_item = {}
        product = item['product']
        cart_item["name"] = product.name
        cart_item["description"] = product.description
        cart_item["unit_price"] = int(item["price"]) * 100
        cart_item["quantity"] = item["quantity"]
        items.append(cart_item)

    try:
        conekta_order = conekta.Order.create({
            "line_items":
            items,
            "shipping_lines": [{
                "amount": SHIPPING_COST,
                "carrier": "El Gran Cazador México"
            }],
            "currency":
            "MXN",
            "card":
            token_id,
            "customer_info": {
                "customer_id": customer.id,
            },
            "shipping_contact": {
                "phone": shipping_address.phone_number,
                "receiver": profile.name,
                "address": {
                    "street1": shipping_address.line1,
                    "city": shipping_address.city,
                    "state": shipping_address.state,
                    "country": "MX",
                    "postal_code": shipping_address.zip_code,
                    "residential": True
                }
            },
            "charges": [{
                "payment_method": {
                    "payment_source_id": customer["payment_sources"][0]["id"],
                    "type": "card"
                }
            }]
        })

        return conekta_order
    except conekta.ConektaError as e:
        return e.error_json['message']
예제 #44
0
파일: views.py 프로젝트: tuchang/myDjango
def remove_from_cart(request, product_id):
    product = models.Product.objects.get(id=product_id)
    cart = Cart(request)
    cart.remove(product)
    return redirect('/cart/')
예제 #45
0
def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save(commit=False)
            client = Client.objects.get(user=request.user)

            order.save()

            client.no_of_orders += 1
            client.save()
            print(client.no_of_orders)

            for item in cart:
                OrderItem.objects.create(order=order,
                                         product=item['product'],
                                         price=item['price'],
                                         quantity=item['quantity'])
            cart.clear()
            # cost=order.get_total_cost()
            discount = order.get_discount(client)
            print(discount)
            print(order.get_total_cost())
            # if client.no_of_orders > 1 :
            # 	 discount=(float(cost)*0.5)
            # 	 print(discount)
            # print(order.get_total_cost())
        return render(
            request, 'orders/order/created.html', {
                'order':
                order,
                'local_css_urls': [
                    "css3/easy-responsive-tabs.css",
                    "css3/material-kit.min1036.css", "css3/demo.css",
                    "css3/vertical-nav.css"
                ],
                'local_js_urls': [
                    "core/jquery.min.js", "core/popper.min.js",
                    "core/bootstrap-material-design.min.js",
                    "js3/vertical-nav.js", "js3/material-kit.min1036.js",
                    "js3/demo.js", "js3/buttons.js", "js3/modernizr.js",
                    "js3/bootstrap.min.js", "js3/plugins/moment.min.js ",
                    "js3/plugins/bootstrap-datetimepicker.js",
                    "js3/plugins/jquery.flexisel.js",
                    "js3/plugins/jquery.sharrre.js",
                    "js3/plugins/nouislider.min.js",
                    "js3/plugins/bootstrap-selectpicker.js",
                    "js3/plugins/bootstrap-tagsinput.js",
                    "js3/plugins/jasny-bootstrap.min.js"
                ],
            })
    else:
        form = OrderCreateForm()
    return render(
        request, 'orders/order/create.html', {
            'form':
            form,
            'local_css_urls': [
                "css3/easy-responsive-tabs.css",
                "css3/material-kit.min1036.css", "css3/demo.css",
                "css3/vertical-nav.css"
            ],
            'local_js_urls': [
                "core/jquery.min.js", "core/popper.min.js",
                "core/bootstrap-material-design.min.js", "js3/vertical-nav.js",
                "js3/material-kit.min1036.js", "js3/demo.js", "js3/buttons.js",
                "js3/modernizr.js", "js3/bootstrap.min.js",
                "js3/plugins/moment.min.js ",
                "js3/plugins/bootstrap-datetimepicker.js",
                "js3/plugins/jquery.flexisel.js",
                "js3/plugins/jquery.sharrre.js",
                "js3/plugins/nouislider.min.js",
                "js3/plugins/bootstrap-selectpicker.js",
                "js3/plugins/bootstrap-tagsinput.js",
                "js3/plugins/jasny-bootstrap.min.js"
            ],
        })
예제 #46
0
파일: views.py 프로젝트: tuchang/myDjango
def cart(request):
    all_categories = models.Category.objects.all()
    cart = Cart(request)
    template = get_template('cart.html')
    html = template.render(context=locals(), request=request)
    return HttpResponse(html)
예제 #47
0
def cart(request):
    if request.session.get('is_login', None):
        all = Product.objects.all()
        cart = Cart(request)
        return render(request, 'mycar.html', locals())
예제 #48
0
def get_cart(request):
    cart = Cart(request)
    template = 'cart.html'
    context = {'cart': cart}
    return render(request, template, context)
예제 #49
0
파일: views.py 프로젝트: Inoxevious/aycii
def add_to_cart(request, product_id, quantity):
    quantity = quantity
    product = Product.objects.get(id=product_id)
    cart = Cart(request)
    cart.add(product, product.unit_price, quantity)
    return render(request, 'unify/products/cart.html', {'cart': Cart(request)})
예제 #50
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['cart'] = Cart(self.request)
     return context
예제 #51
0
파일: views.py 프로젝트: Inoxevious/aycii
def get_cart(request):
    return render(request, 'unify/products/cart.html', {'cart': Cart(request)})
예제 #52
0
def session_cart(request):
    cart = Cart(request)
    return cart
예제 #53
0
파일: views.py 프로젝트: belyaev-pa/u-sport
def cart_del(request, item_id):
  setting = Setting.objects.get(pk=1)
  product = Product.objects.get(id=item_id)
  cart = Cart(request)
  cart.remove(product)
  return HttpResponseRedirect(reverse('main:cart_show',)) 
예제 #54
0
def cart_remove(request, product_id=None):
    cart = Cart(request)
    print(cart)
    product = get_object_or_404(Product, id=product_id)
    cart.remove(product)
    return redirect('cart:cart_detail')
예제 #55
0
def cart_remove(request, product_id):
    cart = Cart(request)
    # print('id(cart) in cart_remove:', id(cart))
    product = get_object_or_404(Product, id=product_id)
    cart.remove_product(product)
    return redirect('cart:cart_detail')
예제 #56
0
def cart_clear(request):
    cart = Cart(request)

    # print('id(cart) in cart_clear:', id(cart))
    cart.clear_cart()
    return redirect(request.META['HTTP_REFERER'])
예제 #57
0
def cart_clear(request):
    cart = Cart(request)
    cart.clear()
    return redirect("cart_detail")
예제 #58
0
파일: views.py 프로젝트: kavehkm/Bookshelf
def cart_remove(request, book_id):
    cart = Cart(request)
    book = get_object_or_404(Book, id=book_id)
    cart.remove(book)
    return redirect('cart_detail')
예제 #59
0
def cart_add(request, id):
    cart = Cart(request)
    product = Product.objects.get(id=id)
    cart.add(product=product)
    return redirect("categori")
예제 #60
0
def item_clear(request, id):
    cart = Cart(request)
    product = Product.objects.get(id=id)
    cart.remove(product)
    return redirect("cart_detail")