diff --git a/src/dashboard/templates/dashboard/category_form.html b/src/dashboard/templates/dashboard/category_form.html index b71aa94..d5941d5 100644 --- a/src/dashboard/templates/dashboard/category_form.html +++ b/src/dashboard/templates/dashboard/category_form.html @@ -10,7 +10,7 @@ {% csrf_token %} {{form.as_p}}
diff --git a/src/storefront/cart.py b/src/storefront/cart.py index 0898156..af3d7fb 100644 --- a/src/storefront/cart.py +++ b/src/storefront/cart.py @@ -10,7 +10,7 @@ from django.core.cache import cache from django.db.models import OuterRef, Q, Subquery from core.models import ( - Product, ProductVariant, OrderLine, Coupon, ShippingRate, + ProductCategory, Product, ProductVariant, OrderLine, Coupon, ShippingRate, SiteSettings ) from core.usps import USPSApi @@ -60,11 +60,11 @@ class CartItem: class Cart: item_class = CartItem - # site_settings = SiteSettings.load() def __init__(self, request): self.request = request self.session = request.session + self.site_settings = SiteSettings.load() self.coupon_code = self.session.get('coupon_code') cart = self.session.get(settings.CART_SESSION_ID) if not cart: @@ -129,6 +129,16 @@ class Cart: def __len__(self): return sum([item['quantity'] for item in self.cart]) + def get_item_prices_for_category(self, category): + for item in self: + if item['variant'].product.category == category: + yield item['price_total'] + else: + continue + + def get_total_price_for_category(self, category): + return sum(self.get_item_prices_for_category(category)) + def get_all_item_quantities(self): for item in self.cart: yield item['quantity'] @@ -139,8 +149,6 @@ class Cart: def get_item_prices(self): for item in self: yield item['price_total'] - # for item in self.cart.values(): - # yield Decimal(item['price']) * sum([value['quantity'] for value in item['variations'].values()]) def get_total_price(self): return sum(self.get_item_prices()) @@ -170,9 +178,11 @@ class Cart: return containers def get_shipping_cost(self, container=None): - # free_shipping_min = self.site_settings.free_shipping_min - # if self.get_total_price() >= free_shipping_min: - # return Decimal('0.00') + free_shipping_min = self.site_settings.free_shipping_min + if free_shipping_min is not None: + category = ProductCategory.objects.get(name='Coffee') + if self.get_total_price_for_category(category) >= free_shipping_min: + return Decimal('0.00') if container is None: container = self.session.get('shipping_container').container diff --git a/src/storefront/templates/storefront/cart_detail.html b/src/storefront/templates/storefront/cart_detail.html index 6b34eb6..c7225b8 100644 --- a/src/storefront/templates/storefront/cart_detail.html +++ b/src/storefront/templates/storefront/cart_detail.html @@ -58,7 +58,10 @@ - +