|
|
|
|
@ -6,7 +6,7 @@ import decimal |
|
|
|
|
|
|
|
|
|
from django.views.generic import ListView |
|
|
|
|
|
|
|
|
|
from cart.forms import CartAddProductForm |
|
|
|
|
# from cart.forms import CartAddProductForm |
|
|
|
|
from .utils import * |
|
|
|
|
from cart.cart import Cart |
|
|
|
|
from .models import * |
|
|
|
|
@ -36,7 +36,7 @@ def producerslist(request): |
|
|
|
|
# category = None |
|
|
|
|
# categories = ProductCategory.objects.filter(level__lte=0) |
|
|
|
|
# products = Product.objects.filter(is_active=True) |
|
|
|
|
producers = Producer.objects.filter(is_active=True) |
|
|
|
|
producers = Manufacturer.objects.filter(is_active=True) |
|
|
|
|
# if category_slug: |
|
|
|
|
# category = get_object_or_404(ProductCategory, slug=category_slug) |
|
|
|
|
# products = products.filter(category__in=category.get_descendants(include_self=True)) |
|
|
|
|
@ -52,49 +52,49 @@ def producerslist(request): |
|
|
|
|
# categories, products = expand_categories(_categories) |
|
|
|
|
# return render(request, 'products/categorieslist.html', {'username': username, 'categories':categories, |
|
|
|
|
# 'products': products}) |
|
|
|
|
|
|
|
|
|
def categorieslist(request, path, instance, producer_slug): |
|
|
|
|
username = auth.get_user(request).username |
|
|
|
|
if instance: |
|
|
|
|
_categories = instance.get_children() |
|
|
|
|
else: |
|
|
|
|
_categories = get_list_or_404(ProductCategory, producer__slug=producer_slug, level__lte=0) |
|
|
|
|
if _categories: |
|
|
|
|
categories, products = expand_categories(_categories) |
|
|
|
|
else: |
|
|
|
|
return productslist(request, producer_slug, instance.slug) |
|
|
|
|
return render( |
|
|
|
|
request, |
|
|
|
|
'products/categorieslist.html', |
|
|
|
|
{ |
|
|
|
|
'username': username, |
|
|
|
|
'instance': instance, |
|
|
|
|
'categories': categories, |
|
|
|
|
'producer_slug': producer_slug, |
|
|
|
|
'products': products |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
def productslist(request, producer_slug, category_slug): |
|
|
|
|
username = auth.get_user(request).username |
|
|
|
|
category = ProductCategory.objects.get(slug=category_slug) |
|
|
|
|
products = Product.objects.filter(is_active=True, category=category) |
|
|
|
|
return render(request, 'products/productslist.html', locals()) |
|
|
|
|
|
|
|
|
|
def product(request, product_slug): |
|
|
|
|
username = auth.get_user(request).username |
|
|
|
|
product = get_object_or_404(Product, slug=product_slug, is_active=True) |
|
|
|
|
cart_product_form = CartAddProductForm() |
|
|
|
|
variant_picker_data = get_variant_picker_data(product) |
|
|
|
|
show_variant_picker = all([v.attributes for v in product.variants.all()]) |
|
|
|
|
# session_key = request.session.session_key |
|
|
|
|
# if not session_key: |
|
|
|
|
# request.session.cycle_key() |
|
|
|
|
|
|
|
|
|
return render(request, 'products/product.html', {'username': username, 'products': product, 'form': cart_product_form, |
|
|
|
|
'show_variant_picker': show_variant_picker, |
|
|
|
|
'variant_picker_data': variant_picker_data, |
|
|
|
|
}) |
|
|
|
|
# |
|
|
|
|
# def categorieslist(request, path, instance, producer_slug): |
|
|
|
|
# username = auth.get_user(request).username |
|
|
|
|
# if instance: |
|
|
|
|
# _categories = instance.get_children() |
|
|
|
|
# else: |
|
|
|
|
# _categories = get_list_or_404(ProductCategory, producer__slug=producer_slug, level__lte=0) |
|
|
|
|
# if _categories: |
|
|
|
|
# categories, products = expand_categories(_categories) |
|
|
|
|
# else: |
|
|
|
|
# return productslist(request, producer_slug, instance.slug) |
|
|
|
|
# return render( |
|
|
|
|
# request, |
|
|
|
|
# 'products/categorieslist.html', |
|
|
|
|
# { |
|
|
|
|
# 'username': username, |
|
|
|
|
# 'instance': instance, |
|
|
|
|
# 'categories': categories, |
|
|
|
|
# 'producer_slug': producer_slug, |
|
|
|
|
# 'products': products |
|
|
|
|
# } |
|
|
|
|
# ) |
|
|
|
|
# |
|
|
|
|
# def productslist(request, producer_slug, category_slug): |
|
|
|
|
# username = auth.get_user(request).username |
|
|
|
|
# category = ProductCategory.objects.get(slug=category_slug) |
|
|
|
|
# products = Product.objects.filter(is_active=True, category=category) |
|
|
|
|
# return render(request, 'products/productslist.html', locals()) |
|
|
|
|
# |
|
|
|
|
# def product(request, product_slug): |
|
|
|
|
# username = auth.get_user(request).username |
|
|
|
|
# product = get_object_or_404(Product, slug=product_slug, is_active=True) |
|
|
|
|
# cart_product_form = CartAddProductForm() |
|
|
|
|
# variant_picker_data = get_variant_picker_data(product) |
|
|
|
|
# show_variant_picker = all([v.attributes for v in product.variants.all()]) |
|
|
|
|
# # session_key = request.session.session_key |
|
|
|
|
# # if not session_key: |
|
|
|
|
# # request.session.cycle_key() |
|
|
|
|
# |
|
|
|
|
# return render(request, 'products/product.html', {'username': username, 'products': product, 'form': cart_product_form, |
|
|
|
|
# 'show_variant_picker': show_variant_picker, |
|
|
|
|
# 'variant_picker_data': variant_picker_data, |
|
|
|
|
# }) |
|
|
|
|
|
|
|
|
|
# Uncomment for elasticsearch |
|
|
|
|
|
|
|
|
|
|