From f52b529c86e8236f255b8a2f63ab27d855df184f Mon Sep 17 00:00:00 2001
From: Nathan Chapman
Date: Sun, 13 Nov 2022 10:56:00 -0700
Subject: [PATCH 1/4] Remove contact page
---
src/dashboard/templates/dashboard/stock.html | 2 +-
src/storefront/urls.py | 1 -
src/storefront/views.py | 11 -----------
3 files changed, 1 insertion(+), 13 deletions(-)
diff --git a/src/dashboard/templates/dashboard/stock.html b/src/dashboard/templates/dashboard/stock.html
index 9c177b2..69d4817 100644
--- a/src/dashboard/templates/dashboard/stock.html
+++ b/src/dashboard/templates/dashboard/stock.html
@@ -27,7 +27,7 @@
{{variant}}
{{ variant.sku }}
- {{ variant.stock }}
+ {{ variant.stock|default_if_none:"0" }}
{{ variant.total_in_warehouse }}
Restock →
{% endwith %}
diff --git a/src/storefront/urls.py b/src/storefront/urls.py
index 3512184..845250b 100644
--- a/src/storefront/urls.py
+++ b/src/storefront/urls.py
@@ -5,7 +5,6 @@ urlpatterns = [
path('about/', views.AboutView.as_view(), name='about'),
path('fair-trade/', views.FairTradeView.as_view(), name='fair-trade'),
path('reviews/', views.ReviewListView.as_view(), name='reviews'),
- path('contact/', views.ContactFormView.as_view(), name='contact'),
path(
'subscriptions/',
views.SubscriptionCreateView.as_view(),
diff --git a/src/storefront/views.py b/src/storefront/views.py
index 26aaab4..67bd368 100644
--- a/src/storefront/views.py
+++ b/src/storefront/views.py
@@ -558,17 +558,6 @@ class ReviewListView(TemplateView):
template_name = 'storefront/reviews.html'
-class ContactFormView(FormView, SuccessMessageMixin):
- template_name = 'storefront/contact_form.html'
- form_class = ContactForm
- success_url = reverse_lazy('storefront:product-list')
- success_message = 'Message sent.'
-
- def form_valid(self, form):
- form.send_email()
- return super().form_valid(form)
-
-
class SubscriptionCreateView(FormView):
template_name = 'storefront/subscriptions.html'
form_class = SubscriptionCreateForm
From 94908d4230954627d2ad28a88dd491c3ae390151 Mon Sep 17 00:00:00 2001
From: Nathan Chapman
Date: Sun, 13 Nov 2022 12:38:38 -0700
Subject: [PATCH 2/4] Add free shipping only to coffee
---
.../templates/dashboard/category_form.html | 2 +-
src/storefront/cart.py | 24 +++++++++++++------
.../templates/storefront/cart_detail.html | 5 +++-
.../templates/storefront/order_form.html | 4 ++++
src/storefront/tests/__init__.py | 4 ++--
src/storefront/tests/test_payments.py | 2 +-
6 files changed, 29 insertions(+), 12 deletions(-)
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}}
- or cancel
+ or cancel
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 @@
-
+
+ Free shipping on coffee orders over ${{ site_settings.free_shipping_min|floatformat:"2" }}
+ *Merch does not count toward total
+
diff --git a/src/storefront/templates/storefront/order_form.html b/src/storefront/templates/storefront/order_form.html
index 03d8c0e..9447aa8 100644
--- a/src/storefront/templates/storefront/order_form.html
+++ b/src/storefront/templates/storefront/order_form.html
@@ -65,6 +65,10 @@
{% csrf_token %}
{{form.as_p}}
+
+ Free shipping on coffee orders over ${{ site_settings.free_shipping_min|floatformat:"2" }}
+ Merchandise does not count toward total
+
diff --git a/src/storefront/tests/__init__.py b/src/storefront/tests/__init__.py
index e7723de..beb58bb 100644
--- a/src/storefront/tests/__init__.py
+++ b/src/storefront/tests/__init__.py
@@ -20,12 +20,12 @@ class RequestFaker:
},
},
'items': [{
- 'name': 'Decaf: 16 oz',
+ 'name': 'Decaf: 16 oz Grind: Whole Beans',
'description': 'Medium Roast',
'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
'quantity': '1'
}, {
- 'name': 'Decaf: 16 oz',
+ 'name': 'Decaf: 16 oz Grind: Percolator',
'description': 'Medium Roast',
'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
'quantity': '2'
diff --git a/src/storefront/tests/test_payments.py b/src/storefront/tests/test_payments.py
index e8ff9b6..146c9fc 100644
--- a/src/storefront/tests/test_payments.py
+++ b/src/storefront/tests/test_payments.py
@@ -36,7 +36,7 @@ class CreateOrderTest(TestCase):
name='16 oz',
sku='234987',
price=13.4,
- weight=Weight(oz=16),
+ weight=Weight(oz=16)
)
def setUp(self):
From f0a9f2c3faf77e2036ba1ef457eb4a6f609983ab Mon Sep 17 00:00:00 2001
From: Nathan Chapman
Date: Sun, 13 Nov 2022 12:44:53 -0700
Subject: [PATCH 3/4] Remove product category link dropdown menu
---
src/templates/base.html | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/templates/base.html b/src/templates/base.html
index 639b9a5..7de20d5 100644
--- a/src/templates/base.html
+++ b/src/templates/base.html
@@ -46,14 +46,9 @@