Пример #1
0
    def articles(self):
        """Returns list of dictionary of articles in shop

        :rtype: list
        """
        res = []
        for item in IShoppingSite(self.context).get_content_listing(IArticle, sort_on="sku"):
            obj = item.getObject()
            article = IArticleAdapter(obj)
            sbehavior = IStockBehavior(obj)
            stock = sbehavior.stock()
            stocks = sbehavior.stocks()
            if stocks:
                price = stocks[-1].price
                subtotal = price * stock
                price = getUtility(IPriceUtility, name="string")(price)
                subtotal = getUtility(IPriceUtility, name="string")(subtotal)
            else:
                price = subtotal = "N/A"
            res.append(
                {
                    "price": price,
                    "sku": item.sku,
                    "stock": stock,
                    "subtotal": subtotal,
                    "title": article.title(),
                    "url": item.getURL(),
                }
            )
        return res
    def add(self):
        """Returns attributes: max and size for input: add

        :rtype: dict
        """
        stock = IStock(self.context)
        maximum = stock.initial_stock() - stock.stock()
        if maximum == 0:
            return None

        return {
            'max': maximum,
            'size': len(str(maximum)),
        }