Beispiel #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)
Beispiel #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)
Beispiel #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
Beispiel #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}))
Beispiel #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
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
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)