Пример #1
0
    def get(self, request):
        cart = request.session.get('cart')
        categories = Category.getAllCategory()
        products = Product.getAllProduct().order_by('-id')

        if request.GET.get('id'):
            filterProductById = Product.objects.get(
                id=int(request.GET.get('id')))
            return render(request, 'productDetail.html', {
                "product": filterProductById,
                "categories": categories
            })

        if not cart:
            request.session['cart'] = {}

        if request.GET.get('category_id'):
            filterProduct = Product.getProductByFilter(
                request.GET['category_id'])
            return render(request, 'home.html', {
                "products": filterProduct,
                "categories": categories
            })

        return render(request, 'home.html', {
            "products": products,
            "categories": categories
        })
Пример #2
0
    def get(self, request):
        if request.user.is_anonymous is not True:
            print(request.user.is_seller)
            print(request.user)
            if request.user.is_seller:
                seller = Seller.objects.get(seller=request.user)
                request.session["customer"] = seller.id
            elif request.user.is_customer:
                customer = Customer.objects.get(customer=request.user)
                request.session["customer"] = customer.id

        cart = request.session.get('cart')
        categories = Category.getAllCategory()
        products = Product.getAllProduct().order_by('-id')

        if request.GET.get('id'):

            filterProductById = Product.objects.get(
                id=int(request.GET.get('id')))
            return render(request, 'productDetail.html', {
                "product": filterProductById,
                "categories": categories
            })

        if not cart:
            request.session['cart'] = {}

        if request.GET.get('category_id'):
            filterProduct = Product.getProductByFilter(
                request.GET['category_id'])
            return render(request, 'home.html', {
                "products": filterProduct,
                "categories": categories
            })

        return render(request, 'home.html', {
            "products": products,
            "categories": categories
        })