def related_items(self): props = getToolByName(self.context, 'portal_properties').pcommerce_properties columns = int(props.getProperty('columns', 3)) width = int(props.getProperty('thumb_width', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' items = [] i = 0 for item in self.product.getRelatedItems(): if IProduct.providedBy(item): col = i % columns + 1 i += 1 adapter = IPricing(item) image = None if item.getImage(): image = {'caption': item.getImageCaption(), 'thumb': '%s/%s' % (item.absolute_url(), width)} items.append({'uid': item.UID(), 'class': 'col%s' % col, 'title': item.Title(), 'description': item.Description(), 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': item.absolute_url()}) return items
def products(self): catalog = getToolByName(self.context, "portal_catalog") props = getToolByName(self.context, "portal_properties").pcommerce_properties columns = int(props.getProperty("new_columns", 2)) no = int(props.getProperty("no_new_products", 2)) width = int(props.getProperty("thumb_width_new_products", 0)) width = width and "image/thumb?width=%s" % width or "image_thumb" results = list(catalog(object_provides=IProduct.__identifier__, new=True)) if not results: return None items = [] i = 0 while len(items) < no and len(results): item = results.pop(random.randrange(len(results))) object = item.getObject() col = i % columns + 1 i += 1 adapter = IPricing(object) image = None if object.getImage(): image = {"caption": object.getImageCaption(), "thumb": "%s/%s" % (item.getURL(), width)} item = { "uid": item.UID, "class": "col%s" % col, "title": item.Title, "description": item.Description, "price": CurrencyAware(adapter.getPrice()), "base_price": CurrencyAware(adapter.getBasePrice()), "offer": adapter.getPrice() < adapter.getBasePrice(), "image": image, "url": item.getURL(), } items.append(item) return items
def products(self): catalog = getToolByName(self.context, 'portal_catalog') props = getToolByName(self.context, 'portal_properties').pcommerce_properties columns = int(props.getProperty('hot_columns', 3)) no = int(props.getProperty('no_hot_products', 6)) width = int(props.getProperty('thumb_width_hot_products', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' results = list(catalog(object_provides=IProduct.__identifier__, hot=True)) if not results: return None items = [] i = 0 while len(items) < no and len(results): item = results.pop(random.randrange(len(results))) object = item.getObject() col = i % columns + 1 i += 1 adapter = IPricing(object) image = None if object.getImage(): image = {'caption': object.getImageCaption(), 'thumb': '%s/%s' % (item.getURL(), width)} item = {'uid': item.UID, 'class': 'col%s' % col, 'title': item.Title, 'description': item.Description, 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': item.getURL()} items.append(item) return items
def variation_items(self): props = getToolByName(self.context, 'portal_properties').pcommerce_properties columns = int(props.getProperty('columns', 3)) width = int(props.getProperty('thumb_width', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' items = [] i = 0 catalog = getToolByName(self.product, 'portal_catalog') variations = catalog(object_provides=IVariation.__identifier__, path={'query': '/'.join(self.product.getPhysicalPath())}) for variation in variations: col = i % columns + 1 i += 1 variation = variation.getObject() adapter = IPricing(self.product) if variation.UID() != self.context.UID(): image = None if variation.getImage(): image = {'caption': variation.getImageCaption(), 'thumb': '%s/%s' % (variation.absolute_url(), width)} items.append({'uid': variation.UID(), 'class': 'col%s' % col, 'title': '%s: %s' % (variation.getType(), variation.Title()), 'description': variation.Description() or self.product.Description(), 'price': CurrencyAware(adapter.getPrice([variation, ])), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice([variation, ]) < adapter.getBasePrice(), 'image': image, 'url': variation.absolute_url()}) return items
def batch(self): catalog = getToolByName(self.context, 'portal_catalog') portal_properties = getToolByName(self.context, 'portal_properties') use_view_action = portal_properties.site_properties.getProperty( 'typesUseViewActionInListings', ()) props = portal_properties.pcommerce_properties columns = int(props.getProperty('columns', 3)) width = int(props.getProperty('thumb_width', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' results = catalog(object_provides=IProduct.__identifier__, path={ 'query': '/'.join(self.context.getPhysicalPath()), 'depth': 1 }, sort_on='getObjPositionInParent') items = [] i = 0 start = (self.page - 1) * (columns * 5) end = start + columns * 5 for item in results: url = item.getURL() if item.portal_type in use_view_action: url += '/view' if start <= i < end: object = item.getObject() col = i % columns + 1 adapter = IPricing(object) image = None if object.getImage(): image = { 'caption': object.getImageCaption(), 'thumb': '%s/%s' % (item.getURL(), width) } item = { 'uid': item.UID, 'class': 'col%s' % col, 'title': item.Title, 'description': item.Description, 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': url } else: item = { 'uid': item.UID, 'title': item.Title, 'description': item.Description, 'url': url } i += 1 items.append(item) return Batch(items, columns * 5, self.page, 5)
def related_items(self): portal_properties = getToolByName(self.context, 'portal_properties') use_view_action = portal_properties.site_properties.getProperty( 'typesUseViewActionInListings', ()) props = portal_properties.pcommerce_properties columns = int(props.getProperty('columns', 3)) width = int(props.getProperty('thumb_width', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' items = [] i = 0 for item in self.product.getRelatedItems(): if IProduct.providedBy(item): col = i % columns + 1 i += 1 adapter = IPricing(item) image = None if item.getImage(): image = { 'caption': item.getImageCaption(), 'thumb': '%s/%s' % (item.absolute_url(), width) } url = item.getURL() if item.portal_type in use_view_action: url += '/view' items.append({ 'uid': item.UID(), 'class': 'col%s' % col, 'title': item.Title(), 'description': item.Description(), 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': url }) return items
def batch(self): catalog = getToolByName(self.context, 'portal_catalog') portal_properties = getToolByName(self.context, 'portal_properties') use_view_action = portal_properties.site_properties.getProperty('typesUseViewActionInListings', ()) props = portal_properties.pcommerce_properties columns = int(props.getProperty('columns', 3)) width = int(props.getProperty('thumb_width', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' results = catalog(object_provides=IProduct.__identifier__, path={'query': '/'.join(self.context.getPhysicalPath()), 'depth': 1}, sort_on='getObjPositionInParent') items = [] i = 0 start = (self.page-1) * (columns * 5) end = start + columns * 5 for item in results: url = item.getURL() if item.portal_type in use_view_action: url += '/view' if start <= i < end: object = item.getObject() col = i % columns + 1 adapter = IPricing(object) image = None if object.getImage(): image = {'caption': object.getImageCaption(), 'thumb': '%s/%s' % (item.getURL(), width)} item = {'uid': item.UID, 'class': 'col%s' % col, 'title': item.Title, 'description': item.Description, 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': url} else: item = {'uid': item.UID, 'title': item.Title, 'description': item.Description, 'url': url} i += 1 items.append(item) return Batch(items, columns * 5, self.page, 5)
def products(self): catalog = getToolByName(self.context, 'portal_catalog') portal_properties = getToolByName(self.context, 'portal_properties') use_view_action = portal_properties.site_properties.getProperty( 'typesUseViewActionInListings', ()) props = portal_properties.pcommerce_properties columns = int(props.getProperty('hot_columns', 3)) no = int(props.getProperty('no_hot_products', 6)) width = int(props.getProperty('thumb_width_hot_products', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' results = list( catalog(object_provides=IProduct.__identifier__, hot=True)) if not results: return None items = [] i = 0 while len(items) < no and len(results): item = results.pop(random.randrange(len(results))) object = item.getObject() col = i % columns + 1 i += 1 adapter = IPricing(object) image = None if object.getImage(): image = { 'caption': object.getImageCaption(), 'thumb': '%s/%s' % (item.getURL(), width) } url = item.getURL() if item.portal_type in use_view_action: url += '/view' item = { 'uid': item.UID, 'class': 'col%s' % col, 'title': item.Title, 'description': item.Description, 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': url } items.append(item) return items