def __call__(self): # check if order was created by authenticated user user = plone.api.user.get_current() if user.getId() != self.order['creator']: raise Unauthorized # disable diazo theming if ajax call if '_' in self.request.form: self.request.response.setHeader('X-Theme-Disabled', 'True') for booking in self.order_data.bookings: add_item_to_cart( request=self.request, uid=booking.attrs['buyable_uid'], count=booking.attrs['buyable_count']) return super(AddOrderItemsToCartView, self).__call__()
def add_to_cart(self, path, quantity=1): # Attempt to find product relative to current object, fall back to root # of site. context = self.context while IBrowserView.providedBy(context): context = aq_parent(context) try: obj = context.restrictedTraverse(path) except (AttributeError, KeyError): if not path.startswith('/'): path = '/' + path obj = api.content.get(path=path) if obj: add_item_to_cart( request=self.request, uid=obj.UID(), count=quantity )