Пример #1
0
def product_details(request, product_id):
    category_list = Category.objects.order_by('created_at')

    product = Product.objects.get(pk=product_id)

    if request.method == 'POST':
        if request.user.is_authenticated():
            postdata = request.POST.copy()
            form = AddToCartForm(request, postdata)
            if form.is_valid():
                cart.add_to_cart(request)
                # if test cookie worked, get rid of it
                if request.session.test_cookie_worked():
                    request.session.delete_test_cookie()

        else:
            return render(request, 'Katale/login.html', {})
    else:
        form = AddToCartForm()
        form.fields['product_id'].widget.attrs['value'] = product_id
        request.session.set_test_cookie()
    cart_item_count = cart.cart_distinct_item_count(request)
    return render(
        request, 'Katale/details.html', {
            'categories': category_list,
            'product': product,
            'cart_form': form,
            'cart_count': cart_item_count,
        })
Пример #2
0
def product_details(request, product_id):
    category_list = Category.objects.order_by('created_at')

    product = Product.objects.get(pk=product_id)

    if request.method == 'POST':
        if request.user.is_authenticated():
            postdata = request.POST.copy()
            form = AddToCartForm(request, postdata)
            if form.is_valid():
                cart.add_to_cart(request)
                # if test cookie worked, get rid of it
                if request.session.test_cookie_worked():
                    request.session.delete_test_cookie()


        else:
            return render(request, 'Katale/login.html', {})
    else:
        form = AddToCartForm()
        form.fields['product_id'].widget.attrs['value'] = product_id
        request.session.set_test_cookie()
    cart_item_count = cart.cart_distinct_item_count(request)
    return render(request, 'Katale/details.html', {'categories': category_list, 'product': product, 'cart_form': form,
                                                   'cart_count': cart_item_count, })
Пример #3
0
def index(request):
    category_list = Category.objects.order_by('created_at')
    # category_list = Category.objects.filter(parent__isnull=True)

    product_list = Product.objects.order_by('created_at')
    if request.method == 'POST':
        if request.user.is_authenticated():
            cart.add_to_cart(request)
        else:
            return render(request, 'Katale/login.html', {})
    cart_item_count = cart.cart_distinct_item_count(request)
    return render(request, 'Katale/index.html', {'categories': category_list, 'products': product_list,
                                                 'cart_count': cart_item_count})
Пример #4
0
def show_cart(request):
    category_list = Category.objects.order_by('created_at')
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
    cart_items = cart.get_cart_items(request)
    cart_item_count = cart.cart_distinct_item_count(request)
    cart_subtotal = cart.cart_total_price(request)
    # final_price = cart.cart_total_price(request)
    return render(request, 'Katale/cart.html',
                  {'products': cart_items, 'cart_count': cart_item_count, 'categories': category_list,
                   'sub_total': cart_subtotal})
Пример #5
0
def index(request):
    category_list = Category.objects.order_by('created_at')
    # category_list = Category.objects.filter(parent__isnull=True)

    product_list = Product.objects.order_by('created_at')
    if request.method == 'POST':
        if request.user.is_authenticated():
            cart.add_to_cart(request)
        else:
            return render(request, 'Katale/login.html', {})
    cart_item_count = cart.cart_distinct_item_count(request)
    return render(
        request, 'Katale/index.html', {
            'categories': category_list,
            'products': product_list,
            'cart_count': cart_item_count
        })
Пример #6
0
def products(request, category_id):
    category_list = Category.objects.order_by('created_at')

    product = Product.objects.filter(category_id=category_id)
    # product = Product.objects.filter(sub_category__category_id=category_id)

    if request.method == 'POST':
        if request.user.is_authenticated():
            cart.add_to_cart(request)
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
                # cart_items = cart.get_cart_items(request)
                # return render(request, 'Katale/cart.html', {'products': cart_items, 'cart_count': cart_item_count})
        else:
            return render(request, 'Katale/login.html', {})

    cart_item_count = cart.cart_distinct_item_count(request)
    return render(request, 'Katale/products.html', {'categories': category_list, 'products': product,
                                                    'cart_count': cart_item_count})
Пример #7
0
def show_cart(request):
    category_list = Category.objects.order_by('created_at')
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
    cart_items = cart.get_cart_items(request)
    cart_item_count = cart.cart_distinct_item_count(request)
    cart_subtotal = cart.cart_total_price(request)
    # final_price = cart.cart_total_price(request)
    return render(
        request, 'Katale/cart.html', {
            'products': cart_items,
            'cart_count': cart_item_count,
            'categories': category_list,
            'sub_total': cart_subtotal
        })
Пример #8
0
def products(request, category_id):
    category_list = Category.objects.order_by('created_at')

    product = Product.objects.filter(category_id=category_id)
    # product = Product.objects.filter(sub_category__category_id=category_id)

    if request.method == 'POST':
        if request.user.is_authenticated():
            cart.add_to_cart(request)
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
                # cart_items = cart.get_cart_items(request)
                # return render(request, 'Katale/cart.html', {'products': cart_items, 'cart_count': cart_item_count})
        else:
            return render(request, 'Katale/login.html', {})

    cart_item_count = cart.cart_distinct_item_count(request)
    return render(
        request, 'Katale/products.html', {
            'categories': category_list,
            'products': product,
            'cart_count': cart_item_count
        })
Пример #9
0
def account_details(request):
    cart_item_count = cart.cart_distinct_item_count(request)

    return render(request, 'Katale/account.html', {'cart_count': cart_item_count})
Пример #10
0
def account_details(request):
    cart_item_count = cart.cart_distinct_item_count(request)

    return render(request, 'Katale/account.html',
                  {'cart_count': cart_item_count})