示例#1
0
    def testGetPriceForCustomer(self):
        """
        """
        p = IPrices(self.item1)
        self.assertEqual("%.2f" % p.getPriceForCustomer(), "44.00")

        p = IPrices(self.item2)
        self.assertEqual(p.getPriceForCustomer(), 57.0)
    def testGetPriceForCustomer(self):
        """
        """
        p = IPrices(self.item1)
        self.assertEqual("%.2f" % p.getPriceForCustomer(), "44.00")

        p = IPrices(self.item2)
        self.assertEqual(p.getPriceForCustomer(), 57.0)
示例#3
0
    def getLatestOrder(self):
        """Returns the last order id of authenticated customer
        """
        om = IOrderManagement(self.context)
        orders = om.getOrdersForAuthenticatedCustomer()
        orders.sort(lambda a, b: cmp(b.created(), a.created()))

        order = orders[0]

        # Address
        customer = order.getCustomer()
        address = IAddressManagement(customer).getInvoiceAddress()

        prices = IPrices(order)

        transaction = {
            "order_id": order.getId(),
            "affiliation": "",
            "total": prices.getPriceForCustomer(),
            "tax": (prices.getPriceForCustomer() - prices.getPriceNet()),
            "shipping": order.getShippingPriceGross(),
            "city": address.city,
            "state": "",
            "country": address.country_title(),
        }

        items = []
        for item in IItemManagement(order).getItems():

            # Product
            product = item.getProduct()

            # Category
            try:
                category = product.getCategories()[0]
                category_title = category.Title()
            except IndexError:
                category_title = u""

            items.append(
                {
                    "order_id": order.getId(),
                    "sku": product.getArticleId(),
                    "productname": product.Title(),
                    "category": category_title,
                    "price": item.getProductPriceGross(),
                    "quantity": item.getProductQuantity(),
                }
            )

        result = {
            "id": order.getId(),
            "url": order.absolute_url(),
            "google_transaction": transaction,
            "google_items": items,
        }

        return result
示例#4
0
    def getLatestOrder(self):
        """Returns the last order id of authenticated customer
        """
        om = IOrderManagement(self.context)
        orders = om.getOrdersForAuthenticatedCustomer()
        orders.sort(lambda a, b: cmp(b.created(), a.created()))

        order = orders[0]

        # Address
        customer = order.getCustomer()
        address = IAddressManagement(customer).getInvoiceAddress()

        prices = IPrices(order)

        transaction = {
            "order_id": order.getId(),
            "affiliation": "",
            "total": prices.getPriceForCustomer(),
            "tax": (prices.getPriceForCustomer() - prices.getPriceNet()),
            "shipping": order.getShippingPriceGross(),
            "city": address.city,
            "state": "",
            "country": address.country_title(),
        }

        items = []
        for item in IItemManagement(order).getItems():

            # Product
            product = item.getProduct()

            # Category
            try:
                category = product.getCategories()[0]
                category_title = category.Title()
            except IndexError:
                category_title = u""

            items.append({
                "order_id": order.getId(),
                "sku": product.getArticleId(),
                "productname": product.Title(),
                "category": category_title,
                "price": item.getProductPriceGross(),
                "quantity": item.getProductQuantity()
            })

        result = {
            "id": order.getId(),
            "url": order.absolute_url(),
            "google_transaction": transaction,
            "google_items": items,
        }

        return result
示例#5
0
    def getPriceForCustomer(self):
        """
        """
        p = IPrices(self.context)
        price = p.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(price, suffix=None)
示例#6
0
    def getPriceForCustomer(self):
        """
        """
        p = IPrices(self.context)
        price = p.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(price, suffix=None)
示例#7
0
    def getTotalPrice(self):
        """
        """
        cart = self._getCart()

        pm = IPrices(cart)
        total = pm.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
示例#8
0
    def getTotalPrice(self):
        """
        """
        cart = self._getCart()

        pm = IPrices(cart)
        total = pm.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
示例#9
0
    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
示例#10
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
示例#11
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
示例#12
0
文件: data.py 项目: viona/Easyshop
    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
示例#13
0
    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
示例#14
0
 def testGetPriceForCustomer(self):
     """
     """
     p = IPrices(self.shop.products.product_1)
     self.assertEqual("%.2f" % p.getPriceForCustomer(), "20.34")
示例#15
0
 def testGetPriceForCustomer(self):
     """Customer has same tax rate as default
     """
     p = IPrices(self.shop.products.product_1)
     self.assertEqual("%.2f" % p.getPriceForCustomer(), "22.00")
示例#16
0
    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 testGetPriceForCustomer(self):
     """
     """
     p = IPrices(self.shop.products.product_1)
     self.assertEqual("%.2f" % p.getPriceForCustomer(), "20.34")
