def update_shipping(order, shipping, contact, cart): """Set the shipping for this order""" # Set a default for when no shipping module is used order.shipping_cost = Decimal("0.00") # Save the shipping info shipper = shipping_method_by_key(shipping) shipper.calculate(cart, contact) order.shipping_description = shipper.description().encode("utf-8") order.shipping_method = shipper.method() order.shipping_cost = shipper.cost() order.shipping_model = shipping if shipper.carrier: # If shipping details available, set the details for the order if hasattr(shipper.carrier, "signed_for"): order.shipping_signed_for = shipper.carrier.signed_for else: order.shipping_signed_for = False if hasattr(shipper.carrier, "tracked"): order.shipping_tracked = shipper.carrier.tracked else: order.shipping_tracked = False if hasattr(shipper.carrier, "postage_speed"): order.shipping_postage_speed = shipper.carrier.postage_speed else: order.shipping_postage_speed = STANDARD
def update_shipping(order, shipping, contact, cart): """ In-place update of shipping details for this order""" # Set a default for when no shipping module is used order.shipping_cost = Decimal("0.00") # Save the shipping info shipper = shipping_method_by_key(shipping) shipper.calculate(cart, contact) order.shipping_description = shipper.description() order.shipping_method = shipper.method() order.shipping_cost = convert_to_currency( shipper.cost(), order.currency.iso_4217_code ) order.shipping_model = shipping if hasattr(shipper, "carrier"): shipping_details = shipper.carrier else: shipping_details = shipper # If shipping details available, set the details for the order order.shipping_signed_for = getattr(shipping_details, "signed_for", False) order.shipping_tracked = getattr(shipping_details, "tracked", False) order.shipping_postage_speed = getattr(shipping_details, "postage_speed", STANDARD) order.estimated_delivery_min_days = getattr( shipping_details, "estimated_delivery_min_days", 1 ) order.estimated_delivery_expected_days = getattr( shipping_details, "estimated_delivery_expected_days", 7 ) order.estimated_delivery_max_days = getattr( shipping_details, "estimated_delivery_max_days", 25 )
def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False): """Iterate through legal shipping modules, building the list for display to the user. Returns the shipping choices list, along with a dictionary of shipping choices, useful for building javascript that operates on shipping choices. """ shipping_options = [] shipping_dict = {} if not cart.is_shippable: methods = [ shipping_method_by_key('NoShipping'), ] else: methods = shipping_methods() valid_methods = [] for method in methods: method.calculate(cart, contact) if method.valid(): valid_methods.append((method, method.cost())) # sort methods by cost valid_methods.sort(key=lambda method_cost: int(method_cost[1])) for method, shipcost in valid_methods: template = lookup_template(paymentmodule, 'shipping_options.html') t = loader.get_template(template) shipping_tax = None taxed_shipping_price = None if config_value('TAX', 'TAX_SHIPPING'): shipping_tax = config_value('TAX', 'TAX_CLASS') taxer = _get_taxprocessor(request) total = shipcost + taxer.by_price(shipping_tax, shipcost) taxed_shipping_price = money_format(total) data = { 'amount': shipcost, 'description': method.description(), 'method': method.method(), 'expected_delivery': method.expectedDelivery(), 'default_view_tax': default_view_tax, 'shipping_tax': shipping_tax, 'taxed_shipping_price': taxed_shipping_price } if hasattr(method, 'shipping_discount'): data['discount'] = method.shipping_discount() c = RequestContext(request, data) shipping_options.append((method.id, t.render(c))) shipping_dict[method.id] = shipcost return shipping_options, shipping_dict
def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False): """Iterate through legal shipping modules, building the list for display to the user. Returns the shipping choices list, along with a dictionary of shipping choices, useful for building javascript that operates on shipping choices. """ shipping_options = [] shipping_dict = {} if not cart.is_shippable: methods = [shipping_method_by_key("NoShipping")] else: methods = shipping_methods() valid_methods = [] for method in methods: method.calculate(cart, contact) if method.valid(): valid_methods.append((method, method.cost())) # sort methods by cost valid_methods.sort(key=lambda method_cost: int(method_cost[1])) for method, shipcost in valid_methods: template = lookup_template(paymentmodule, "shipping_options.html") t = loader.get_template(template) shipping_tax = None taxed_shipping_price = None if config_value("TAX", "TAX_SHIPPING"): shipping_tax = config_value("TAX", "TAX_CLASS") taxer = _get_taxprocessor(request) total = shipcost + taxer.by_price(shipping_tax, shipcost) currency_code = currency_for_request(request) taxed_shipping_price = money_format(total, currency_code) data = { "amount": shipcost, "description": method.description(), "method": method.method(), "expected_delivery": method.expectedDelivery(), "default_view_tax": default_view_tax, "shipping_tax": shipping_tax, "taxed_shipping_price": taxed_shipping_price, } if hasattr(method, "shipping_discount"): data["discount"] = method.shipping_discount() shipping_options.append((method.id, t.render(data))) shipping_dict[method.id] = shipcost return shipping_options, shipping_dict
def _get_shipping_choices( request, paymentmodule, cart, contact, default_view_tax=False ): """Iterate through legal shipping modules, building the list for display to the user. Returns the shipping choices list, along with a dictionary of shipping choices, useful for building javascript that operates on shipping choices. """ shipping_options = [] shipping_dict = {} if not cart.is_shippable: methods = [shipping_method_by_key("NoShipping")] else: methods = shipping_methods() valid_methods = [] for method in methods: method.calculate(cart, contact) if method.valid(): valid_methods.append((method, method.cost())) # sort methods by cost valid_methods.sort(key=lambda method_cost: int(method_cost[1])) for method, shipcost in valid_methods: template = lookup_template(paymentmodule, "shipping_options.html") t = loader.get_template(template) shipping_tax = None taxed_shipping_price = None if config_value("TAX", "TAX_SHIPPING"): shipping_tax = config_value("TAX", "TAX_CLASS") taxer = _get_taxprocessor(request) total = shipcost + taxer.by_price(shipping_tax, shipcost) currency_code = currency_for_request(request) taxed_shipping_price = money_format(total, currency_code) data = { "amount": shipcost, "description": method.description(), "method": method.method(), "expected_delivery": method.expectedDelivery(), "default_view_tax": default_view_tax, "shipping_tax": shipping_tax, "taxed_shipping_price": taxed_shipping_price, } if hasattr(method, "shipping_discount"): data["discount"] = method.shipping_discount() shipping_options.append((method.id, t.render(data))) shipping_dict[method.id] = shipcost return shipping_options, shipping_dict
def update_shipping(order, shipping, contact, cart): """Set the shipping for this order""" # Set a default for when no shipping module is used order.shipping_cost = Decimal("0.00") # Save the shipping info shipper = shipping_method_by_key(shipping) shipper.calculate(cart, contact) order.shipping_description = shipper.description().encode("utf-8") order.shipping_method = shipper.method() order.shipping_cost = shipper.cost() order.shipping_model = shipping
def _get_shipping_choices(request, paymentmodule, cart, contact, default_view_tax=False): """Iterate through legal shipping modules, building the list for display to the user. Returns the shipping choices list, along with a dictionary of shipping choices, useful for building javascript that operates on shipping choices. """ shipping_options = [] shipping_dict = {} if not cart.is_shippable: methods = [shipping_method_by_key('NoShipping'), ] else: methods = shipping_methods() valid_methods = [] for method in methods: method.calculate(cart, contact) if method.valid(): valid_methods.append((method, method.cost())) # sort methods by cost valid_methods.sort(key=lambda method_cost: int(method_cost[1])) for method, shipcost in valid_methods: template = lookup_template(paymentmodule, 'shipping_options.html') t = loader.get_template(template) shipping_tax = None taxed_shipping_price = None if config_value('TAX', 'TAX_SHIPPING'): shipping_tax = config_value('TAX', 'TAX_CLASS') taxer = _get_taxprocessor(request) total = shipcost + taxer.by_price(shipping_tax, shipcost) taxed_shipping_price = money_format(total) data = { 'amount': shipcost, 'description': method.description(), 'method': method.method(), 'expected_delivery': method.expectedDelivery(), 'default_view_tax': default_view_tax, 'shipping_tax': shipping_tax, 'taxed_shipping_price': taxed_shipping_price } if hasattr(method, 'shipping_discount'): data['discount'] = method.shipping_discount() c = RequestContext(request, data) shipping_options.append((method.id, t.render(c))) shipping_dict[method.id] = shipcost return shipping_options, shipping_dict