def get_shipping_method(self, basket, shipping_address=None, **kwargs): """ Return the shipping method used """ if not basket.is_shipping_required(): return NoShippingRequired() # Instantiate a new FixedPrice shipping method instance charge_incl_tax = D(self.txn.value('PAYMENTREQUEST_0_SHIPPINGAMT')) # Assume no tax for now charge_excl_tax = charge_incl_tax name = self.txn.value('SHIPPINGOPTIONNAME') session_method = super(SuccessResponseView, self).get_shipping_method( basket, shipping_address, **kwargs) if not session_method or (name and name != session_method.name): if name: method = self._get_shipping_method_by_name(name, basket, shipping_address) else: method = None if not method: method = FixedPrice(charge_excl_tax, charge_incl_tax) if session_method: method.name = session_method.name method.code = session_method.code else: method = session_method return method
from decimal import Decimal as D from oscar.apps.shipping.methods import FixedPrice, NoShippingRequired from oscar.apps.shipping.repository import Repository as CoreRepository # Dummy shipping methods method1 = FixedPrice(D("10.00")) method1.code = "method1" method1.description = "Ship by van" method2 = FixedPrice(D("20.00")) method2.code = "method2" method2.description = "Ship by boat" METHODS = (method1, method2) class Repository(CoreRepository): def get_shipping_methods(self, user, basket, shipping_addr=None, **kwargs): return self.prime_methods(basket, METHODS) def find_by_code(self, code, basket): if code == NoShippingRequired.code: method = NoShippingRequired() else: method = None for method_ in METHODS: if method_.code == code: method = method_ if method is None: raise ValueError("No shipping method found with code '%s'" % code) return self.prime_method(basket, method)
from decimal import Decimal as D from oscar.apps.shipping.methods import FixedPrice, NoShippingRequired from oscar.apps.shipping.repository import Repository as CoreRepository # Dummy shipping methods method1 = FixedPrice(D('12.00')) method1.code = 'method1' method1.name = 'Ship by van' method2 = FixedPrice(D('24.00')) method2.code = 'method2' method2.name = 'Ship by pigeon' method2.description = 'Here is a description of this shipping method' class Repository(CoreRepository): methods = { method1.code: method1, method2.code: method2, } def get_shipping_methods(self, user, basket, shipping_addr=None, **kwargs): methods = self.methods.values() return self.prime_methods(basket, methods) def find_by_code(self, code, basket): if code == NoShippingRequired.code: method = NoShippingRequired() else: method = self.methods.get(code, None) return self.prime_method(basket, method)
from decimal import Decimal as D from oscar.apps.shipping.methods import FixedPrice from oscar.apps.shipping.repository import Repository as CoreRepository # Dummy shipping methods method1 = FixedPrice(charge_excl_tax=D("10.00"), charge_incl_tax=D("10.00")) method1.code = "method1" method1.description = "Ship by van" method2 = FixedPrice(charge_excl_tax=D("20.00"), charge_incl_tax=D("20.00")) method2.code = "method2" method2.description = "Ship by boat" class Repository(CoreRepository): methods = ( method1, method2, )