def faq(request): faq_questions = FAQ.objects.all() cart = Cart(request) cart_items_count = cart.items_count() context = { 'faq': faq_questions, 'cart': cart_items_count, } return render(request, 'faq.html', context)
def about_us(request): cart = Cart(request) gallery = AboutUsGallery.objects.all() description = AboutUsDesc.objects.first() context = { 'cart': cart.items_count(), 'gallery': gallery, 'description': description, } return render(request, 'about_us.html', context)
def get_context_data(self, **kwargs): cart = Cart(self.request) cart_items = cart.items_list total_price = cart.total_price context = { 'cart_items': cart_items, 'total_price': total_price, 'cart': cart.items_count() } return context
def add_item(request): print("add item view function started") cart = Cart(request) if request.method == 'POST' and request.is_ajax(): product_id = request.POST['product_id'] quantity = request.POST['quantity'] size = request.POST['size'] cart.add_item(request, product_id, quantity, size) items = cart.items_count() return HttpResponse(json.dumps({'cart': items}))
def get_context_data(self, **kwargs): categories = Category.objects.all() products = Products.objects.filter(availability=True) cart = Cart(self.request) context = { 'categories': categories, 'products': products, 'cart': cart.items_count(), } return context
def delete_item(request): cart = Cart(request) if request.method == 'POST' and request.is_ajax(): product_id = request.POST['product_id'] size = request.POST['size'] cart.delete_item(product_id, size) total_price = str(cart.total_price) return_object = {} return HttpResponse(json.dumps({'total_price': total_price})) else: return Http404
def set_quantity(request): cart = Cart(request) if request.method == 'POST' and request.is_ajax(): product_id = request.POST['product-id'] size = request.POST['size'] action = request.POST['action'] if action: cart.set_quantity(product_id, action, size) total_price = str(cart.total_price) response_dict = json.dumps({'total_price': total_price}) return HttpResponse(response_dict) else: return Http404
def category_view(request, id): category = Category.objects.get(id=id) key_group = Products.objects.filter(availability=True).filter( category=category) categories = Category.objects.all() cart = Cart(request) context = { 'categories': categories, 'category': category, 'cart': cart.items_count(), 'key_group': key_group, } return render(request, 'category.html', context)
def search(request): cart = Cart(request) param = request.POST.get('search') categories = Category.objects.all() key_group = Products.objects.filter(availability=True).filter( tags__name__iexact=param) if len(key_group) == 0: key_group = Products.objects.filter(availability=True) context = { 'key_group': key_group, 'categories': categories, 'cart': cart.items_count(), 'param': param } return render(request, 'search.html', context)
def process_request(self, request): """ Add the carts to the request object. """ request.carts = dict( (name, Cart(request, name)) for name, Cart in get_carts().items()) if 'default' in get_carts(): request.cart = request.carts['default'] return None
def product_detail(request, id): product_id = id product = Products.objects.get(id=product_id) availability = product.avalability_type if availability == 'a': availability_type = 'в наличии' else: availability_type = 'под заказ' param = product.category suggestions = Products.objects.filter(category=param).exclude( id=product.id) cart = Cart(request) context = { 'product': product, 'suggestions': suggestions, 'cart': cart.items_count(), 'availability': availability_type, } return render(request, 'product-detail.html', context)
def get(self, request): search = SearchForm() categories_all = Category.objects.all() categories = Category.objects.all()[:4] new_products = Products.objects.filter( availability=True).order_by('-creation')[:6] carousel = Carousel.objects.first() carousel_no_first = Carousel.objects.exclude()[1:] cart = Cart(request) reviews = Reviews.objects.all() context = { 'categories': categories, 'categories_all': categories_all, 'new_products': new_products, 'search': search, 'carousel': carousel, 'carousel_no_first': carousel_no_first, 'cart': cart.items_count(), 'reviews': reviews, } return render(request, 'index.html', context)
def order(request): cart = Cart(request) if request.method == 'POST' and request.is_ajax(): name = request.POST['name'] phone = request.POST['phone'] order = Order(name=name, phone_number=phone, total=Decimal(cart.total_price)) order.save() for item in cart.items_list: item_id = item['product_id'] item_quantity = item['quantity'] item = Products.objects.get(id=item_id) order_item = OrderItem(product=item, quantity=item_quantity, order=order) order_item.save() cart.clean_cart() return HttpResponse('') else: return Http404
def process_request(self, request): request.cart = Cart(request) return None
def clean_cart(request): cart = Cart(request) cart.clean_cart() return HttpResponse('')