Created
May 3, 2015 23:19
-
-
Save fawx/e8a76bbacf206abd44b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_total_weight_in_oz(request, order_form): | |
# sort the shopping cart by skus so we can match it up with | |
# an actual queryset of product data (mostly for the weights) | |
cart_by_skus = sorted( request.cart , key=lambda item: item.sku ) | |
skus = [item.sku for item in cart_by_skus] | |
quantities = [item.quantity for item in cart_by_skus] | |
products = ProductVariation.objects.filter(product__sku__in=skus).order_by('sku') | |
discount = '' | |
discounted_products = '' | |
if request.session.get('discount_code'): | |
discount = DiscountCode.objects.get(code=request.session.get('discount_code')) | |
if discount.free_shipping: | |
discounted_products = [product.sku for product in discount.all_products()] | |
i = 0 | |
total_weight = 0 | |
for product in products: | |
if product.product.sku not in discounted_products: | |
total_weight += quantities[i] * product.weight | |
i += 1 | |
return total_weight * 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment