Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
 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
Пример #4
0
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}))
Пример #5
0
    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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
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)
Пример #9
0
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)
Пример #10
0
    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
Пример #11
0
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)
Пример #12
0
    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)
Пример #13
0
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
Пример #14
0
 def process_request(self, request):
     request.cart = Cart(request)
     return None
Пример #15
0
def clean_cart(request):
    cart = Cart(request)
    cart.clean_cart()
    return HttpResponse('')