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 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('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 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 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 variations(self): catalog = getToolByName(self.context, 'portal_catalog') results = catalog(object_provides=IVariation.__identifier__, path={'query': '/'.join(self.product.getPhysicalPath())}) variations = {} for variation in results: if not variations.has_key(variation.getType): variations[variation.getType] = [] if not variation.getAddPrice: price_adapter = IPricing(variation.getObject()) variations[variation.getType].append({ 'uid': variation.UID, 'name': variation.Title, 'price': CurrencyAware(IPricing(self.product).getPrice([variation.getObject()])), 'price_raw': IPricing(self.product).getPrice([variation.getObject()]), 'base_price': CurrencyAware(variation.getAddPrice and self.base_price.getValue() + float(variation.getPrice) or price_adapter.getBasePrice()), 'base_price_raw':variation.getAddPrice and self.base_price.getValue() + float(variation.getPrice) or price_adapter.getBasePrice(), 'add_price': variation.getAddPrice and CurrencyAware(float(variation.getPrice)) or None, 'add_price_raw': variation.getAddPrice and float(variation.getPrice) or None, }) return [{'name': type[0], 'variations': type[1]} for type in variations.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 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
def price(self): import logging v_uid = None product = aq_inner(self.context) if IVariation.providedBy(product): product = aq_parent(product) v_uid = self.context.UID() v_uids = self.request.get('v', '') v_uids = v_uids.split(',') v_uids = [uid for uid in v_uids if uid != ''] if not len(v_uids) and v_uid is not None: v_uids = [ v_uid, ] catalog = getToolByName(self.context, 'uid_catalog') variations = catalog(object_provides=IVariation.__identifier__, UID=v_uids) variations = [variation.getObject() for variation in variations] price = IPricing(product).getPrice(variations) return CurrencyAware(price)
def base_price(self): if IVariation.providedBy(self.context): return CurrencyAware(IPricing(self.product).getBasePrice([aq_inner(self.context),])) return CurrencyAware(IPricing(self.product).getBasePrice())