def add(request): if request.session.get('restaurant_cart') == None: response = HttpResponse({"error": "there was an error"}) response.status_code = 403 # To announce that the user isn't allowed to publish return response if request.session.get('restaurant_cart'): restaurant_selected_cart = request.session.get('restaurant_cart') # restaurant_selected_cart = request.session.get('restaurant_cart', 0) restaurant = request.GET.get('dr') if (restaurant == restaurant_selected_cart): cart = Cart(request.session) product = Submenu.objects.get(id=request.GET.get('dish_id')) cart.add( product, price=product.price, ) return HttpResponse("Added") else: response = HttpResponse({"error": "there was an error"}) response.status_code = 403 # To announce that the user isn't allowed to publish return response else: restaurant = request.GET.get('dr') cart = Cart(request.session) restaurant_selected_cart = request.session.get('restaurant_cart', restaurant) product = Submenu.objects.get(id=request.GET.get('dish_id')) cart.add( product, price=product.price, ) return HttpResponse("Added")
def add(request, product_id): cart = Cart(request.session) product = Product.objects.get(pk=product_id) cart.add(product, price=product.price) products = Product.objects.order_by('-updated_at') context = {'products': products} return render(request, 'shop/index.html', context)
def add(request): cart = Cart(request.session) selitem_id = request.GET.get('id') selitem_qty = request.GET.get('quantity') selitem = Item.objects.get(id=selitem_id) cart.add(selitem, selitem_qty, price=selitem.price) return redirect(reverse('store') + "#No{}Card".format(selitem.product.id))
def add_cart(request): if request.is_ajax(): if request.method == 'POST': cart = Cart(request.session) producto = Product.objects.get(id=request.POST.get('id')) cart.add(producto,price=producto.price) return HttpResponse('Agregado')
def waiter(): while True: from fridge.models import ShoppingCart, UserLimit, Product from carton.cart import Cart from django.contrib.sessions.backends.db import SessionStore with open('session_key.csv', 'r') as f: data = csv.reader(f) for line in data: k = line k = k[0] s = SessionStore(session_key=k) cart = Cart(s) product = Product.objects.get(name='Avocado') print(product) with open('object_counting_report.csv', 'r') as reading: read = csv.reader(reading) for line in read: for l in line: name = [] number = [] for item in l: if item.isalpha(): name.append(item) elif item.isdigit(): number.append(int(item)) else: pass name = (''.join(c for c in name)) number = (number[0]) prodset = UserLimit.objects.all() # session = requests.Session() for num in prodset: if number < num.set_limit: qty = num.set_limit - number + 1 print( 'dddddddddddddddddddddddddddddddddddddddddddd') print(num.set_limit) try: # tobeupdated = ShoppingCart.objects.get(product=item.product) product = Product.objects.get(name='Avocado') # cart.add( product ) cart.add(product, price=product.selling_price) s.save() print('paint') print(cart.items) print('adding') except: # cart = ShoppingCart(product=item.product, quantity=qty) print('excepted') # pass break
def setUp(self): self.client = Client() self.ticket = set_dependent_classes() self.client.login(username="******", password="******") session = self.client.session cart = Cart(session) cart.add(self.ticket['item'], price=self.ticket['item'].price) session.save()
def add_to_cart(request, restaurant_id, food_item_id): cart = Cart(request.session) food_item = FoodItem.objects.get(id=food_item_id) food_item.times_ordered += 1 food_item.save() cart.add(food_item, price=food_item.price) messages.success(request, '{0} added to Cart'.format(food_item.name)) return redirect('customer:restaurant_view', restaurant_id=restaurant_id)
def add(request): cart = Cart(request.session) event = Event.objects.get(id=request.GET.get('id')) cart.add(event, price=event.price) messages.success(request, "Event added to basket") return render(request, 'ticket/cart/basket.html')
def add_cart(request): if request.method == 'POST': if request.is_ajax(): cart = Cart(request.session) goods = Goods.objects.get(id=request.POST.get('good')) cart.add(goods, price=goods.price) return JsonResponse({'message': "Added {}".format(goods.name)}) return JsonResponse({'message': "Please Access with AJAX/POST"})
def cart_add(request): if request.is_ajax() and request.POST and 'part' in request.POST: cart = Cart(request.session) product = models.Part.objects.get(slug=request.POST.get('part')) cart.add(product, price=product.price) return HttpResponse(content=product.name + " successfully added to cart") else: return HttpResponse(status=400, content="Error adding to cart")
def add(request): cart = Cart(request.session) product = Product.objects.get(pk=request.POST.get('product_id')) quantity = request.POST.get('quantity', 1) discount = request.POST.get('discount', 0) price = product.price - float(discount) cart.add(product, price, quantity) return HttpResponse()
def update_cart(request): cart = Cart(request.session) for product in cart.products: print product.name qty = int(request.POST.get("product_" + str(product.id))) if qty > 0 and qty < 100: cart.remove(product) cart.add(product, price=product.price, quantity=qty) return redirect("pos:cart")
def carrinho_adicionar(request): if request.method == 'POST': carrinho = Cart(request.session) produto = Produto.objects.get(pk=request.POST.get('id')) carrinho.add(produto, price=produto.preco, quantity=request.POST.get('quantidade')) data = json.dumps({'itens': str(len(carrinho.items)), 'total': str(carrinho.total)}) return HttpResponse(data, content_type='application/json') else: return HttpResponse('404')
def add_single(request): cart = Cart(request.session) plato = Plato.objects.get(id=request.GET.get('product_id')) if cart.products: if plato.restaurante.id != cart.products[0].restaurante.id: cart.clear() cart.add(plato, price=plato.precio) return platilla_cesta(request);
def add_single(request): cart = Cart(request.session) plato = Plato.objects.get(id=request.GET.get('product_id')) if cart.products: if plato.restaurante.id != cart.products[0].restaurante.id: cart.clear() cart.add(plato, price=plato.precio) return platilla_cesta(request)
def post(self, request, *args, **kwargs): if not request.is_ajax(): raise Http404 cart = Cart(request.session) try: order_cart = OrderCart.objects.get(session_key=request.session.session_key) except OrderCart.DoesNotExist: order_cart = OrderCart() order_cart.session_key = request.session.session_key order_cart.ip_address = request.META.get('REMOTE_ADDRESS', None) order_cart.save() software = get_object_or_404(SoftwareProduct, slug=kwargs['software_slug']) software_modules = request.POST.get('software_modules', None) try: quantity = int(request.POST.get('quantity', '1')) except ValueError: quantity = 1 software_pricing = get_object_or_404(SoftwareProductPricing, software=software, slug=kwargs['slug'], active=True) discount = software_pricing.software.additional_license_discount price = software_pricing.price software_pks = [str(software_pricing.pk)] if software_modules: software_modules = software_modules.split(",") software_modules = software_pricing.active_software_modules.filter(pk__in=software_modules) for software_module in software_modules: software_pks.append("m_%s" % software_module.pk) price += software_module.price try: order_cart_item = OrderItemCart.objects.get(cart=order_cart, software_pks=",".join(software_pks)) order_cart_item.price = price order_cart_item.quantity = order_cart_item.quantity + quantity quantity = order_cart_item.quantity except OrderItemCart.DoesNotExist: order_cart_item = OrderItemCart() order_cart_item.cart = order_cart order_cart_item.software_pks = ",".join(software_pks) order_cart_item.software = software_pricing order_cart_item.price = price order_cart_item.quantity = quantity order_cart_item.save() if software_modules: order_cart_item.modules = software_modules if discount > 0 and quantity > 1: additional_license_price = price - (price * discount / 100) additional_licenses_price = additional_license_price * (quantity - 1) price = (price + additional_licenses_price) / quantity order_cart_item.price = price order_cart_item.save() cart.remove(order_cart_item) cart.add(order_cart_item, price=order_cart_item.price, quantity=quantity) context = self.get_context_data(**kwargs) context.update({ 'software': software, 'order_cart_item': order_cart_item }) return self.render_to_response(context)
def add(request): cart = Cart(request.session) # Get cart session # Get product, raise error if doesn't exist try: product = Product.objects.get(id=request.GET.get('id')) except Product.DoesNotExist: raise Http404("Product does not exist") cart.add(product, price=product.price) # Add item to cart messages.success(request, 'The item has been added to your cart.') # Msg for success return redirect('all_products')
def add(request): cart = Cart(request.session) product = Product.objects.get(id=request.POST.get('id')) cart.add(product, price=product.price, quantity=request.POST.get('qty')) recent_product = dict(name=product.productName, image=product.image.url, price=product.price, total=cart.total, items=cart.count) return HttpResponse( json.dumps(recent_product, use_decimal=True), content_type="application/json" )
def clear_add(request): cart = Cart(request.session) menu = get_object_or_404(StoreMenu, pk=request.GET.get('menu')) cart.clear() cart.add(menu, price=menu.menu_price) context = { 'message': 'OK', 'total': cart.total, } return JsonResponse(context)
def add_product(request, product_id): cart = Cart(request.session) product = Product.objects.get(pk=product_id) cart.add(product, price=product.price_ukr()) result = {'products_in_cart': len(cart.items), 'cart_total_sum': int(cart.total)} json_response = json.dumps(result) return HttpResponse(json_response, content_type="application/json")
def add(request): cart = Cart(request.session) product = __get_product_from_request(request) if product in cart.products: raise SuspiciousOperation("Photo already in shopping cart") if product.owner == request.user: raise SuspiciousOperation("You can not buy your own photos") cart.add(product, price=product.price) return render(request, 'carts/redirect.html')
def add(request, product_id): cart = Cart(request.session) if Item2.objects.filter(product_id=product_id): product = Item2.objects.get(product_id=product_id) elif Item3.objects.filter(product_id=product_id): product = Item3.objects.get(product_id=product_id) else: product = Item4.objects.get(product_id=product_id) cart.add(product, price=product.price) return HttpResponseRedirect('/tohfa/show')
def add_to_cart(request, site_id): """ Adds Site to the cart """ cart = Cart(request.session) order_site = get_object_or_404(OrderSite, pk=site_id) cart.add(product=order_site, price=order_site.site.price.amount) message = ("{} have been successfully added to the cart.".format( order_site.site.name)) return JsonResponse({"total": cart.total, "message": message})
def add(request): """ 向购物车内增加商品 """ print request.GET print request.POST cart = Cart(request.session) product = Product.objects.get(id=request.GET['id']) quantity = request.POST['quantity'] cart.add(product, price=product.price, quantity=quantity) return HttpResponseRedirect('/cart/')
def add(request): cart = Cart(request.session) item = Menu.objects.get(pk=request.GET.get('menu_id')) if request.user.groups.filter(name="vip").exists(): cart.add(item, price=item.price * .9) else: cart.add(item, price=item.price) message = 'Added ' + item.name + ' to cart' messages.success(request, message) return HttpResponseRedirect('/menu')
def post(self, request): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) cart = Cart(request.session) product = get_object_or_404(Product, id=serializer.data['product_id']) cart.add(product, price=product.price) response_data = { 'detail': 'Product was added to cart.' } response_status = status.HTTP_201_CREATED return Response(response_data, status=response_status)
def add_to_cart(request, slug): if request.is_ajax(): cart = Cart(request.session) product = get_object_or_404(Product, slug=slug) cart.add(product, price=product.price) return render_to_response('mcat_order/cart.html', {'product' : product}, context_instance=RequestContext(request), content_type="application/xhtml+xml" ) else: if settings.DEBUG: print("Not ajax request") raise Http404
def cart_action(request, action): cart = Cart(request.session) item_id = int(request.GET.get('item_id')) item = MenuCollection.get(item_id) if action == 'add': cart.add(item, price=item.price) messages.success(request, '{} adicionado ao carrinho!'.format(item.name)) return HttpResponseRedirect(reverse_lazy('menu:list')) elif action == 'remove': cart.remove(item) messages.success(request, '{} removido do carrinho!'.format(item.name)) return HttpResponseRedirect(reverse_lazy('orders:cart'))
def add(request): cart = Cart(request.session) product = Product.objects.get(id=request.GET.get('id')) try: product_stock = ProductStock.objects.get(product=product) except ObjectDoesNotExist: product_stock = None ####ir buscar preco correcto cart.add(product, price=2) html = new_cart_html(request,0) cart_contents_qty = cart_contents_payload(request) payload = update_cart_status_and_prepare_payload(request, html, cart_contents_qty, True) return HttpResponse(json.dumps(payload), content_type="application/json")
def add(request, item_id): cart = Cart(request.session) print(request.session.session_key) print(request) s_key = request.session.session_key # ****************************** # ****** Let's write the session key to a csv ********** with open('session_key.csv', 'w') as f: s_key = s_key.rsplit(',') print(s_key) writer = csv.writer(f) writer.writerow(s_key) product = Product.objects.get(id=item_id) cart.add(product, price=product.selling_price) return redirect('stock')
def inventory(request): if request.method == 'GET': i = Item.objects.all() items = [] for item in i: print item.name, item.description items.append(item) return HttpResponse(render_template(request, 'SecuCart/inventory.html', { 'items': items })) elif request.method == 'POST': print 'item_number:', request.POST.get('item_number') for i in request.POST: if i != 'item_number': item = Item.objects.get(name=i) print 'item:', i, item.name, item.quantity, item.price item.quantity = item.quantity - int(request.POST.get('item_number')) item.save() cart = Cart(request.session) cart.add(item, price=1.0, quantity=request.POST.get('item_number')) return HttpResponse(render_template(request, 'SecuCart/shopping_cart.html', {}))
def post(self, request, **kwargs): """ Add item to cart. Args: request: The incoming post request object **kwargs: Any keyword arguments passed to the function Returns: A redirect to the deals homepage """ dealid = request.POST.get('dealid') deal = Deal.objects.get(id=dealid) cart = Cart(request.session) cart.add(deal, price=deal.price) return redirect('/')
def add_product(request): cart = Cart(request.session) menu = get_object_or_404(StoreMenu, pk=request.GET.get('menu')) for item in cart.items: old_store_pk = item.product.store.pk if old_store_pk != menu.store.pk: context = { 'message': 'WARNING', 'total': cart.total, } return JsonResponse(context) cart.add(menu, price=menu.menu_price) quantity = cart.cart_serializable[str(menu.pk)]['quantity'] price = cart.cart_serializable[str(menu.pk)]['price'] context = { 'message': 'OK', 'total': cart.total, 'quantity': quantity, 'sub_total': int(quantity) * int(price), } return JsonResponse(context)
def add(request, product_id): product = Product.objects.get(id=product_id) if request.method == "POST": cart = Cart(request.session) form = CartItemForm(request.POST or None) if form.is_valid(): item = form.save() item.final_cost = item.calculateFinalCost() c = item.final_cost print "Final "+str(item.final_cost) if item.rounded: if product.rounded_cost is None: item.final_cost = c + product.category.rounded_cost else: item.final_cost = c + product.rounded_cost cart.add(item, price=item.final_cost) return HttpResponseRedirect("/shopping/cart/") else: print form.errors else: form = CartItemForm(initial={'id':product_id}) token = {} token['form'] = form token['quantities'] = product.quantities.all token['colors'] = product.colors.all token['finishes'] = product.finishes.all token['product'] = product if product.category.rounded and product.rounded: token['can_be_round'] = True token['rounded_cost'] = product.rounded_cost if product.rounded_cost is None: token['rounded_cost'] = product.category.rounded_cost else: token['can_be_round'] = False token.update(csrf(request)) return render_to_response('tinbox/order.html', token)
def post(self, request, *args, **kwargs): action = request.POST.get('action') delete = action == 'delete' clear = action == 'clear' cart = Cart(request.session) product = Product.objects.filter( pk=request.POST.get('product')).first() quantity = request.POST.get('quantity', 1) if delete: if cart.is_empty is False: cart.remove(product) elif clear: if cart.is_empty is False: cart.clear() else: cart.add(product, product.price, quantity) if cart.is_empty: return redirect('product_list') return super().get(request, *args, **kwargs)
def update_cart(request): cart = Cart(request.session) if request.is_ajax(): if request.method == 'POST': product_id = request.POST.get('id') product_qty = request.POST['qty'] if isNum(product_id) and isNum(product_qty) and product_id > 0 and product_qty >= 0: product = Product.objects.get(id=product_id) try: product_stock_count = ProductStock.objects.filter(product=product).count() except ObjectDoesNotExist: product_stock_count = 0 is_valid = False #print product.availability if (product_stock_count > 0 and int(product_qty) > 0 and product_stock_count >= int(product_qty)) or (product.availability == ProductAvailability.objects.get(name='Pre-Order') and int(product_qty) > 0) : cart.remove(product) #print product.price cart.add(product, price=moneyfield_to_decimal(get_correct_price_based_on_quantity(product, int(product_qty))), quantity=product_qty) cart_contents_qty = cart_contents_payload(request) is_valid = True elif int(product_qty) == 0: cart.remove(product) cart_contents_qty = cart_contents_payload_unique(request, True, product_id) elif int(product_qty) > 0: cart_contents_qty = cart_contents_payload_unique(request, True, product_id) #elif int(product_qty) > 0 and product.availability == 'Pre-Order': html = new_cart_html(request, product_qty) payload = update_cart_status_and_prepare_payload(request, html, cart_contents_qty, is_valid) return HttpResponse(json.dumps(payload), content_type="application/json") return HttpResponseRedirect('/')
def add(request): cart = Cart(request.session) pk = request.POST.get('pk') quantity = request.POST.get('quantity') if quantity == '': message = ' 수량을 선택해주세요.' ctx = { 'message': message, } return JsonResponse(ctx) else: product = Product.objects.get(id=pk) if not product.category == 'EXTRA': cart.add(product, price=product.price, quantity=quantity) total_count = cart.count message = ' 상품을 장바구니에 담았습니다.' ctx = { 'message': message, 'total_count': total_count, } return JsonResponse(ctx) elif product.title == '13oz컵 • 홀더 • 뚜겅 세트': cart.add(product, price=product.price, quantity=quantity) total_count = cart.count message = ' 상품을 장바구니에 담았습니다.' ctx = { 'message': message, 'total_count': total_count, } return JsonResponse(ctx) else: cart.add(product, price=product.price, quantity=quantity) for cart_item in cart.items: if cart_item.product.title == product.title: if cart_item.quantity > 5: cart.set_quantity(product, quantity=5) total_count = cart.count message = ' 상품은 최대 5개까지 구매하실 수 있습니다.' ctx = { 'message': message, 'total_count': total_count, } return JsonResponse(ctx) else: total_count = cart.count message = ' 상품을 장바구니에 담았습니다.' ctx = { 'message': message, 'total_count': total_count, } return JsonResponse(ctx)
class CartTests(TestCase): def setUp(self): engine = import_module(settings.SESSION_ENGINE) self.session = engine.SessionStore() self.session.save() self.client.cookies[ settings.SESSION_COOKIE_NAME] = self.session.session_key self.factory = RequestFactory() self.cart = Cart(self.session) self.deer = Product.objects.create( name='deer', price=10.0, custom_id=1, ) self.moose = Product.objects.create( name='moose', price=20.0, custom_id=2, ) self.ticket = Ticket.objects.create( name='Clint Mansell', price=25.0, custom_id=6, ) def show_response(self): """ Utility method to return a response from the `show` view. """ request = self.factory.get(reverse('carton-tests-show')) request.session = self.session return show(request) def test_product_is_added(self): """ Can a product be added to the cart? """ self.cart.add(self.deer, 10.00, 1) self.session.save() self.assertContains(self.show_response(), '1 deer for $10.0') def test_multiple_products_are_added(self): """ Can multiple products be added to the cart? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.moose, 20.00, 1) self.session.save() response = self.show_response() self.assertContains(response, '1 deer for $10.0') self.assertContains(response, '1 moose for $20.0') def test_stale_item_is_removed_from_cart(self): """ Are items which are not in the database kept out of the cart? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.moose, 20.00, 1) self.session.save() response = self.show_response() self.assertContains(response, 'deer') self.assertContains(response, 'moose') self.deer.delete() response = self.show_response() self.assertNotContains(response, 'deer') self.assertContains(response, 'moose') def test_quantity_increases(self): """ Do multiple calls to `add` increase the quantity in the cart? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.deer, 10.00, 2) self.session.save() self.assertContains(self.show_response(), '3 deer') def test_items_are_counted_properly(self): """ Are items in the cart counted correctly? """ self.cart.add(self.deer, 10.00, 2) self.cart.add(self.moose, 20.00, 1) self.session.save() response = self.show_response() self.assertContains(response, 'items count: 3') self.assertContains(response, 'unique count: 2') def test_products_are_removed_all_together(self): """ Can all products of a single type be removed? """ self.cart.add(self.deer, 10.00, 3) self.cart.add(self.moose, 20.00, 1) self.session.save() self.cart.remove(self.deer) response = self.show_response() self.assertNotContains(response, 'deer') self.assertContains(response, 'moose') def test_single_product_is_removed(self): """ Can a single instance of a product be removed? """ self.cart.add(self.deer, 10.00, 3) self.session.save() self.cart.remove_single(self.deer) self.assertContains(self.show_response(), '2 deer') def test_quantity_is_overwritten(self): """ Can an items quantity be changed? """ self.cart.add(self.deer, 10.00, 3) self.session.save() self.cart.set_quantity(self.deer, 4) self.assertContains(self.show_response(), '4 deer') def test_cart_items_are_cleared(self): """ Can a cart be entirely cleared? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.moose, 20.00, 1) self.cart.clear() self.session.save() response = self.show_response() self.assertNotContains(response, 'deer') self.assertNotContains(response, 'moose') @override_settings(CART_PRODUCT_LOOKUP={'price__gt': 1}) def test_custom_product_filter_are_applied(self): """ We modify the cart queryset to exclude some products. We should not be able to add excluded products to the cart. """ exclude = Product.objects.create( name='EXCLUDED', price=0.99, custom_id=100, ) self.cart.add(self.deer, 10.00, 1) self.cart.add(exclude, exclude.price, 1) self.session.save() response = self.show_response() self.assertNotContains(response, 'EXCLUDE') self.assertContains(response, 'deer') def test_get_model_product_path(self): """ Is a string with the full, correct import path returned for a model? """ self.assertEqual( self.cart.get_product_model_path(self.deer), 'carton.tests.models.Product', ) def test_different_product_models(self): """ Does the cart work with different models? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.ticket, 25.00, 1) self.session.save() response = self.show_response() self.assertContains(response, '1 deer for $10.0') self.assertContains(response, '1 Clint Mansell for $25.0')
def add(request): cart = Cart(request.session) product = Product.objects.get(id=request.GET.get('id')) cart.add(product, price=product.price) return HttpResponse("Added")
class CartTests(TestCase): def setUp(self): engine = import_module(settings.SESSION_ENGINE) self.session = engine.SessionStore() self.session.save() self.client.cookies[settings.SESSION_COOKIE_NAME] = self.session.session_key self.factory = RequestFactory() self.cart = Cart(self.session) self.deer = Product.objects.create( name='deer', price=10.0, custom_id=1, ) self.moose = Product.objects.create( name='moose', price=20.0, custom_id=2, ) self.ticket = Ticket.objects.create( name='Clint Mansell', price=25.0, custom_id=6, ) def show_response(self): """ Utility method to return a response from the `show` view. """ request = self.factory.get(reverse('carton-tests-show')) request.session = self.session return show(request) def test_product_is_added(self): """ Can a product be added to the cart? """ self.cart.add(self.deer, 10.00, 1) self.session.save() self.assertContains(self.show_response(), '1 deer for $10.0') def test_multiple_products_are_added(self): """ Can multiple products be added to the cart? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.moose, 20.00, 1) self.session.save() response = self.show_response() self.assertContains(response, '1 deer for $10.0') self.assertContains(response, '1 moose for $20.0') def test_stale_item_is_removed_from_cart(self): """ Are items which are not in the database kept out of the cart? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.moose, 20.00, 1) self.session.save() response = self.show_response() self.assertContains(response, 'deer') self.assertContains(response, 'moose') self.deer.delete() response = self.show_response() self.assertNotContains(response, 'deer') self.assertContains(response, 'moose') def test_quantity_increases(self): """ Do multiple calls to `add` increase the quantity in the cart? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.deer, 10.00, 2) self.session.save() self.assertContains(self.show_response(), '3 deer') def test_items_are_counted_properly(self): """ Are items in the cart counted correctly? """ self.cart.add(self.deer, 10.00, 2) self.cart.add(self.moose, 20.00, 1) self.session.save() response = self.show_response() self.assertContains(response, 'items count: 3') self.assertContains(response, 'unique count: 2') def test_products_are_removed_all_together(self): """ Can all products of a single type be removed? """ self.cart.add(self.deer, 10.00, 3) self.cart.add(self.moose, 20.00, 1) self.session.save() self.cart.remove(self.deer) response = self.show_response() self.assertNotContains(response, 'deer') self.assertContains(response, 'moose') def test_single_product_is_removed(self): """ Can a single instance of a product be removed? """ self.cart.add(self.deer, 10.00, 3) self.session.save() self.cart.remove_single(self.deer) self.assertContains(self.show_response(), '2 deer') def test_quantity_is_overwritten(self): """ Can an items quantity be changed? """ self.cart.add(self.deer, 10.00, 3) self.session.save() self.cart.set_quantity(self.deer, 4) self.assertContains(self.show_response(), '4 deer') def test_cart_items_are_cleared(self): """ Can a cart be entirely cleared? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.moose, 20.00, 1) self.cart.clear() self.session.save() response = self.show_response() self.assertNotContains(response, 'deer') self.assertNotContains(response, 'moose') @override_settings(CART_PRODUCT_LOOKUP={'price__gt': 1}) def test_custom_product_filter_are_applied(self): """ We modify the cart queryset to exclude some products. We should not be able to add excluded products to the cart. """ exclude = Product.objects.create( name='EXCLUDED', price=0.99, custom_id=100, ) self.cart.add(self.deer, 10.00, 1) self.cart.add(exclude, exclude.price, 1) self.session.save() response = self.show_response() self.assertNotContains(response, 'EXCLUDE') self.assertContains(response, 'deer') def test_get_model_product_path(self): """ Is a string with the full, correct import path returned for a model? """ self.assertEqual( self.cart.get_product_model_path(self.deer), 'carton.tests.models.Product', ) def test_different_product_models(self): """ Does the cart work with different models? """ self.cart.add(self.deer, 10.00, 1) self.cart.add(self.ticket, 25.00, 1) self.session.save() response = self.show_response() self.assertContains(response, '1 deer for $10.0') self.assertContains(response, '1 Clint Mansell for $25.0')
def add(request, id): cart = Cart(request.session) product = get_object_or_404(models.Product, pk=id) cart.add(product, price=product.price) return HttpResponse(product.price)
def add_to_cart(request, id): cart = Cart(request.session) product = get_object_or_404(models.Product, pk=id) cart.add(product, price=product.price) return HttpResponseRedirect('../../../card/showcard')
def add(request): cart = Cart(request.session) isbn = request.POST.get("book_isbn", "") product = Book.objects.get(isbn=isbn) cart.add(product, price=product.price) return render(request, 'shopping/show-cart.html')
def add(request): cart = Cart(request.session) product = Product.objects.get(id=request.GET.get('product_id')) cart.add(product, price=product.price) messages.success(request, 'Prodotto Aggiunto al Carrello') return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def add(request): cart = Cart(request.session) libro = Libro.objects.get(id=request.GET.get("id")) cart.add(libro, price=libro.precio) return render(request, "gracias.html")
def add_to_cart(request, pid): product = m.Product.objects.get(id=pid) cart = Cart(request.session) cart.add(product, price=product.price) return HttpResponse('add_success')
def add_to_cart(request, Product_id): cart = Cart(request.session) product = Product.objects.get(id=Product_id) cart.add(product, product.price) return HttpResponse("Added")
def add(request, num=None): cart = Cart(request.session) item = Menu.objects.get(id=num) cart.add(item, price=item.price) return HttpResponse("Added")