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 getPaymentPrices(self): """ """ shop = IShopManagement(self.context).getShop() pp = IPaymentPriceManagement(shop) cm = ICurrencyManagement(shop) result = [] for payment_price in pp.getPaymentPrices(): price = cm.priceToString(payment_price.getPrice()) result.append( { "id": payment_price.getId(), "title": payment_price.Title(), "price": price, "url": payment_price.absolute_url(), "up_url": "%s/es_folder_position?position=up&id=%s" % (self.context.absolute_url(), payment_price.getId()), "down_url": "%s/es_folder_position?position=down&id=%s" % (self.context.absolute_url(), payment_price.getId()), "amount_of_criteria": self._getAmountOfCriteria(payment_price.getId()), } ) return result
def _getPropertiesForConfiguration(self, cart_item): """ """ u = getUtility(INumberConverter) cm = ICurrencyManagement(self.context) # Store all selected options for lookup below selected_options = {} for property in cart_item.getProperties(): selected_options[property["id"]] = property["selected_option"] product = cart_item.getProduct() pm = IPropertyManagement(product) result = [] for property in pm.getProperties(): # Only properties with at least one option are displayed. if len(property.getOptions()) == 0: continue options = [] for option in property.getOptions(): # generate value string option_id = option["id"] option_name = option["name"] option_price = option["price"] if option_price != "0.0": option_price = u.stringToFloat(option_price) option_price = cm.priceToString(option_price, "long", "after", suffix=None) content = "%s %s" % (option_name, option_price) else: content = option_name # is option selected? selected_option = selected_options.get(property.getId(), "") selected = option_id == selected_option options.append({ "id": option_id, "title": content, "selected": selected, }) result.append({ "id": "property_%s_%s" % (product.UID(), property.getId()), "title": property.Title(), "options": options, }) return result
def getDiscounts(self): """ """ shop = IShopManagement(self.context).getShop() dm = IDiscountsManagement(shop) cm = ICurrencyManagement(shop) result = [] for discount in dm.getDiscounts(): value = cm.priceToString(discount.getValue()) result.append({ "id": discount.getId(), "title": discount.Title(), "description": discount.Description(), "value": value, "url": discount.absolute_url(), "up_url": "%s/es_folder_position?position=up&id=%s" % (self.context.absolute_url(), discount.getId()), "down_url": "%s/es_folder_position?position=down&id=%s" % (self.context.absolute_url(), discount.getId()), "amount_of_criteria": self._getAmountOfCriteria(discount.getId()) }) return result
def getPaymentValues(self): """ """ nc = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) price_net = cm.priceToString(self.context.getPaymentPriceNet(), suffix=None) price_gross = cm.priceToString(self.context.getPaymentPriceGross(), suffix=None) tax_rate = nc.floatToTaxString(self.context.getPaymentTaxRate()) tax = cm.priceToString(self.context.getPaymentTax(), suffix=None) transtool = getToolByName(self.context, 'translation_service') return { "display": self.context.getPaymentPriceGross() != 0, "price_net": price_net, "price_gross": price_gross, "tax_rate": tax_rate, "tax": tax, "title": transtool.utranslate("plone", u"Cash on Delivery").encode('utf-8') }
def getShippingPrices(self): """ """ shop = IShopManagement(self.context).getShop() sm = IShippingPriceManagement(shop) cm = ICurrencyManagement(shop) result = [] for shipping_price in sm.getShippingPrices(): price = cm.priceToString(shipping_price.getPrice()) result.append({ "id": shipping_price.getId(), "title": shipping_price.Title(), "description": shipping_price.Description(), "price": price, "url": shipping_price.absolute_url(), "up_url": "%s/es_folder_position?position=up&id=%s" % (self.context.absolute_url(), shipping_price.getId()), "down_url": "%s/es_folder_position?position=down&id=%s" % (self.context.absolute_url(), shipping_price.getId()), "amount_of_criteria": self._getAmountOfCriteria(shipping_price.getId()) }) 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 getRotatingObjects(self): """ """ shop = IShopManagement(self.context).getShop() cm = ICurrencyManagement(shop) catalog = getToolByName(self.context, "portal_catalog") path = self.data.path.encode("utf-8") obj = self.context.restrictedTraverse(path) result = [] for item in IRotating(obj).getItems(self.data.limit): brains = catalog.searchResults(UID = item["uid"]) product = brains[0].getObject() standard_price = IPrices(product).getPriceForCustomer(effective=False) price = IPrices(product).getPriceForCustomer() item["for_sale"] = product.getForSale() item["standard_price"] = cm.priceToString(standard_price) item["price"] = cm.priceToString(price) result.append(item) 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 getDiscounts(self): """ """ return [] cm = ICurrencyManagement(self.context) cart = self._getCart() if cart is None: return [] discounts = [] for cart_item in IItemManagement(cart).getItems(): discount = IDiscountsCalculation(cart_item).getDiscount() if discount is not None: value = getMultiAdapter( (discount, cart_item)).getPriceForCustomer() discounts.append({ "title": discount.Title(), "value": cm.priceToString(value, prefix="-", suffix=None), }) return discounts
def getTotalTax(self): """ """ cart = self._getCart() total = ITaxes(cart).getTaxForCustomer() cm = ICurrencyManagement(self.context) return cm.priceToString(total)
def getPriceForCustomer(self): """ """ p = IPrices(self.context) price = p.getPriceForCustomer() cm = ICurrencyManagement(self.context) return cm.priceToString(price, suffix=None)
def _getPropertiesForConfiguration(self): """ """ u = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) selected_options = {} for name, value in self.request.items(): if name.startswith("property"): selected_options[name[42:]] = value pm = IPropertyManagement(self.context) result = [] for property in pm.getProperties(): # Only properties with at least one option are displayed. if len(property.getOptions()) == 0: continue # Preset with select option options = [{ "id" : "select", "title" : _(u"Select"), "selected" : False, }] for option in property.getOptions(): # generate value string option_id = option["id"] option_name = option["name"] option_price = option["price"] if option_price != "0.0": option_price = u.stringToFloat(option_price) option_price = cm.priceToString(option_price, "long", "after", suffix=None) content = "%s %s" % (option_name, option_price) else: content = option_name # is option selected? selected_option = selected_options.get(property.getId(), "") selected = option_id == selected_option options.append({ "id" : option_id, "title" : content, "selected" : selected, }) result.append({ "id" : "property_%s_%s" % (self.context.UID(), property.getId()), "title" : property.Title(), "options" : options, }) return result
def getValue(self): """ """ if self.context.getType() == "absolute": cm = ICurrencyManagement(IShopManagement(self.context).getShop()) return cm.priceToString(self.context.getValue()) else: c = getUtility(INumberConverter) return c.floatToTaxString(self.context.getValue())
def getTotalPrice(self): """ """ cart = self._getCart() pm = IPrices(cart) total = pm.getPriceForCustomer() cm = ICurrencyManagement(self.context) return cm.priceToString(total)
def _getPropertiesForConfiguration(self, cart_item): """ """ u = getUtility(INumberConverter) cm = ICurrencyManagement(self.context) # Store all selected options for lookup below selected_options = {} for property in cart_item.getProperties(): selected_options[property["id"]] = property["selected_option"] product = cart_item.getProduct() pm = IPropertyManagement(product) result = [] for property in pm.getProperties(): # Only properties with at least one option are displayed. if len(property.getOptions()) == 0: continue options = [] for option in property.getOptions(): # generate value string option_id = option["id"] option_name = option["name"] option_price = option["price"] if option_price != "0.0": option_price = u.stringToFloat(option_price) option_price = cm.priceToString(option_price, "long", "after", suffix=None) content = "%s %s" % (option_name, option_price) else: content = option_name # is option selected? selected_option = selected_options.get(property.getId(), "") selected = option_id == selected_option options.append({ "id" : option_id, "title" : content, "selected" : selected, }) result.append({ "id" : "property_%s_%s" % (product.UID(), property.getId()), "title" : property.Title(), "options" : options, }) return result
def getCartPrice(self): """Returns the price of the current cart. """ cart = self._getCart() if cart is None: price = 0.0 else: price = IPrices(cart).getPriceForCustomer() cm = ICurrencyManagement(self.context) return cm.priceToString(price, suffix=None)
def getTaxForCustomer(self): """ """ cm = ICurrencyManagement(self.context) cart = self._getCart() if cart is None: tax = 0.0 else: tax = ITaxes(cart).getTaxForCustomer() return cm.priceToString(tax, suffix=None)
def getCartPrice(self): """ """ shop = self._getShop() cm = ICurrencyManagement(shop) if ICartManagement(shop).hasCart(): cart = self._getCart() price = IPrices(cart).getPriceForCustomer() return cm.priceToString(price) else: return cm.priceToString(0.0)
def getCartItems(self): """ """ shop = IShopManagement(self.context).getShop() cart = self._getCart() # If there isn't a cart yet if cart is None: return [] cm = ICurrencyManagement(self.context) result = [] for cart_item in IItemManagement(cart).getItems(): product = cart_item.getProduct() product_price = IPrices(cart_item).getPriceForCustomer() / cart_item.getAmount() product_price = cm.priceToString(product_price) price = IPrices(cart_item).getPriceForCustomer() # Discount total_price = 0 discount = IDiscountsCalculation(cart_item).getDiscount() if discount is not None: discount_price = getMultiAdapter((discount, cart_item)).getPriceForCustomer() discount = { "title" : discount.Title(), "value" : cm.priceToString(discount_price, prefix="-"), } total_price = price - discount_price # Product title data = IData(product).asDict() title = data["title"] result.append({ "id" : cart_item.getId(), "product_title" : title, "product_url" : product.absolute_url(), "product_price" : product_price, "price" : cm.priceToString(price), "amount" : cart_item.getAmount(), "properties" : self._getProperties(cart_item), "total_price" : cm.priceToString(total_price), "discount" : discount, }) return result
def getItems(self): """ """ nc = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) items = [] item_manager = IItemManagement(self.context) for item in item_manager.getItems(): product_price_gross = cm.priceToString(item.getProductPriceGross(), suffix=None) tax_rate = nc.floatToTaxString(item.getTaxRate()) tax = cm.priceToString(item.getTax(), suffix=None) price_gross = cm.priceToString(item.getPriceGross(), suffix=None) # Get url. Takes care of, if the product has been deleted in the # meanwhile. product = item.getProduct() if product is None: url = None articleId = None else: url = product.absolute_url() articleId = product.getArticleId() # Properties for property in item.getProperties(): if IProductVariant.providedBy(product) == True: property["show_price"] = False else: property["show_price"] = True temp = { "product_title" : item.getProductTitle(), "product_quantity" : "%.0f" % item.getProductQuantity(), "product_url" : url, "product_articleid" : articleId, "product_price_gross" : product_price_gross, "price_gross" : price_gross, "tax_rate" : tax_rate, "tax" : tax, "properties" : item.getProperties(), "has_discount" : abs(item.getDiscountGross()) > 0, "discount_description" : item.getDiscountDescription(), "discount" : cm.priceToString(item.getDiscountGross(), prefix="-", suffix=None), } items.append(temp) return items
def getSearchPrice(self, product): """ """ product = product.getObject() # Price cm = ICurrencyManagement(product) p = IPrices(product) # Effective price price = p.getPriceForCustomer() price = cm.priceToString(price) return price
def getShippingInfo(self): """ """ sm = IShippingPriceManagement(self.context) shipping_price = sm.getPriceForCustomer() cm = ICurrencyManagement(self.context) price = cm.priceToString(shipping_price) method = IShippingMethodManagement(self.context).getSelectedShippingMethod() return { "price" : price, "title" : method.Title(), "description" : method.Description() }
def getShippingInfo(self): """ """ sm = IShippingPriceManagement(self.context) shipping_price = sm.getPriceForCustomer() cm = ICurrencyManagement(self.context) price = cm.priceToString(shipping_price) method = IShippingMethodManagement( self.context).getSelectedShippingMethod() return { "price": price, "title": method.Title(), "description": method.Description() }
def afterSetUp(self): """ """ super(TestCurrencyManagementUSD, self).afterSetUp() self.shop.setCurrency("usd") self.cm = ICurrencyManagement(self.shop)
def getTotalStandardPriceForCustomer(self): """ """ selected_accessories = self.request.get("accessories", []) selected_accessories = tuplize(selected_accessories) product_price = self.getStandardPriceForCustomer(formatted=False) total_accessories = 0 for accessory in self.getAccessories(): # We take only selected accessories into account if accessory["uid"] in selected_accessories: total_accessories += accessory["total_raw_standard_price"] total_price = product_price + total_accessories cm = ICurrencyManagement(self.context) return cm.priceToString(total_price, suffix=None)
def getShipping(self): """ """ nc = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) price_net = cm.priceToString(self.context.getShippingPriceNet(), suffix=None) price_gross = cm.priceToString(self.context.getShippingPriceGross(), suffix=None) tax_rate = nc.floatToTaxString(self.context.getShippingTaxRate()) tax = cm.priceToString(self.context.getShippingTax(), suffix=None) return { "price_net" : price_net, "price_gross" : price_gross, "tax_rate" : tax_rate, "tax" : tax, }
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[42:]] = 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[42:]] = 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 getShipping(self): """ """ nc = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) price_net = cm.priceToString(self.context.getShippingPriceNet(), suffix=None) price_gross = cm.priceToString(self.context.getShippingPriceGross(), suffix=None) tax_rate = nc.floatToTaxString(self.context.getShippingTaxRate()) tax = cm.priceToString(self.context.getShippingTax(), suffix=None) return { "price_net": price_net, "price_gross": price_gross, "tax_rate": tax_rate, "tax": tax, }
def getPaymentValues(self): """ """ nc = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) price_net = cm.priceToString(self.context.getPaymentPriceNet(), suffix=None) price_gross = cm.priceToString(self.context.getPaymentPriceGross(), suffix=None) tax_rate = nc.floatToTaxString(self.context.getPaymentTaxRate()) tax = cm.priceToString(self.context.getPaymentTax(), suffix=None) transtool = getToolByName(self.context, 'translation_service') return { "display" : self.context.getPaymentPriceGross() != 0, "price_net" : price_net, "price_gross" : price_gross, "tax_rate" : tax_rate, "tax" : tax, "title" : transtool.utranslate("plone", u"Cash on Delivery").encode('utf-8') }
def getPaymentInfo(self): """ """ pp = IPaymentPriceManagement(self.context) price = pp.getPriceForCustomer() cm = ICurrencyManagement(self.context) price = cm.priceToString(price, suffix=None) customer = ICustomerManagement(self.context).getAuthenticatedCustomer() pim = IPaymentInformationManagement(customer) selected_payment_method = pim.getSelectedPaymentMethod() if selected_payment_method is None: return {"display": False} else: return { "price": price, "title": selected_payment_method.Title(), "display": len(self.getCartItems()) > 0, }
def getShippingInfo(self): """ """ sm = IShippingPriceManagement(self.context) shipping_price = sm.getPriceForCustomer() cm = ICurrencyManagement(self.context) price = cm.priceToString(shipping_price, suffix=None) method = IShippingMethodManagement(self.context).getSelectedShippingMethod() if method is None: return { "display" : False, } else: return { "price" : price, "title" : method.Title(), "description" : method.Description(), "display" : len(self.getCartItems()) > 0 }
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 getPaymentMethodInfo(self): """ """ # method customer = ICustomerManagement(self.context).getAuthenticatedCustomer() selected_payment_method = customer.selected_payment_method pm = IPaymentMethodManagement(self.context) method = pm.getPaymentMethod(selected_payment_method) # price pp = IPaymentPriceManagement(self.context) payment_price = pp.getPriceGross() cm = ICurrencyManagement(self.context) price = cm.priceToString(payment_price) return { "type": method.portal_type, "title": method.Title(), "price": price, "display": payment_price != 0, }
def getPriceForCustomer(self, formatted=True): """ """ p = IPrices(self.context) price = p.getPriceForCustomer() if IProductVariantsManagement(self.context).hasVariants() == False: total_diff = 0.0 pm = IPropertyManagement(self.context) for property_id, selected_option in self.request.form.items(): if property_id.startswith("property"): total_diff += pm.getPriceForCustomer( property_id[42:], selected_option ) price += total_diff if formatted == True: cm = ICurrencyManagement(self.context) return cm.priceToString(price, suffix=None) else: return price
def getShippingInfo(self): """ """ sm = IShippingPriceManagement(self.context) shipping_price = sm.getPriceForCustomer() cm = ICurrencyManagement(self.context) price = cm.priceToString(shipping_price, suffix=None) method = IShippingMethodManagement( self.context).getSelectedShippingMethod() if method is None: return { "display": False, } else: return { "price": price, "title": method.Title(), "description": method.Description(), "display": len(self.getCartItems()) > 0 }
def getPaymentMethodInfo(self): """ """ # method customer = ICustomerManagement(self.context).getAuthenticatedCustomer() selected_payment_method = customer.selected_payment_method pm = IPaymentMethodManagement(self.context) method = pm.getPaymentMethod(selected_payment_method) # price pp = IPaymentPriceManagement(self.context) payment_price = pp.getPriceGross() cm = ICurrencyManagement(self.context) price = cm.priceToString(payment_price) return { "type" : method.portal_type, "title" : method.Title(), "price" : price, "display" : payment_price != 0, }
def _getPropertiesForVariants(self, cart_item): """ """ u = getUtility(INumberConverter) cm = ICurrencyManagement(self.context) variant = cart_item.getProduct() product = variant.aq_inner.aq_parent selected_options = {} for property in variant.getForProperties(): name, value = property.split(":") selected_options[name] = value pm = IPropertyManagement(product) result = [] for property in pm.getProperties(): # Only properties with at least one option are displayed. if len(property.getOptions()) == 0: continue options = [] for option in property.getOptions(): # generate value string option_id = option["id"] option_name = option["name"] content = option_name # is option selected? selected_option = selected_options.get(property.getId(), "") selected = option_id == selected_option options.append({ "id": option_id, "title": content, "selected": selected, }) result.append({ "id": "property_%s_%s" % (product.UID(), property.getId()), "title": property.Title(), "options": options, }) 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 getPaymentInfo(self): """ """ pp = IPaymentPriceManagement(self.context) price = pp.getPriceForCustomer() cm = ICurrencyManagement(self.context) price = cm.priceToString(price, suffix=None) customer = ICustomerManagement(self.context).getAuthenticatedCustomer() pim = IPaymentInformationManagement(customer) selected_payment_method = pim.getSelectedPaymentMethod() if selected_payment_method is None: return { "display" : False } else: return { "price" : price, "title" : selected_payment_method.Title(), "display" : len(self.getCartItems()) > 0, }
def getStandardPriceForCustomer(self, formatted=True): """Returns the standard price for a customer when the product is for sale. Used to display the crossed-out standard price. """ p = IPrices(self.context) price = p.getPriceForCustomer(effective=False) if IProductVariantsManagement(self.context).hasVariants() == False: total_diff = 0.0 pm = IPropertyManagement(self.context) for property_id, selected_option in self.request.form.items(): if property_id.startswith("property"): total_diff += pm.getPriceForCustomer( property_id[42:], selected_option ) price + total_diff if formatted == True: cm = ICurrencyManagement(self.context) return cm.priceToString(price, suffix = None) else: return price
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 getDiscounts(self): """ """ return [] cart = self._getCart() if cart is None: return [] cm = ICurrencyManagement(self.context) discounts = [] for cart_item in IItemManagement(cart).getItems(): discount = IDiscountsCalculation(cart_item).getDiscount() if discount is not None: value = getMultiAdapter((discount, cart_item)).getPriceForCustomer() discounts.append({ "title" : discount.Title(), "value" : cm.priceToString(value, prefix="-"), }) return discounts
def getDiscounts(self): """ """ shop = IShopManagement(self.context).getShop() dm = IDiscountsManagement(shop) cm = ICurrencyManagement(shop) result = [] for discount in dm.getDiscounts(): value = cm.priceToString(discount.getValue()) result.append({ "id" : discount.getId(), "title" : discount.Title(), "description" : discount.Description(), "value" : value, "url" : discount.absolute_url(), "up_url" : "%s/es_folder_position?position=up&id=%s" % (self.context.absolute_url(), discount.getId()), "down_url" : "%s/es_folder_position?position=down&id=%s" % (self.context.absolute_url(), discount.getId()), "amount_of_criteria" : self._getAmountOfCriteria(discount.getId()) }) return result
def getCartItems(self): """ """ shop = IShopManagement(self.context).getShop() cart = self._getCart() # If there isn't a cart yet if cart is None: return [] cm = ICurrencyManagement(self.context) result = [] for cart_item in IItemManagement(cart).getItems(): product = cart_item.getProduct() product_price = IPrices( cart_item).getPriceForCustomer() / cart_item.getAmount() product_price = cm.priceToString(product_price) price = IPrices(cart_item).getPriceForCustomer() # Discount total_price = 0 discount = IDiscountsCalculation(cart_item).getDiscount() if discount is not None: discount_price = getMultiAdapter( (discount, cart_item)).getPriceForCustomer() discount = { "title": discount.Title(), "value": cm.priceToString(discount_price, prefix="-"), } total_price = price - discount_price # Product title data = IData(product).asDict() title = data["title"] result.append({ "id": cart_item.getId(), "product_title": title, "product_url": product.absolute_url(), "product_price": product_price, "price": cm.priceToString(price), "amount": cart_item.getAmount(), "properties": self._getProperties(cart_item), "total_price": cm.priceToString(total_price), "discount": discount, }) return result
def getItems(self): """ """ nc = queryUtility(INumberConverter) cm = ICurrencyManagement(self.context) items = [] item_manager = IItemManagement(self.context) for item in item_manager.getItems(): product_price_gross = cm.priceToString(item.getProductPriceGross(), suffix=None) tax_rate = nc.floatToTaxString(item.getTaxRate()) tax = cm.priceToString(item.getTax(), suffix=None) price_gross = cm.priceToString(item.getPriceGross(), suffix=None) # Get url. Takes care of, if the product has been deleted in the # meanwhile. product = item.getProduct() if product is None: url = None else: if IProductVariant.providedBy(product): url = product.aq_inner.aq_parent.absolute_url() else: url = product.absolute_url() # Properties for property in item.getProperties(): if IProductVariant.providedBy(product) == True: property["show_price"] = False else: property["show_price"] = True temp = { "product_title" : item.getProductTitle(), "product_quantity" : item.getProductQuantity(), "product_url" : url, "product_price_gross" : product_price_gross, "price_gross" : price_gross, "tax_rate" : tax_rate, "tax" : tax, "properties" : item.getProperties(), "has_discount" : abs(item.getDiscountGross()) > 0, "discount_description" : item.getDiscountDescription(), "discount" : cm.priceToString(item.getDiscountGross(), prefix="-", suffix=None), } items.append(temp) return items