コード例 #1
0
    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
コード例 #2
0
ファイル: payment_prices.py プロジェクト: ned14/Easyshop
    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
コード例 #3
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
コード例 #4
0
ファイル: discounts_container.py プロジェクト: viona/Easyshop
    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
コード例 #5
0
ファイル: order_view.py プロジェクト: viona/Easyshop
    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')
        }
コード例 #6
0
    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
コード例 #7
0
ファイル: related_products.py プロジェクト: Easyshop/Easyshop
 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
コード例 #8
0
    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
コード例 #9
0
ファイル: data.py プロジェクト: Easyshop/Easyshop
    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(),
            }        
コード例 #10
0
ファイル: cart.py プロジェクト: viona/Easyshop
    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
コード例 #11
0
    def getTotalTax(self):
        """
        """
        cart = self._getCart()
        total = ITaxes(cart).getTaxForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
コード例 #12
0
ファイル: order_view.py プロジェクト: Easyshop/Easyshop
    def getPriceForCustomer(self):
        """
        """
        p = IPrices(self.context)
        price = p.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(price, suffix=None)
コード例 #13
0
ファイル: order_view.py プロジェクト: viona/Easyshop
    def getPriceForCustomer(self):
        """
        """
        p = IPrices(self.context)
        price = p.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(price, suffix=None)
コード例 #14
0
ファイル: order_preview.py プロジェクト: Easyshop/Easyshop
    def getTotalTax(self):
        """
        """
        cart = self._getCart()
        total = ITaxes(cart).getTaxForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
コード例 #15
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
コード例 #16
0
ファイル: discount.py プロジェクト: ned14/Easyshop
 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())
コード例 #17
0
 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())
コード例 #18
0
    def getTotalPrice(self):
        """
        """
        cart = self._getCart()

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

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
コード例 #19
0
ファイル: order_preview.py プロジェクト: Easyshop/Easyshop
    def getTotalPrice(self):
        """
        """
        cart = self._getCart()

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

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
コード例 #20
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
コード例 #21
0
ファイル: cart.py プロジェクト: Easyshop/Easyshop
 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)
コード例 #22
0
ファイル: cart.py プロジェクト: Easyshop/Easyshop
    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)
コード例 #23
0
ファイル: cart.py プロジェクト: Easyshop/Easyshop
 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)
コード例 #24
0
ファイル: cart.py プロジェクト: viona/Easyshop
    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)
コード例 #25
0
ファイル: cart.py プロジェクト: viona/Easyshop
    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)
コード例 #26
0
ファイル: cart.py プロジェクト: viona/Easyshop
    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)
コード例 #27
0
ファイル: cart.py プロジェクト: Easyshop/Easyshop
    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
コード例 #28
0
ファイル: order_view.py プロジェクト: Easyshop/Easyshop
    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
コード例 #29
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
コード例 #30
0
ファイル: order_preview.py プロジェクト: Easyshop/Easyshop
    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()
        }
コード例 #31
0
    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()
        }
コード例 #32
0
 def afterSetUp(self):
     """
     """
     super(TestCurrencyManagementUSD, self).afterSetUp()
     self.shop.setCurrency("usd")
     
     self.cm = ICurrencyManagement(self.shop)
コード例 #33
0
    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)
コード例 #34
0
ファイル: order_view.py プロジェクト: Easyshop/Easyshop
    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,
        }
コード例 #35
0
ファイル: search_results.py プロジェクト: viona/Easyshop
    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
コード例 #36
0
ファイル: search_results.py プロジェクト: Easyshop/Easyshop
    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
コード例 #37
0
ファイル: order_view.py プロジェクト: viona/Easyshop
    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,
        }
コード例 #38
0
ファイル: order_view.py プロジェクト: Easyshop/Easyshop
    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')
        }
コード例 #39
0
ファイル: cart.py プロジェクト: viona/Easyshop
    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,
            }
コード例 #40
0
ファイル: cart.py プロジェクト: Easyshop/Easyshop
    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
            }        
コード例 #41
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
コード例 #42
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,
        }
コード例 #43
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
コード例 #44
0
ファイル: cart.py プロジェクト: viona/Easyshop
    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
            }
コード例 #45
0
ファイル: order_preview.py プロジェクト: Easyshop/Easyshop
 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,
     }
コード例 #46
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
コード例 #47
0
ファイル: thank_you.py プロジェクト: ned14/Easyshop
    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
コード例 #48
0
ファイル: cart.py プロジェクト: Easyshop/Easyshop
    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,
            }
コード例 #49
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
コード例 #50
0
    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(),
            }
コード例 #51
0
ファイル: order_preview.py プロジェクト: Easyshop/Easyshop
    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
コード例 #52
0
    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
コード例 #53
0
ファイル: cart.py プロジェクト: viona/Easyshop
    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
コード例 #54
0
    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