示例#1
0
文件: cart.py 项目: viona/Easyshop
    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
示例#2
0
 def getBuyLabel(self):
     """
     """
     pm = IPropertyManagement(self.context)
     if len(pm.getProperties()) > 0:
         return "Buy Product"
     else:
         return "Add to Cart"
示例#3
0
    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
示例#4
0
文件: cart.py 项目: Easyshop/Easyshop
    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
示例#5
0
文件: cart.py 项目: viona/Easyshop
    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 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', 'size', 'material', 'quality'])
示例#7
0
    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', 'size', 'material', 'quality'])
示例#8
0
文件: cart.py 项目: Easyshop/Easyshop
    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
示例#9
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[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
示例#10
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[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
示例#11
0
    def getProperties(self):
        """
        """
        result = []
        pm = IPropertyManagement(self.context)
        for property in pm.getProperties():

            # Only properties with at least one option are displayed.
            options = property.getOptions()
            if len(options) == 0:
                continue

            result.append({
                "id": property.getId(),
                "name": "property_" + property.getId(),
                "title": property.Title(),
                "options": options,
            })

        return result
示例#12
0
    def getProperties(self):
        """
        """
        result = []
        pm = IPropertyManagement(self.context)
        for property in pm.getProperties():

            # Only properties with at least one option are displayed.
            options = property.getOptions()
            if len(options) == 0:
                continue

            result.append({
                "id"      : property.getId(),
                "name"    : "property_" + property.getId(),
                "title"   : property.Title(),
                "options" : options,
            })

        return result
示例#13
0
    def _getPropertiesForVariants(self):
        """
        """
        u = queryUtility(INumberConverter)
        cm = ICurrencyManagement(self.context)

        selected_options = {}
        for name, value in self.request.items():
            if name.startswith("property"):
                if len(name) > 42:
                    selected_options[name[42:]] = value
                else:
                    selected_options[name[9:]] = value

        # If nothing is selected we select the default variant
        if selected_options == {}:
            pvm = IProductVariantsManagement(self.context)
            default_variant = pvm.getDefaultVariant()

            # If there is no default variant return empty list
            if default_variant is None:
                return []

            for property in default_variant.getForProperties():
                name, value = property.split(":")
                selected_options[name] = 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

            options = []
            for option in property.getOptions():

                # generate value string
                option_id    = option["id"]
                option_name  = option["name"]
                # option_price = option["price"]
                # option_price = u.stringToFloat(option_price)
                # option_price = cm.priceToString(option_price, "long", "after")
                # content = "%s %s" % (option_name, option_price)
                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