Add free shipping only to coffee
This commit is contained in:
parent
f52b529c86
commit
94908d4230
@ -10,7 +10,7 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{form.as_p}}
|
{{form.as_p}}
|
||||||
<p class="form__submit">
|
<p class="form__submit">
|
||||||
<input class="action-button" type="submit" value="Create category"> or <a href="{% url 'dashboard:category-detail' category.pk %}">cancel</a>
|
<input class="action-button" type="submit" value="Save changes"> or <a href="{% url 'dashboard:category-detail' category.pk %}">cancel</a>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from django.core.cache import cache
|
|||||||
from django.db.models import OuterRef, Q, Subquery
|
from django.db.models import OuterRef, Q, Subquery
|
||||||
|
|
||||||
from core.models import (
|
from core.models import (
|
||||||
Product, ProductVariant, OrderLine, Coupon, ShippingRate,
|
ProductCategory, Product, ProductVariant, OrderLine, Coupon, ShippingRate,
|
||||||
SiteSettings
|
SiteSettings
|
||||||
)
|
)
|
||||||
from core.usps import USPSApi
|
from core.usps import USPSApi
|
||||||
@ -60,11 +60,11 @@ class CartItem:
|
|||||||
|
|
||||||
class Cart:
|
class Cart:
|
||||||
item_class = CartItem
|
item_class = CartItem
|
||||||
# site_settings = SiteSettings.load()
|
|
||||||
|
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
self.request = request
|
self.request = request
|
||||||
self.session = request.session
|
self.session = request.session
|
||||||
|
self.site_settings = SiteSettings.load()
|
||||||
self.coupon_code = self.session.get('coupon_code')
|
self.coupon_code = self.session.get('coupon_code')
|
||||||
cart = self.session.get(settings.CART_SESSION_ID)
|
cart = self.session.get(settings.CART_SESSION_ID)
|
||||||
if not cart:
|
if not cart:
|
||||||
@ -129,6 +129,16 @@ class Cart:
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return sum([item['quantity'] for item in self.cart])
|
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):
|
def get_all_item_quantities(self):
|
||||||
for item in self.cart:
|
for item in self.cart:
|
||||||
yield item['quantity']
|
yield item['quantity']
|
||||||
@ -139,8 +149,6 @@ class Cart:
|
|||||||
def get_item_prices(self):
|
def get_item_prices(self):
|
||||||
for item in self:
|
for item in self:
|
||||||
yield item['price_total']
|
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):
|
def get_total_price(self):
|
||||||
return sum(self.get_item_prices())
|
return sum(self.get_item_prices())
|
||||||
@ -170,9 +178,11 @@ class Cart:
|
|||||||
return containers
|
return containers
|
||||||
|
|
||||||
def get_shipping_cost(self, container=None):
|
def get_shipping_cost(self, container=None):
|
||||||
# free_shipping_min = self.site_settings.free_shipping_min
|
free_shipping_min = self.site_settings.free_shipping_min
|
||||||
# if self.get_total_price() >= free_shipping_min:
|
if free_shipping_min is not None:
|
||||||
# return Decimal('0.00')
|
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:
|
if container is None:
|
||||||
container = self.session.get('shipping_container').container
|
container = self.session.get('shipping_container').container
|
||||||
|
|||||||
@ -58,7 +58,10 @@
|
|||||||
<input type="submit" value="Apply" class="action-button">
|
<input type="submit" value="Apply" class="action-button">
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
<!-- <h5>Free shipping on orders over ${{ site_settings.free_shipping_min|floatformat:"2" }}</h5> -->
|
<h5>
|
||||||
|
Free shipping on coffee orders over ${{ site_settings.free_shipping_min|floatformat:"2" }}<br>
|
||||||
|
<small>*Merch does not count toward total</small>
|
||||||
|
</h5>
|
||||||
<div class="cart__table-wrapper">
|
<div class="cart__table-wrapper">
|
||||||
<table class="cart__totals">
|
<table class="cart__totals">
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@ -65,6 +65,10 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{form.as_p}}
|
{{form.as_p}}
|
||||||
</form>
|
</form>
|
||||||
|
<h5>
|
||||||
|
Free shipping on coffee orders over ${{ site_settings.free_shipping_min|floatformat:"2" }}<br>
|
||||||
|
<small><em>Merchandise does not count toward total</em></small>
|
||||||
|
</h5>
|
||||||
<div class="cart__table-wrapper">
|
<div class="cart__table-wrapper">
|
||||||
<table class="cart__totals">
|
<table class="cart__totals">
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@ -20,12 +20,12 @@ class RequestFaker:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
'items': [{
|
'items': [{
|
||||||
'name': 'Decaf: 16 oz',
|
'name': 'Decaf: 16 oz Grind: Whole Beans',
|
||||||
'description': 'Medium Roast',
|
'description': 'Medium Roast',
|
||||||
'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
|
'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
|
||||||
'quantity': '1'
|
'quantity': '1'
|
||||||
}, {
|
}, {
|
||||||
'name': 'Decaf: 16 oz',
|
'name': 'Decaf: 16 oz Grind: Percolator',
|
||||||
'description': 'Medium Roast',
|
'description': 'Medium Roast',
|
||||||
'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
|
'unit_amount': {'currency_code': 'USD', 'value': '13.40'},
|
||||||
'quantity': '2'
|
'quantity': '2'
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class CreateOrderTest(TestCase):
|
|||||||
name='16 oz',
|
name='16 oz',
|
||||||
sku='234987',
|
sku='234987',
|
||||||
price=13.4,
|
price=13.4,
|
||||||
weight=Weight(oz=16),
|
weight=Weight(oz=16)
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user