def product_group(self): uid = self.request.get('uid') if not uid: raise ValueError(u'No execution context UID') obj = get_object_by_uid(self.context, uid) if not obj: raise ValueError(u'Execution context object not found by UID') if IProductGroup.providedBy(obj): return obj if IVariant.providedBy(obj): return aq_parent(obj) raise ValueError(u'Object not implements IProductGroup or IVariant')
def cart_items(self, items): ret = list() sm = getSecurityManager() for uid, count, comment in items: try: obj = api.content.get(UID=uid) except ValueError: remove_item_from_cart(self.request, uid) continue if not sm.checkPermission(permissions.BuyItems, obj): remove_item_from_cart(self.request, uid) continue buyable_period = queryAdapter(obj, IBuyablePeriod) if buyable_period: now = datetime.now() effective = buyable_period.effective if effective and now < effective: remove_item_from_cart(self.request, uid) continue expires = buyable_period.expires if expires and now > expires: remove_item_from_cart(self.request, uid) continue data = get_item_data_provider(obj) title = data.title discount_net = data.discount_net(count) price = (Decimal(str(data.net)) - discount_net) * count if data.display_gross: price = price + price / Decimal(100) * Decimal(str(data.vat)) url = obj.absolute_url() description = obj.Description() comment_required = data.comment_required quantity_unit_float = data.quantity_unit_float quantity_unit = translate(data.quantity_unit, context=self.request) preview_image_url = get_item_preview(obj).url if IVariant.providedBy(obj) and get_item_preview(obj).url == '': preview_image_url = get_item_preview(aq_parent(obj)).url item_state = get_item_state(obj, self.request) no_longer_available = not item_state.validate_count(count) alert = item_state.alert(count) item = self.item( uid, title, count, price, url, comment, description, comment_required, quantity_unit_float, quantity_unit, preview_image_url, no_longer_available, alert) ret.append(item) return ret
def can_enable(self): return not self.aspect_schema.providedBy(self.context) and IVariant.providedBy( self.context )
def can_enable(self): return not self.aspect_schema.providedBy(self.context) \ and IVariant.providedBy(self.context)