Merge branch 'release/1.0.3'
This commit is contained in:
commit
e919a3cc1b
@ -456,7 +456,7 @@ section:not(:last-child) {
|
||||
background-position: center;
|
||||
color: white;
|
||||
text-align: center;
|
||||
padding: 8rem 1rem;
|
||||
padding: 4rem 1rem;
|
||||
font-family: 'Vollkorn', serif;
|
||||
}
|
||||
.site__banner h1 {
|
||||
@ -568,7 +568,7 @@ article + article {
|
||||
/* Products
|
||||
========================================================================== */
|
||||
.product__list {
|
||||
margin-top: 8rem;
|
||||
margin-top: 4rem;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 8rem;
|
||||
|
||||
@ -3,6 +3,8 @@ import logging
|
||||
from decimal import Decimal
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import redirect, reverse
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
from core.models import Product, OrderLine, Coupon
|
||||
from core.usps import USPSApiWithRate
|
||||
@ -22,6 +24,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class Cart:
|
||||
def __init__(self, request):
|
||||
self.request = request
|
||||
self.session = request.session
|
||||
self.coupon_code = self.session.get('coupon_code')
|
||||
cart = self.session.get(settings.CART_SESSION_ID)
|
||||
@ -73,10 +76,12 @@ class Cart:
|
||||
return sum(item['quantity'] for item in self.cart.values())
|
||||
|
||||
def get_total_weight(self):
|
||||
return sum([item['product'].weight.value * item['quantity'] for item in self])
|
||||
if len(self) > 0:
|
||||
return sum([item['product'].weight.value * item['quantity'] for item in self])
|
||||
else:
|
||||
return 0
|
||||
|
||||
def get_shipping_box(self):
|
||||
logger.info(len(self))
|
||||
if len(self) > 6 and len(self) <= 10:
|
||||
return ShippingContainer.LG_FLAT_RATE_BOX
|
||||
elif len(self) > 2 and len(self) <= 6:
|
||||
@ -87,10 +92,19 @@ class Cart:
|
||||
return ShippingContainer.VARIABLE
|
||||
|
||||
def get_shipping_cost(self):
|
||||
usps_rate_request = self.build_usps_rate_request()
|
||||
usps = USPSApiWithRate(settings.USPS_USER_ID, test=True)
|
||||
validation = usps.get_rate(usps_rate_request)
|
||||
return Decimal(validation.result['RateV4Response']['Package']['Postage']['CommercialRate'])
|
||||
if len(self) > 0:
|
||||
usps_rate_request = self.build_usps_rate_request()
|
||||
usps = USPSApiWithRate(settings.USPS_USER_ID, test=True)
|
||||
validation = usps.get_rate(usps_rate_request)
|
||||
logger.info(validation.result)
|
||||
try:
|
||||
rate = Decimal(validation.result['RateV4Response']['Package']['Postage']['CommercialRate'])
|
||||
return rate
|
||||
except KeyError as e:
|
||||
raise e("USPS Result has no 'Postage'")
|
||||
return Decimal('0.00')
|
||||
else:
|
||||
return Decimal('0.00')
|
||||
|
||||
def get_total_price(self):
|
||||
return sum(Decimal(item['price']) * item['quantity'] for item in self.cart.values())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user