Esempio n. 1
0
 def getBuyLabel(self):
     """
     """
     pm = IPropertyManagement(self.context)
     if len(pm.getProperties()) > 0:
         return "Buy Product"
     else:
         return "Add to Cart"
Esempio n. 2
0
    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 testGetProperty(self):
        """
        """
        pm = IPropertyManagement(self.shop.products.product_1)

        p = pm.getProperty("color")
        self.assertEqual(p.aq_inner.aq_parent.portal_type, "Product")

        p = pm.getProperty("size")
        self.assertEqual(p.aq_inner.aq_parent.portal_type, "ProductGroup")
    def testGetPriceNet_2(self):
        """Test a properties which is just in groups
        """
        pm = IPropertyManagement(self.shop.products.product_1)

        price = pm.getPriceNet("size", "Small")
        self.assertEqual("%.2f" % price, "-9.24")

        price = pm.getPriceNet("size", "Medium")
        self.assertEqual("%.2f" % price, "0.84")

        price = pm.getPriceNet("size", "Large")
        self.assertEqual("%.2f" % price, "18.49")
    def testGetPriceGross_2(self):
        """Test a properties which is just in groups
        """
        pm = IPropertyManagement(self.shop.products.product_1)

        price = pm.getPriceGross("size", "Small")
        self.assertEqual(price, -11.0)

        price = pm.getPriceGross("size", "Medium")
        self.assertEqual(price, 1.0)

        price = pm.getPriceGross("size", "Large")
        self.assertEqual(price, 22.0)
    def testGetPriceGross_1(self):
        """Test a property which is in group and product.
        """
        pm = IPropertyManagement(self.shop.products.product_1)

        price = pm.getPriceGross("color", "Red")
        self.assertEqual(price, -10.0)

        price = pm.getPriceGross("color", "Blue")
        self.assertEqual(price, 0.0)

        price = pm.getPriceGross("color", "Green")
        self.assertEqual(price, 15.0)
    def testGetPriceForCustomer_2(self):
        """Test a property which is just in group.
        """
        pm = IPropertyManagement(self.shop.products.product_1)

        price = pm.getPriceForCustomer("size", "Small")
        self.assertEqual("%.2f" % price, "-10.17")

        price = pm.getPriceForCustomer("size", "Medium")
        self.assertEqual("%.2f" % price, "0.92")

        price = pm.getPriceForCustomer("size", "Large")
        self.assertEqual("%.2f" % price, "20.34")
    def testGetPriceForCustomer_1(self):
        """Test a property which is in group and product.
        """
        pm = IPropertyManagement(self.shop.products.product_1)

        price = pm.getPriceForCustomer("color", "Red")
        self.assertEqual("%.2f" % price, "-9.24")

        price = pm.getPriceForCustomer("color", "Blue")
        self.assertEqual(price, 0.0)

        price = pm.getPriceForCustomer("color", "Green")
        self.assertEqual("%.2f" % price, "13.87")
    def testGetPriceNet_1(self):
        """Test a property which is in group and product
        """
        pm = IPropertyManagement(self.shop.products.product_1)

        # Note that color prices are taken from product not from group
        price = pm.getPriceNet("color", "Red")
        self.assertEqual("%.2f" % price, "-8.40")

        price = pm.getPriceNet("color", "Blue")
        self.assertEqual(price, 0.0)

        price = pm.getPriceNet("color", "Green")
        self.assertEqual("%.2f" % price, "12.61")
    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"])
Esempio n. 11
0
    def getCurrentPrice(self):
        """
        """
        pm = IPropertyManagement(self.context)

        total_diff = 0.0
        for property_id, selected_option in self.request.form.items():
            if property_id.startswith("property"):
                total_diff += pm.getPriceForCustomer(property_id[9:],
                                                     selected_option)

        p = IPrices(self.context)
        price = p.getPriceGross() + total_diff

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(price)
Esempio n. 12
0
    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
Esempio n. 13
0
    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,
        }