def getBuyLabel(self): """ """ pm = IPropertyManagement(self.context) if len(pm.getProperties()) > 0: return "Buy Product" else: return "Add to Cart"
def showSelectPropertiesView(self): """Returns True if the select properties view is meant to be shown. """ pm = IPropertyManagement(self.context) if len(pm.getProperties()) > 0: return True return False
def testGetProperties(self): """Get properties from product. Note: product 1 is in group 1 group 1 has color property too but products properties are choosen Note that properties are taken from group and product """ pm = IPropertyManagement(self.shop.products.product_1) ids = [p.getId() for p in pm.getProperties()] self.assertEqual(ids, ["color", "material", "quality", "size"])
def getProperties(self): """ """ u = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) selected_properties = {} for name, value in self.request.form.items(): if name.startswith("property"): selected_properties[name[9:]] = value pm = IPropertyManagement(self.context) result = [] for property in pm.getProperties(): options = [] for option in property.getOptions(): # generate value string name = option["name"] price = option["price"] if price != "": price = u.stringToFloat(price) price = cm.priceToString(price, "long", "after") content = "%s %s" % (name, price) else: content = name # is option selected? selected = name == selected_properties.get( property.getId(), False) options.append({ "content": content, "value": name, "selected": selected, }) result.append({ "id": property.getId(), "title": property.Title(), "options": options, }) return result
def getProperties(self): """ """ u = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) selected_properties = {} for name, value in self.request.form.items(): if name.startswith("property"): selected_properties[name[9:]] = value pm = IPropertyManagement(self.context) result = [] for property in pm.getProperties(): options = [] for option in property.getOptions(): # generate value string name = option["name"] price = option["price"] if price != "": price = u.stringToFloat(price) price = cm.priceToString(price, "long", "after") content = "%s %s" % (name, price) else: content = name # is option selected? selected = name == selected_properties.get(property.getId(), False) options.append({ "content" : content, "value" : name, "selected" : selected, }) result.append({ "id" : property.getId(), "title" : property.Title(), "options" : options, }) return result
def getInfo(self): """ """ products_per_line = self.getFormatInfo().get("products_per_line") batch = self._getBatch() # This optimized for speed, as we need _getBatch here anyway. # So there is no need of an extra method call within the page # template to get informations we have here already. Same is true # for format infos, see below batch_infos = { "previous_url": self._getPreviousUrl(batch), "previous": batch.previous, "next_url": self._getNextUrl(batch), "next": batch.next, "last_url": self._getLastUrl(batch), "navigation_list": batch.navlist, "number_of_pages": batch.numpages, "page_number": batch.pagenumber, } sorting = self.request.get("sorting", None) f = self.getFormatInfo() line = [] products = [] for index, product in enumerate(batch): cm = ICurrencyManagement(self.context) price = IPrices(product).getPriceForCustomer() price = cm.priceToString(price, symbol="symbol", position="before") # photo image = IPhotoManagement(product).getMainPhoto() if image is not None: image = "%s/image_%s" % (image.absolute_url(), f.get("image_size")) # properties view property_manager = IPropertyManagement(product) if len(property_manager.getProperties()) > 0: showSelectPropertiesView = True else: showSelectPropertiesView = False t = f.get("text") if t == "description": text = product.getDescription() elif t == "short_text": text = product.getShortText() elif t == "text": text = product.getText() else: text = "" if (index + 1) % products_per_line == 0 and products_per_line > 1: klass = "last" else: klass = "notlast" line.append({ "title": product.Title(), "short_title": product.getShortTitle() or product.Title(), "text": text, "url": "%s?sorting=%s" % (product.absolute_url(), sorting), "image": image, "price": price, "showSelectPropertiesView": showSelectPropertiesView, "class": klass, }) if (index + 1) % products_per_line == 0: products.append(line) line = [] # the rest products.append(line) # Return format infos here, because we need it anyway in this method # This is for speed reasons. See above. return { "products": products, "batch_info": batch_infos, "format_info": f, }
def getInfo(self): """ """ products_per_line = self.getFormatInfo().get("products_per_line") batch = self._getBatch() # This optimized for speed, as we need _getBatch here anyway. # So there is no need of an extra method call within the page # template to get informations we have here already. Same is true # for format infos, see below batch_infos = { "previous_url" : self._getPreviousUrl(batch), "previous" : batch.previous, "next_url" : self._getNextUrl(batch), "next" : batch.next, "last_url" : self._getLastUrl(batch), "navigation_list" : batch.navlist, "number_of_pages" : batch.numpages, "page_number" : batch.pagenumber, } sorting = self.request.get("sorting", None) f = self.getFormatInfo() line = [] products = [] for index, product in enumerate(batch): cm = ICurrencyManagement(self.context) price = IPrices(product).getPriceForCustomer() price = cm.priceToString(price, symbol="symbol", position="before") # photo image = IPhotoManagement(product).getMainPhoto() if image is not None: image = "%s/image_%s" % (image.absolute_url(), f.get("image_size")) # properties view property_manager = IPropertyManagement(product) if len(property_manager.getProperties()) > 0: showSelectPropertiesView = True else: showSelectPropertiesView = False t = f.get("text") if t == "description": text = product.getDescription() elif t == "short_text": text = product.getShortText() elif t == "text": text = product.getText() else: text = "" if (index + 1) % products_per_line == 0 and products_per_line > 1: klass = "last" else: klass = "notlast" line.append({ "title" : product.Title(), "short_title" : product.getShortTitle() or product.Title(), "text" : text, "url" : "%s?sorting=%s" % (product.absolute_url(), sorting), "image" : image, "price" : price, "showSelectPropertiesView" : showSelectPropertiesView, "class" : klass, }) if (index + 1) % products_per_line == 0: products.append(line) line = [] # the rest products.append(line) # Return format infos here, because we need it anyway in this method # This is for speed reasons. See above. return { "products" : products, "batch_info" : batch_infos, "format_info" : f, }