def asDict(self): """ """ pvm = IProductVariantsManagement(self.context) if pvm.hasVariants() == True: variant = pvm.getSelectedVariant() or pvm.getDefaultVariant() return IData(variant).asDict() else: # price cm = ICurrencyManagement(self.context) price = IPrices(self.context).getPriceForCustomer() price = cm.priceToString(price) # image image = IImageManagement(self.context).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), "preview") images = [] for temp in IImageManagement(self.context).getImages(): images.append("%s/image_tile" % temp.absolute_url()) return { "article_id" : self.context.getArticleId(), "title" : self.context.Title(), "short_title" : self.context.getShortTitle() or self.context.Title(), "description" : self.context.Description(), "url" : self.context.absolute_url(), "price" : price, "image" : image, "images" : images, "text" : self.context.getText(), "short_text" : self.context.getShortText(), }
def testGetImages(self): """ """ pm = IImageManagement(self.product_1) ids = [p.getId() for p in pm.getImages()] self.assertEqual(ids, ["image_1", "image_2"])
def _data(self): """ """ limit = self.data.count if limit != 0: products = self.context.getRefs("products_products")[:limit] else: products = self.context.getRefs("products_products") result = [] for product in products: mtool = getToolByName(self.context, "portal_membership") if mtool.checkPermission("View", product) == True: # Image image = IImageManagement(product).getMainImage() image_url = image.absolute_url() + "/image_thumb" # Price price = IPrices(product).getPriceGross() cm = ICurrencyManagement(product) price = cm.priceToString(price) result.append({ "title": product.Title(), "url": product.absolute_url(), "image_url": image_url, "price": price, }) return result
def _data(self): """ """ limit = self.data.count if limit != 0: products = self.context.getRefs("products_products")[:limit] else: products = self.context.getRefs("products_products") result = [] for product in products: mtool = getToolByName(self.context, "portal_membership") if mtool.checkPermission("View", product) == True: # Image image = IImageManagement(product).getMainImage() image_url = image.absolute_url() + "/image_thumb" # Price price = IPrices(product).getPriceGross() cm = ICurrencyManagement(product) price = cm.priceToString(price) result.append({ "title" : product.Title(), "url" : product.absolute_url(), "image_url" : image_url, "price" : price, }) return result
def getImageUrls(self): """ """ pm = IImageManagement(self.context) result = [] for image in pm.getImages(): result.append( "%s/image_tile" % image.absolute_url(), ) return result
def getImageUrls(self): """ """ pm = IImageManagement(self.context) result = [] for image in pm.getImages(): result.append({ "small" : "%s/image_thumb" % image.absolute_url(), "large" : "%s/image_large" % image.absolute_url(), }) return result
def getImageUrls(self): """ """ pm = IImageManagement(self.context) result = [] for image in pm.getImages(): result.append({ "small": "%s/image_thumb" % image.absolute_url(), "large": "%s/image_large" % image.absolute_url(), }) return result
def getProducts(self): """ """ selector = getattr(self.context, "thank-you", None) if selector is None: return [] mtool = getToolByName(self.context, "portal_membership") result = [] for product in selector.getRefs(): if mtool.checkPermission("View", product) is None: continue # image pm = IImageManagement(product) image = pm.getMainImage() if image is None: image = None else: image = "%s/image_shop_small" % image.absolute_url() cm = ICurrencyManagement(self.context) price = IPrices(product).getPriceForCustomer() price = cm.priceToString(price) result.append({ "title": product.Title(), "short_title": product.getShortTitle() or product.Title(), "url": product.absolute_url(), "price": price, "image": image, }) return result
def getProducts(self): """ """ selector = getattr(self.context, "thank-you", None) if selector is None: return [] mtool = getToolByName(self.context, "portal_membership") result = [] for product in selector.getRefs(): if mtool.checkPermission("View", product) is None: continue # image pm = IImageManagement(product) image = pm.getMainImage() if image is None: image = None else: image = "%s/image_shop_small" % image.absolute_url() cm = ICurrencyManagement(self.context) price = IPrices(product).getPriceForCustomer() price = cm.priceToString(price) result.append( { "title": product.Title(), "short_title": product.getShortTitle() or product.Title(), "url": product.absolute_url(), "price": price, "image": image, } ) return result
def asDict(self): """ """ pvm = IProductVariantsManagement(self.context) if pvm.hasVariants() == True: variant = pvm.getSelectedVariant() or pvm.getDefaultVariant() return IData(variant).asDict() else: # price cm = ICurrencyManagement(self.context) price = IPrices(self.context).getPriceForCustomer() price = cm.priceToString(price) # image image = IImageManagement(self.context).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), "preview") images = [] for temp in IImageManagement(self.context).getImages(): images.append("%s/image_tile" % temp.absolute_url()) return { "article_id": self.context.getArticleId(), "title": self.context.Title(), "short_title": self.context.getShortTitle() or self.context.Title(), "description": self.context.Description(), "url": self.context.absolute_url(), "price": price, "image": image, "images": images, "text": self.context.getText(), "short_text": self.context.getShortText(), }
def testGetMainImage(self): """ """ pm = IImageManagement(self.product_1) self.assertEqual(pm.getMainImage().getId(), "product_1")
def testHasImage(self): """ """ pm = IImageManagement(self.product_1) self.assertEqual(pm.hasImages(), True)
def getInfo(self): """ """ 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 parent = self.context.aq_inner.aq_parent if ICategory.providedBy(parent): parent_url = parent.absolute_url() elif ICategoriesContainer.providedBy(parent): shop = IShopManagement(self.context).getShop() parent_url = shop.absolute_url() else: parent_url = None batch_infos = { "parent_url": parent_url, "first_url": self._getFirstUrl(batch), "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, "amount": batch.sequence_length, } sorting = self.request.SESSION.get("sorting") f = self.getFormatInfo() products_per_line = f["products_per_line"] line = [] products = [] for index, product in enumerate(batch): # Price cm = ICurrencyManagement(self.context) p = IPrices(product) # Effective price price = p.getPriceForCustomer() price = cm.priceToString(price, symbol="symbol", position="before") # Standard price standard_price = p.getPriceForCustomer(effective=False) standard_price = cm.priceToString(standard_price, symbol="symbol", position="before") # Image image = IImageManagement(product).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), f.get("image_size")) # Text temp = f.get("text") if temp == "description": text = product.getDescription() elif temp == "short_text": text = product.getShortText() elif temp == "text": text = product.getText() else: text = "" # Title temp = f.get("title") if temp == "title": title = product.Title() elif temp == "short_title": title = product.getShortTitle() try: chars = int(f.get("chars")) except (TypeError, ValueError): chars = 0 if (chars != 0) and (len(title) > chars): title = title[:chars] title += "..." # CSS Class if (index + 1) % products_per_line == 0: klass = "last" else: klass = "notlast" line.append({ "title": title, "text": text, "url": product.absolute_url(), "image": image, "for_sale": product.getForSale(), "price": price, "standard_price": standard_price, "class": klass, }) if (index + 1) % products_per_line == 0: products.append(line) line = [] # the rest if len(line) > 0: 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): """ """ 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 parent = self.context.aq_inner.aq_parent if ICategory.providedBy(parent): parent_url = parent.absolute_url() elif ICategoriesContainer.providedBy(parent): shop = IShopManagement(self.context).getShop() parent_url = shop.absolute_url() else: parent_url = None batch_infos = { "parent_url" : parent_url, "first_url" : self._getFirstUrl(batch), "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, "amount" : batch.sequence_length, } sorting = self.request.SESSION.get("sorting") f = self.getFormatInfo() products_per_line = f["products_per_line"] line = [] products = [] for index, product in enumerate(batch): # Price cm = ICurrencyManagement(self.context) p = IPrices(product) # Effective price price = p.getPriceForCustomer() price = cm.priceToString(price, symbol="symbol", position="before") # Standard price standard_price = p.getPriceForCustomer(effective=False) standard_price = cm.priceToString(standard_price, symbol="symbol", position="before") # Image image = IImageManagement(product).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), f.get("image_size")) # Text temp = f.get("text") if temp == "description": text = product.getDescription() elif temp == "short_text": text = product.getShortText() elif temp == "text": text = product.getText() else: text = "" # Title temp = f.get("title") if temp == "title": title = product.Title() elif temp == "short_title": title = product.getShortTitle() try: chars = int(f.get("chars")) except (TypeError, ValueError): chars = 0 if (chars != 0) and (len(title) > chars): title = title[:chars] title += "..." # CSS Class if (index + 1) % products_per_line == 0: klass = "last" else: klass = "notlast" line.append({ "title" : title, "text" : text, "url" : product.absolute_url(), "image" : image, "for_sale" : product.getForSale(), "price" : price, "standard_price" : standard_price, "class" : klass, }) if (index + 1) % products_per_line == 0: products.append(line) line = [] # the rest if len(line) > 0: 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 getSelectors(self): """ """ fi = self.getFormatInfo() products_per_line = fi.get("products_per_line") mtool = getToolByName(self.context, "portal_membership") selectors = [] for selector in self.context.objectValues("ProductSelector"): # ignore thank you selection if selector.getId() != "thank-you": continue products_per_line = products_per_line lines = [] products = [] for index, product in enumerate(selector.getRefs()): if mtool.checkPermission("View", product) is None: continue cm = ICurrencyManagement(self.context) price = IPrices(product).getPriceForCustomer() price = cm.priceToString(price) # image image = IImageManagement(product).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), fi.get("image_size")) t = fi.get("text") if t == "description": text = product.getDescription() elif t == "short_text": text = product.getShortText() elif t == "text": text = product.getText() else: text = "" n = len(selector.getRefs()) if index == n - 1 and n > 1 and products_per_line > 1: klass = "last" else: klass = "notlast" products.append({ "title": product.Title(), "short_title": product.getShortTitle() or product.Title(), "url": product.absolute_url(), "price": price, "image": image, "text": text, "class": klass, }) if (index + 1) % products_per_line == 0: lines.append(products) products = [] # the rest lines.append(products) selectors.append({ "edit_url": "%s/base_edit" % selector.absolute_url(), "show_title": selector.getShowTitle(), "title": selector.Title(), "lines": lines, "products_per_line": products_per_line, "td_width": "%s%%" % (100 / products_per_line), }) return selectors
def asDict(self): """ """ # NOTE: The replacement of "%P" for title is made within ProductVariant # content type. # NOTE: The IImageManagement adapter is doing the check which image is # to display: variant vs. parent # image image = IImageManagement(self.context).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), "preview") images = [] for temp in IImageManagement(self.context).getImages(): images.append("%s/image_tile" % temp.absolute_url()) # title title = self.context.Title() or self.parent.Title() # short title short_title = self.context.getShortTitle() or \ self.parent.getShortTitle() or \ title if "%" in short_title: short_title = short_title.replace("%P", self.parent.getShortTitle()) # article id article_id = self.context.getArticleId() or \ self.parent.getArticleId() if "%" in article_id: article_id = article_id.replace("%P", self.parent.getArticleId()) # Text text = self.context.getText() or self.parent.getText() if "%" in text: text = text.replace("%P", self.parent.getText()) # Short Text short_text = self.context.getShortText() or self.parent.getShortText() if "%" in short_text: short_text = short_text.replace("%P", self.parent.getShortText()) # Description description = self.context.Description() or self.parent.Description() if "%" in description: description = description.replace("%P", self.parent.Description()) # options options = [] for option in self.context.getForProperties(): name, value = option.split(":") options.append({ "name": name, "value": value, }) return { "article_id": article_id, "title": title, "short_title": short_title, "description": description, "url": self.context.absolute_url(), "image": image, "images": images, "text": text, "short_text": short_text, "options": options, }
def getSelectors(self): """ """ mtool = getToolByName(self.context, "portal_membership") catalog = getToolByName(self.context, "portal_catalog") selectors = [] brains = catalog.searchResults( path = "/".join(self.context.getPhysicalPath()), portal_type = "ProductSelector", sort_on = "getObjPositionInParent", ) for selector in brains: # ignore thank you selection if selector.getId == "thank-you": continue selector = selector.getObject() fi = IFormats(selector).getFormats() products_per_line = fi.get("products_per_line") lines = [] products = [] for index, product in enumerate(selector.getRefs()): if mtool.checkPermission("View", product) is None: continue # Price cm = ICurrencyManagement(self.context) p = IPrices(product) # Effective price price = p.getPriceForCustomer() price = cm.priceToString(price, symbol="symbol", position="before", suffix=None) # Standard price standard_price = p.getPriceForCustomer(effective=False) standard_price = cm.priceToString(standard_price, symbol="symbol", position="before", suffix=None) # image image = IImageManagement(product).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), fi.get("image_size")) # Text temp = fi.get("text") if temp == "description": text = product.getDescription() elif temp == "short_text": text = product.getShortText() elif temp == "text": text = product.getText() else: text = "" # Title temp = fi.get("title") if temp == "title": title = product.Title() elif temp == "short_title": title = product.getShortTitle() try: chars = int(fi.get("chars")) except (ValueError, TypeError): chars = 0 if (chars != 0) and (len(title) > chars): title = title[:chars] title += "..." if (index + 1) % products_per_line == 0: klass = "last" else: klass = "notlast" products.append({ "title" : title, "url" : product.absolute_url(), "for_sale" : product.getForSale(), "price" : price, "standard_price" : standard_price, "image" : image, "text" : text, "class" : klass, }) if (index+1) % products_per_line == 0: lines.append(products) products = [] # the rest lines.append(products) selectors.append({ "edit_url" : "%s/base_edit" % selector.absolute_url(), "show_title" : selector.getShowTitle(), "title" : selector.Title(), "lines" : lines, "products_per_line" : products_per_line, "product_height" : fi.get("product_height"), "td_width" : "%s%%" % (100 / products_per_line), }) return selectors
def testGetImages(self): """ """ pm = IImageManagement(self.product_1) self.assertEqual(pm.getImages(), [])
def asDict(self): """ """ # NOTE: The replacement of "%P" for title is made within ProductVariant # content type. # NOTE: The IImageManagement adapter is doing the check which image is # to display: variant vs. parent # image image = IImageManagement(self.context).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), "preview") images = [] for temp in IImageManagement(self.context).getImages(): images.append("%s/image_tile" % temp.absolute_url()) # title title = self.context.Title() or self.parent.Title() # short title short_title = self.context.getShortTitle() or \ self.parent.getShortTitle() or \ title if "%" in short_title: short_title = short_title.replace("%P", self.parent.getShortTitle()) # article id article_id = self.context.getArticleId() or \ self.parent.getArticleId() if "%" in article_id: article_id = article_id.replace("%P", self.parent.getArticleId()) # Text text = self.context.getText() or self.parent.getText() if "%" in text: text = text.replace("%P", self.parent.getText()) # Short Text short_text = self.context.getShortText() or self.parent.getShortText() if "%" in short_text: short_text = short_text.replace("%P", self.parent.getShortText()) # Description description = self.context.Description() or self.parent.Description() if "%" in description: description = description.replace("%P", self.parent.Description()) # options options = [] for option in self.context.getForProperties(): name, value = option.split(":") options.append({ "name" : name, "value" : value, }) return { "article_id" : article_id, "title" : title, "short_title" : short_title, "description" : description, "url" : self.context.absolute_url(), "image" : image, "images" : images, "text" : text, "short_text" : short_text, "options" : options, }
def getProducts(self): """Returns the last products, which are added to the cart. """ cm = ICurrencyManagement(self.context) result = [] for cart_item_id in self.request.SESSION.get("added-to-cart", []): cart = ICartManagement(self.context).getCart() cart_item = IItemManagement(cart).getItem(cart_item_id) if cart_item is None: continue product = cart_item.getProduct() if product is None: continue # Price price = IPrices(product).getPriceForCustomer() # Image product = cart_item.getProduct() image = IImageManagement(product).getMainImage() if image is not None: image_url = image.absolute_url() else: image_url = None # Get selected properties properties = [] pm = IPropertyManagement(product) for selected_property in cart_item.getProperties(): property_price = pm.getPriceForCustomer( selected_property["id"], selected_property["selected_option"]) # Get titles of property and option titles = getTitlesByIds(product, selected_property["id"], selected_property["selected_option"]) if titles is None: continue if (property_price == 0.0) or \ (IProductVariant.providedBy(product)) == True: show_price = False else: show_price = True properties.append({ "id": selected_property["id"], "selected_option": titles["option"], "title": titles["property"], "price": cm.priceToString(property_price), "show_price": show_price, }) price += property_price total = cart_item.getAmount() * price result.append({ "title": product.Title(), "url": product.absolute_url(), "amount": cart_item.getAmount(), "total": cm.priceToString(total), "price": cm.priceToString(price), "image_url": image_url, "properties": properties, }) # Update selected shipping method. TODO: This should be factored out and # made available via a event or similar. It is also used within # ajax/cart/_refresh_cart customer = ICustomerManagement(self.context).getAuthenticatedCustomer() shop = IShopManagement(self.context).getShop() shipping_methods = IShippingMethodManagement(shop).getShippingMethods( check_validity=True) shipping_methods_ids = [sm.getId() for sm in shipping_methods] selected_shipping_method = self.request.get("selected_shipping_method") # Set selected shipping method if selected_shipping_method in shipping_methods_ids: customer.selected_shipping_method = \ safe_unicode(self.request.get("selected_shipping_method")) else: customer.selected_shipping_method = shipping_methods_ids[0] # Reset session if self.request.SESSION.has_key("added-to-cart"): del self.request.SESSION["added-to-cart"] return result
def getProducts(self): """Returns the last products, which are added to the cart. """ cm = ICurrencyManagement(self.context) result = [] for cart_item_id in self.request.SESSION.get("added-to-cart", []): cart = ICartManagement(self.context).getCart() cart_item = IItemManagement(cart).getItem(cart_item_id) if cart_item is None: continue product = cart_item.getProduct() if product is None: continue # Price price = IPrices(product).getPriceForCustomer() # Image product = cart_item.getProduct() image = IImageManagement(product).getMainImage() if image is not None: image_url = image.absolute_url() else: image_url = None # Get selected properties properties = [] pm = IPropertyManagement(product) for selected_property in cart_item.getProperties(): property_price = pm.getPriceForCustomer( selected_property["id"], selected_property["selected_option"]) # Get titles of property and option titles = getTitlesByIds( product, selected_property["id"], selected_property["selected_option"]) if titles is None: continue if (property_price == 0.0) or \ (IProductVariant.providedBy(product)) == True: show_price = False else: show_price = True properties.append({ "id" : selected_property["id"], "selected_option" : titles["option"], "title" : titles["property"], "price" : cm.priceToString(property_price), "show_price" : show_price, }) price += property_price total = cart_item.getAmount() * price result.append({ "title" : product.Title(), "url" : product.absolute_url(), "amount" : cart_item.getAmount(), "total" : cm.priceToString(total), "price" : cm.priceToString(price), "image_url" : image_url, "properties" : properties, }) # Update selected shipping method. TODO: This should be factored out and # made available via a event or similar. It is also used within # ajax/cart/_refresh_cart customer = ICustomerManagement(self.context).getAuthenticatedCustomer() shop = IShopManagement(self.context).getShop() shipping_methods = IShippingMethodManagement(shop).getShippingMethods(check_validity=True) shipping_methods_ids = [sm.getId() for sm in shipping_methods] selected_shipping_method = self.request.get("selected_shipping_method") # Set selected shipping method if selected_shipping_method in shipping_methods_ids: customer.selected_shipping_method = \ safe_unicode(self.request.get("selected_shipping_method")) else: customer.selected_shipping_method = shipping_methods_ids[0] # Reset session if self.request.SESSION.has_key("added-to-cart"): del self.request.SESSION["added-to-cart"] return result
def getSelector(self): """ """ mtool = getToolByName(self.context, "portal_membership") catalog = getToolByName(self.context, "portal_catalog") fi = IFormats(self.context).getFormats() products_per_line = fi.get("products_per_line") lines = [] products = [] for index, product in enumerate(self.context.getRefs()): if mtool.checkPermission("View", product) is None: continue # Price cm = ICurrencyManagement(self.context) p = IPrices(product) # Effective price price = p.getPriceForCustomer() price = cm.priceToString(price, symbol="symbol", position="before", suffix=None) # Standard price standard_price = p.getPriceForCustomer(effective=False) standard_price = cm.priceToString(standard_price, symbol="symbol", position="before", suffix=None) # image image = IImageManagement(product).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), fi.get("image_size")) # Text temp = fi.get("text") if temp == "description": text = product.getDescription() elif temp == "short_text": text = product.getShortText() elif temp == "text": text = product.getText() else: text = "" # Title temp = fi.get("title") if temp == "title": title = product.Title() elif temp == "short_title": title = product.getShortTitle() try: chars = int(fi.get("chars")) except (ValueError, TypeError): chars = 0 if (chars != 0) and (len(title) > chars): title = title[:chars] title += "..." if (index + 1) % products_per_line == 0: klass = "last" else: klass = "notlast" products.append({ "title": title, "url": product.absolute_url(), "for_sale": product.getForSale(), "price": price, "standard_price": standard_price, "image": image, "text": text, "class": klass, }) if (index + 1) % products_per_line == 0: lines.append(products) products = [] # the rest lines.append(products) return { "edit_url": "%s/base_edit" % self.context.absolute_url(), "show_title": self.context.getShowTitle(), "title": self.context.Title(), "lines": lines, "products_per_line": products_per_line, "product_height": fi.get("product_height"), "td_width": "%s%%" % (100 / products_per_line), }
def getProducts(self): """ """ catalog = getToolByName(self.context, "portal_catalog") brains = catalog.searchResults( portal_type = "Product" ) result = [] line = [ "Title", "Url", "Price", "Short Title", "Article ID", "Description", "Weight", "Text", "Short Text", "Image",] line = ['"%s"' % field for field in line] line = "\t".join(line) result.append(line) for brain in brains: product = brain.getObject() # Price price = IPrices(product).getPriceGross() # This is crap and has to be optimized. text = product.getText() text = text.replace("\n", "") text = text.replace("\r", "") text = text.replace("\t", "") short_text = product.getShortText() short_text = short_text.replace("\n", "") short_text = short_text.replace("\r", "") short_text = short_text.replace("\t", "") description = product.Description() description = description.replace("\n", "") description = description.replace("\r", "") description = description.replace("\t", "") line = [ product.Title(), product.absolute_url(), price, product.getShortTitle(), product.getArticleId(), description, product.getWeight(), text, short_text, ] # Images im = IImageManagement(product) for image in im.getImages(): if image.absolute_url() == product.absolute_url(): url = image.absolute_url() + "/image" else: url = image.absolute_url() line.append(url) line = ['"%s"' % field for field in line] line = "\t".join(line) result.append(line) self.request.response.setHeader('Content-type', 'text/plain') self.request.response.setHeader( 'Content-disposition', 'attachment; filename=%s' % "products.txt" ) return "\r\n".join(result)
def getSelectors(self): """ """ fi = self.getFormatInfo() products_per_line = fi.get("products_per_line") mtool = getToolByName(self.context, "portal_membership") selectors = [] for selector in self.context.objectValues("ProductSelector"): # ignore thank you selection if selector.getId() != "thank-you": continue products_per_line = products_per_line lines = [] products = [] for index, product in enumerate(selector.getRefs()): if mtool.checkPermission("View", product) is None: continue cm = ICurrencyManagement(self.context) price = IPrices(product).getPriceForCustomer() price = cm.priceToString(price) # image image = IImageManagement(product).getMainImage() if image is not None: image = "%s/image_%s" % (image.absolute_url(), fi.get("image_size")) t = fi.get("text") if t == "description": text = product.getDescription() elif t == "short_text": text = product.getShortText() elif t == "text": text = product.getText() else: text = "" n = len(selector.getRefs()) if index == n - 1 and n > 1 and products_per_line > 1: klass = "last" else: klass = "notlast" products.append( { "title": product.Title(), "short_title": product.getShortTitle() or product.Title(), "url": product.absolute_url(), "price": price, "image": image, "text": text, "class": klass, } ) if (index + 1) % products_per_line == 0: lines.append(products) products = [] # the rest lines.append(products) selectors.append( { "edit_url": "%s/base_edit" % selector.absolute_url(), "show_title": selector.getShowTitle(), "title": selector.Title(), "lines": lines, "products_per_line": products_per_line, "td_width": "%s%%" % (100 / products_per_line), } ) return selectors
def getContent(self): """ """ data = {} # Title if self.context.getOverwriteTitle() == True: title = self.context.Title() else: title = self.object.Title() # Text if self.context.getOverwriteText() == True: text = self.context.getText() else: text = self.object.getText() # Image if len(self.context.getImage()) != 0: image = self.context else: image = IImageManagement(self.object).getMainImage() if image is not None: image_url = image.absolute_url() else: image_url = None # Price if IProduct.providedBy(self.object) == True: cm = ICurrencyManagement(self.object) p = IPrices(self.object) # Effective price price = p.getPriceForCustomer() price = cm.priceToString(price, symbol="symbol", position="before") # Standard price standard_price = p.getPriceForCustomer(effective=False) standard_price = cm.priceToString(standard_price, symbol="symbol", position="before") for_sale = self.object.getForSale() else: for_sale = False standard_price = "0.0" price = "0.0" data.update({ "portal_type": self.object.getPortalTypeName(), "id": self.object.getId(), "url": self.object.absolute_url(), "title": title, "description": self.object.Description(), "text": text, "image_url": image_url, "price": price, "standard_price": standard_price, "for_sale": for_sale, "image_size": self.context.getImageSize(), }) return data
def getProducts(self): """ """ catalog = getToolByName(self.context, "portal_catalog") brains = catalog.searchResults(portal_type="Product") result = [] line = [ "Title", "Url", "Price", "Short Title", "Article ID", "Description", "Weight", "Text", "Short Text", "Image", ] line = ['"%s"' % field for field in line] line = "\t".join(line) result.append(line) for brain in brains: product = brain.getObject() # Price price = IPrices(product).getPriceGross() # This is crap and has to be optimized. text = product.getText() text = text.replace("\n", "") text = text.replace("\r", "") text = text.replace("\t", "") short_text = product.getShortText() short_text = short_text.replace("\n", "") short_text = short_text.replace("\r", "") short_text = short_text.replace("\t", "") description = product.Description() description = description.replace("\n", "") description = description.replace("\r", "") description = description.replace("\t", "") line = [ product.Title(), product.absolute_url(), price, product.getShortTitle(), product.getArticleId(), description, product.getWeight(), text, short_text, ] # Images im = IImageManagement(product) for image in im.getImages(): if image.absolute_url() == product.absolute_url(): url = image.absolute_url() + "/image" else: url = image.absolute_url() line.append(url) line = ['"%s"' % field for field in line] line = "\t".join(line) result.append(line) self.request.response.setHeader('Content-type', 'text/plain') self.request.response.setHeader( 'Content-disposition', 'attachment; filename=%s' % "products.txt") return "\r\n".join(result)
def getContent(self): """ """ data = {} # Title if self.context.getOverwriteTitle() == True: title = self.context.Title() else: title = self.object.Title() # Text if self.context.getOverwriteText() == True: text = self.context.getText() else: text = self.object.getText() # Image if len(self.context.getImage()) != 0: image = self.context else: image = IImageManagement(self.object).getMainImage() if image is not None: image_url = image.absolute_url() else: image_url = None # Price if IProduct.providedBy(self.object) == True: cm = ICurrencyManagement(self.object) p = IPrices(self.object) # Effective price price = p.getPriceForCustomer() price = cm.priceToString(price, symbol="symbol", position="before") # Standard price standard_price = p.getPriceForCustomer(effective=False) standard_price = cm.priceToString( standard_price, symbol="symbol", position="before") for_sale = self.object.getForSale() else: for_sale = False standard_price = "0.0" price = "0.0" data.update({ "portal_type" : self.object.getPortalTypeName(), "id" : self.object.getId(), "url" : self.object.absolute_url(), "title" : title, "description" : self.object.Description(), "text" : text, "image_url" : image_url, "price" : price, "standard_price" : standard_price, "for_sale" : for_sale, "image_size" : self.context.getImageSize(), }) return data