def shipping_method(self, basket=None, key=None): """ Returns the shipping method model based on the data stored in the session. """ if not basket: basket = self.request.basket if not key: package = basket.get_package() if basket else None if package: key = package.upc if self.is_return_to_store_enabled(): key += "_return-to-store" rep = self.get_shipping_repository(key) if rep: code = self._get('shipping', 'method_code') if code: return rep.find_by_code(code, basket) #fallback to no shipping required and catch cases where it does not allow. #No shipping required is only valid for return to merchant where return label provided to us #in all other cases we shall redirect to pending packages page with a message no_shipping_required = methods.NoShippingRequired() return no_shipping_required
def find_by_code(self, code, basket): """ Return the appropriate Method object for the given code """ for method_class in self.methods: if method_class.code == code: method = method_class() return self.prime_method(basket, method) # Check for NoShippingRequired as that is a special case if code == methods.NoShippingRequired.code: return self.prime_method(basket, methods.NoShippingRequired())
def get_shipping_methods(self, basket, shipping_addr=None, **kwargs): """ Return a list of all applicable shipping method instances for a given basket, address etc. """ if not basket.is_shipping_required(): # Special case! Baskets that don't require shipping get a special # shipping method. return [shipping_methods.NoShippingRequired()] methods = self.get_available_shipping_methods( basket=basket, shipping_addr=shipping_addr, **kwargs) if basket.has_shipping_discounts: methods = self.apply_shipping_offers(basket, methods) return methods
def get_shipping_methods(self, user, basket, shipping_addr=None, request=None, **kwargs): """ Return a list of all applicable shipping method objects for a given basket, address etc. We default to returning the ``Method`` models that have been defined but this behaviour can easily be overridden by subclassing this class and overriding this method. """ if not basket.is_shipping_required(): return [methods.NoShippingRequired()] # We need to instantiate each method class to avoid thread-safety # issues methods_ = [klass() for klass in self.methods] return self.prime_methods(basket, methods_)
def setUp(self): self.method = methods.NoShippingRequired() basket = Basket() self.charge = self.method.calculate(basket)
def setUp(self): self.method = methods.NoShippingRequired()