class TestFormatterInfos(EasyShopTestCase): """ """ def afterSetUp(self): """ """ super(TestFormatterInfos, self).afterSetUp() self.fi_1 = IFormats(self.shop) self.fi_2 = IFormats(self.shop.categories.category_1) # TODO: test for setFormats # TODO: test for effective formats def testGetFormats(self): """ """ fi_1 = self.fi_1.getFormats() fi_2 = self.fi_2.getFormats() self.assertEqual(fi_1["lines_per_page"], 1) self.assertEqual(fi_1["products_per_line"], 2) self.assertEqual(fi_1["image_size"], "mini") self.assertEqual(fi_1["text"], "short_text") self.assertEqual(fi_1["product_height"], 0) self.assertEqual(fi_2["lines_per_page"], 1) self.assertEqual(fi_2["products_per_line"], 2) self.assertEqual(fi_2["image_size"], "mini") self.assertEqual(fi_2["text"], "short_text") self.assertEqual(fi_2["product_height"], 0)
def saveFormatter(self): """ """ fi = IFormats(self.context) f = fi.setFormats(self.request) referer = self.request.get("HTTP_REFERER", "") if referer.find("thank-you") != -1: url = referer else: url = self.context.absolute_url() self.request.response.redirect(url)
def getFormats(self, effective=True): """Returns either the first object with formats enabled or the shop content object """ object = self.context if effective == True: while IShop.providedBy(object) == False: try: fi = IFormats(object) except TypeError: pass else: if fi.formats["enabled"] == True: break if base_hasattr(object, "getParentCategory") and \ object.getParentCategory() is not None: object = object.getParentCategory() else: object = object.aq_inner.aq_parent fi = IFormats(object) try: lines_per_page = int(fi.formats["lines_per_page"]) except (TypeError, ValueError): lines_per_page = 1 try: products_per_line = int(fi.formats["products_per_line"]) except (TypeError, ValueError): products_per_line = 2 try: product_height = int(fi.formats["product_height"]) except (TypeError, ValueError): product_height = 0 return { "enabled": fi.formats["enabled"], "lines_per_page": lines_per_page, "products_per_line": products_per_line, "product_height": product_height, "image_size": fi.formats["image_size"], "text": fi.formats["text"], "title": fi.formats["title"], "chars": fi.formats["chars"], }
def saveFormatter(self, portlethash): """ """ fi = IFormats(self.context) fi.setFormats(self.request.form) kss_core = self.getCommandSet("core") kss_zope = self.getCommandSet("zope") kss_plone = self.getCommandSet("plone") layout = self.request.form.get("layout") if layout == "categories-view": kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("categories-list"), manager="easyshop.categories-manager", name="easyshop.categories-viewlet") elif layout == "products-view": kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"), manager="easyshop.products-manager", name="easyshop.products-viewlet") elif layout == "product-selector-view": kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"), manager="easyshop.product-selector-manager", name="easyshop.product-selector-viewlet") # For easyshop.easyarticle elif layout == "overview": kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"), manager="easyshop.products-manager", name="easyshop.products-viewlet") # For easyshop.easyarticle elif layout == "ps-view": kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"), manager="easyshop.ps-manager", name="easyshop.ps-viewlet") # else: # kss_zope.refreshViewlet(kss_core.getHtmlIdSelector("products-list"), # manager="easyshop.search-results-manager", # name="easyshop.search-results-viewlet") kss_plone.refreshPortlet(portlethash)
def getFormatInfo(self): """ """ return IFormats(self.context).getFormats()
def afterSetUp(self): """ """ super(TestFormatterInfos, self).afterSetUp() self.fi_1 = IFormats(self.shop) self.fi_2 = IFormats(self.shop.categories.category_1)
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 getFormatInfo(self): """ """ fi = IFormats(self.context) return fi.getFormats(effective=False)
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 getFormatInfo(self): """ """ # Could be overwritten to provide fixed category views. return IFormats(self.context).getFormats()
def getFormats(self): """ """ # Could be overwritten to provide fixed category views. # s. DemmelhuberShop return IFormats(self.context).getFormats()