def get_order_from_id(id): """ An order_id is a string consisting of the userid and the order date in iso format, joined by the pipe character. """ userid, datestr = id.split('|') date = parser.parse(datestr) if userid == '_orders_': data = storage.get_shop_data(['orders', date]) else: data = storage.get_shop_data([userid, 'orders', date]) return data
def shipping_methods(self): method_map = storage.get_shop_data(['shipping_methods'], default={}) methods = [] for key, method in list(method_map.items()): method['key'] = key methods.append(method) return methods
def from_request(cls, request, user_id=None, browser_id=None): """Get the user's shopping cart. The cart is an OrderedDict keyed by product UID. It's stored in a BTree on the site, keyed by user id for logged-in users and by the browser id cookie for anonymous users. If a user starts logged out and then logs in, the cart is moved. """ if user_id is None: user_id = get_current_userid() if browser_id is None: browser_id = get_site().browser_id_manager.getBrowserId() if user_id is not None: # logged in storage_id = user_id data = storage.get_shop_data([user_id, 'cart']) if data is None: # not found; see if there's an anonymous one # we can upgrade to be stored by user id data = storage.get_shop_data([browser_id, 'cart']) if data is not None: for item in data['items']: try: item['user'] = user_id except TypeError: # we had at least one case in # production of a corrupted cart # just create a new one if it happens data = PersistentMapping() break storage.del_shop_data([browser_id]) else: # create a new cart data = PersistentMapping() storage.set_shop_data([user_id, 'cart'], data) else: storage_id = browser_id data = storage.get_shop_data([browser_id, 'cart']) if data is None: data = PersistentMapping() return Cart(storage_id, data, request)
def handleSave(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return if self._name == '+': method = PersistentMapping() if self.shipping_methods: shipping_method_id = str( max(int(x) for x in self.shipping_methods.keys()) + 1) else: shipping_method_id = '0' else: shipping_method_id = self._name method = storage.get_shop_data( ['shipping_methods', shipping_method_id]) method.update(data) storage.set_shop_data(['shipping_methods', shipping_method_id], method) if not self.using_plone5(): # redirect if P4 self.redirect_to_shipping_methods_view()
def find_coupon_by_code(code): """Find coupons based on a code entered by the user. Skips coupons that are not active for the current date. Returns None if multiple coupons are found. """ userid = get_current_userid() code = code.lower() coupons = [] for b in get_catalog().unrestrictedSearchResults( portal_type='jazkarta.cart.coupon'): coupon = b._unrestrictedGetObject() # skip if it's not the right code if coupon.code.lower() != code: continue # skip if it's not currently active if coupon.start and coupon.start > datetime.now(): continue if coupon.end and coupon.end < datetime.now(): continue # limit on number of uses per user if coupon.per_user_limit and userid is not None: code_use = storage.get_shop_data( [userid, 'coupons', coupon.UID()], default=0) if code_use >= coupon.per_user_limit: continue coupons.append(coupon) if len(coupons) > 1 or len(coupons) == 0: return None return coupons[0]
def all_shipping_methods(self): return storage.get_shop_data(['shipping_methods'], default={})