Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Cache properties in checkout object
Krzysztof Wolski6f41b11c8d2c
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.pyindex ae7f5e3ba7..c06c415fb8 100644--- a/saleor/checkout/core.py+++ b/saleor/checkout/core.py@@ -31,6 +31,8 @@ class Checkout(object):self.tracking_code = tracking_codeself.user = userself.discounts = cart.discounts+ self.cached_shipping_method = None+ self.cached_shipping_address = None@classmethoddef from_storage(cls, storage_data, cart, user, tracking_code):@@ -86,9 +88,12 @@ class Checkout(object):@propertydef shipping_address(self):+ if self.cached_shipping_address is not None:+ return self.cached_shipping_addressaddress = self._get_address_from_storage('shipping_address')if address is None and self.user.is_authenticated():- return self.user.default_shipping_address+ address = self.user.default_shipping_address+ self.cached_shipping_address = addressreturn address@shipping_address.setter@@ -100,6 +105,8 @@ class Checkout(object):@propertydef shipping_method(self):+ if self.cached_shipping_method is not None:+ return self.cached_shipping_methodshipping_address = self.shipping_addressif shipping_address is not None:shipping_method_country_id = self.storage.get(@@ -113,12 +120,14 @@ class Checkout(object):shipping_country_code = shipping_address.country.codeif (shipping_method_country.country_code == ANY_COUNTRY orshipping_method_country.country_code == shipping_country_code):+ self.cached_shipping_method = shipping_method_countryreturn shipping_method_country@shipping_method.setterdef shipping_method(self, shipping_method_country):self.storage['shipping_method_country_id'] = shipping_method_country.idself.modified = True+ self.cached_shipping_method = shipping_method_country@propertydef email(self):