def net(self, items): settings = get_shop_shipping_settings() calc = CartItemCalculator(self.context) shipping_limit_from_gross = settings.shipping_limit_from_gross free_shipping_limit = Decimal(str(settings.free_shipping_limit)) purchase_price = Decimal(0) # calculate shipping from gross if shipping_limit_from_gross: purchase_price += calc.net(items) + calc.vat(items) # calculate shipping from net else: purchase_price += calc.net(items) # purchase price exceeds free shipping limit, no shipping costs if free_shipping_limit and purchase_price > free_shipping_limit: return Decimal(0) flat_shipping_cost = Decimal(str(settings.flat_shipping_cost)) item_shipping_cost = Decimal(str(settings.item_shipping_cost)) shipping_costs = Decimal(0) # item shipping costs set, calculate for contained cart items if item_shipping_cost > Decimal(0): for item in items: if not cart_item_shippable(self.context, item): continue shipping_costs += item_shipping_cost * item[1] # consider flat shipping cost if set if flat_shipping_cost: # item shipping costs exceed flat shipping costs if shipping_costs > flat_shipping_cost: return shipping_costs # flat shipping costs apply return Decimal(flat_shipping_cost) # return calculated shipping costs return shipping_costs
def net(self, items): settings = get_shop_shipping_settings() cart_data = get_data_provider(self.context) shipping_limit_from_gross = settings.shipping_limit_from_gross free_shipping_limit = Decimal(str(settings.free_shipping_limit)) purchase_price = Decimal(0) # calculate shipping from gross if shipping_limit_from_gross: purchase_price += cart_data.net(items) + cart_data.vat(items) # calculate shipping from net else: purchase_price += cart_data.net(items) # purchase price exceeds free shipping limit, no shipping costs if free_shipping_limit and purchase_price > free_shipping_limit: return Decimal(0) flat_shipping_cost = Decimal(str(settings.flat_shipping_cost)) item_shipping_cost = Decimal(str(settings.item_shipping_cost)) # flag whether all items have free shipping flag set all_items_free_shipping = True shipping_costs = Decimal(0) # item shipping costs set, calculate for contained cart items if item_shipping_cost > Decimal(0): for item in items: # ignore item if not shippable if not cart_item_shippable(self.context, item): continue # ignore item if free shipping set if cart_item_free_shipping(self.context, item): continue # as soon as one item in cart has no free shipping, # all_items_free_shipping is False all_items_free_shipping = False shipping_costs += item_shipping_cost * item[1] # calculate flat shipping costs anyway if no item shipping costs else: all_items_free_shipping = False # consider flat shipping cost if set, gets ignored if all items # have free shipping set if flat_shipping_cost and not all_items_free_shipping: # item shipping costs exceed flat shipping costs if shipping_costs > flat_shipping_cost: return shipping_costs # flat shipping costs apply return Decimal(flat_shipping_cost) # return calculated shipping costs return shipping_costs