示例#18
0
    def _addItemFromCartItem(self, id, cart_item):
        """Sets the item by given cart item.
        """
        self.context.manage_addProduct["easyshop.core"].addOrderItem(
            id=str(id))
        new_item = getattr(self.context, str(id))

        # set product quantity
        new_item.setProductQuantity(cart_item.getAmount())

        # Set product prices & taxes
        product_taxes = ITaxes(cart_item.getProduct())
        product_prices = IPrices(cart_item.getProduct())
        item_prices = IPrices(cart_item)
        item_taxes = ITaxes(cart_item)

        new_item.setTaxRate(product_taxes.getTaxRateForCustomer())
        new_item.setProductTax(product_taxes.getTaxForCustomer())

        new_item.setProductPriceGross(product_prices.getPriceForCustomer())
        new_item.setProductPriceNet(product_prices.getPriceNet())

        # Set item prices & taxes
        new_item.setTax(item_taxes.getTaxForCustomer())
        new_item.setPriceGross(item_prices.getPriceForCustomer())
        new_item.setPriceNet(item_prices.getPriceNet())

        # Discount
        discount = IDiscountsCalculation(cart_item).getDiscount()
        if discount is not None:
            new_item.setDiscountDescription(discount.Title())

            dp = getMultiAdapter((discount, cart_item))
            new_item.setDiscountGross(dp.getPriceForCustomer())
            new_item.setDiscountNet(dp.getPriceNet())

        # Set product
        product = cart_item.getProduct()
        new_item.setProduct(product)

        # Set product name and id
        data = IData(product).asDict()
        new_item.setProductTitle(data["title"])
        new_item.setArticleId(data["article_id"])

        # Set properties
        properties = []
        pm = IPropertyManagement(product)
        for selected_property in cart_item.getProperties():

            # Get the price
            property_price = pm.getPriceForCustomer(
                selected_property["id"], selected_property["selected_option"])

            # By default we save the titles of the properties and selected
            # options In this way they are kept if the title of a property or
            # option will be changed after the product has been bought.
            titles = getTitlesByIds(product, selected_property["id"],
                                    selected_property["selected_option"])

            # If we don't find the property or option we ignore the property.
            # This can only happen if the property has been deleted after a
            # product has been added to the cart. In this case we don't want the
            # property at all (I think).
            if titles is None:
                continue

            properties.append({
                "title": titles["property"],
                "selected_option": titles["option"],
                "price": str(property_price),
            })

        new_item.setProperties(properties)
示例#19
0
 def testGetPriceForCustomer(self):
     """
     """
     p = IPrices(self.order)
     self.assertEqual("%.2f" % p.getPriceForCustomer(), "151.00")
示例#20
0
 def testGetPriceForCustomer(self):
     """
     """
     pp = IPrices(self.item1)
     self.assertEqual(pp.getPriceForCustomer(), 4536.0)
示例#21
0
    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,
        }
示例#22
0
    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,
        }
示例#23
0
文件: data.py 项目: Easyshop/Easyshop
    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
示例#24
0
 def testGetPriceForCustomer(self):
     """
     """
     p = IPrices(self.cart)
     self.assertEqual(p.getPriceForCustomer(), 211.00)
 def testGetPriceForCustomer(self):
     """Customer has same tax rate as default
     """
     p = IPrices(self.shop.products.product_1)
     self.assertEqual("%.2f" % p.getPriceForCustomer(), "22.00")
示例#26
0
    def _addItemFromCartItem(self, id, cart_item):
        """Sets the item by given cart item.
        """        
        self.context.manage_addProduct["easyshop.core"].addOrderItem(id=str(id))
        new_item = getattr(self.context, str(id))

        # set product quantity        
        new_item.setProductQuantity(cart_item.getAmount())
                
        # Set product prices & taxes
        product_taxes  = ITaxes(cart_item.getProduct())
        product_prices = IPrices(cart_item.getProduct())
        item_prices = IPrices(cart_item)
        item_taxes  = ITaxes(cart_item)
        
        new_item.setTaxRate(product_taxes.getTaxRateForCustomer())
        new_item.setProductTax(product_taxes.getTaxForCustomer())
        
        new_item.setProductPriceGross(product_prices.getPriceForCustomer())
        new_item.setProductPriceNet(product_prices.getPriceNet())

        # Set item prices & taxes
        new_item.setTax(item_taxes.getTaxForCustomer())
        new_item.setPriceGross(item_prices.getPriceForCustomer())
        new_item.setPriceNet(item_prices.getPriceNet())

        # Discount
        discount = IDiscountsCalculation(cart_item).getDiscount()
        if discount is not None:
            new_item.setDiscountDescription(discount.Title())

            dp = getMultiAdapter((discount, cart_item))
            new_item.setDiscountGross(dp.getPriceForCustomer())
            new_item.setDiscountNet(dp.getPriceNet())
        
        # Set product
        product = cart_item.getProduct()
        new_item.setProduct(product)

        # Set product name and id
        data = IData(product).asDict()
        new_item.setProductTitle(data["title"])
        new_item.setArticleId(data["article_id"])

        # Set properties
        properties = []
        pm = IPropertyManagement(product)
        for selected_property in cart_item.getProperties():

            # Get the price
            property_price = pm.getPriceForCustomer(
                selected_property["id"], 
                selected_property["selected_option"])

            # By default we save the titles of the properties and selected 
            # options In this way they are kept if the title of a property or 
            # option will be changed after the product has been bought.
            titles = getTitlesByIds(
                product,
                selected_property["id"], 
                selected_property["selected_option"])

            # If we don't find the property or option we ignore the property. 
            # This can only happen if the property has been deleted after a 
            # product has been added to the cart. In this case we don't want the 
            # property at all (I think).
            if titles is None:
                continue
                                    
            properties.append({
                "title" : titles["property"],
                "selected_option" : titles["option"],
                "price" : str(property_price),
            })
                            
        new_item.setProperties(properties)
示例#27
0
 def testGetPriceForCustomer(self):
     """
     """
     pp = IPrices(self.item1)
     self.assertEqual(pp.getPriceForCustomer(), 4536.0)