示例#1
0
    def process(self, order=None):
        """
        """
        shop = IShopManagement(self.context).getShop()
        callback_url = "%s/nochex?order=%s" % (shop.absolute_url(),
                                               order.UID())
        success_url = "%s/thank-you" % shop.absolute_url()

        pc = IPrices(order)
        price_gross = "%.2f" % pc.getPriceGross()

        info = {
            "merchant_id": NOCHEX_ID,
            "amount": price_gross,
            "order_id": order.getId(),
            "success_url": success_url,
            "callback_url": callback_url,
        }

        # redirect to paypal
        parameters = "&".join(["%s=%s" % (k, v) for (k, v) in info.items()])

        url = NOCHEX_URL + "?" + parameters
        self.context.REQUEST.RESPONSE.redirect(url)

        return PaymentResult(NOT_PAYED)
示例#2
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
示例#3
0
    def process(self, order=None):
        """
        """    
        shop = IShopManagement(self.context).getShop()
        callback_url = "%s/nochex?order=%s" % (shop.absolute_url(), order.UID())
        success_url  = "%s/thank-you" % shop.absolute_url()
        
        pc = IPrices(order)
        price_gross = "%.2f" % pc.getPriceGross()
        
        info = {
            "merchant_id" : NOCHEX_ID,
            "amount" : price_gross,
            "order_id": order.getId(),
            "success_url" : success_url,
            "callback_url" : callback_url,
        }

        # redirect to paypal    
        parameters = "&".join(["%s=%s" % (k, v) for (k, v) in info.items()])                
        
        url = NOCHEX_URL + "?" + parameters
        self.context.REQUEST.RESPONSE.redirect(url)
        
        return PaymentResult(NOT_PAYED)
    def testGetPriceGross(self):
        """
        """
        p = IPrices(self.item1)
        self.assertEqual(p.getPriceGross(), 44.0)

        p = IPrices(self.item2)
        self.assertEqual(p.getPriceGross(), 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)
示例#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 getPriceForCustomer(self):
        """
        """
        p = IPrices(self.context)
        price = p.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(price, suffix=None)
示例#8
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
示例#9
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
示例#10
0
    def getTotalPrice(self):
        """
        """
        cart = self._getCart()

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

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
示例#11
0
    def testGetPriceNet(self):
        """
        """
        p = IPrices(self.item1)
        price_net = "%.2f" % p.getPriceNet()
        self.assertEqual(price_net, "36.97")

        p = IPrices(self.item2)
        price_net = "%.2f" % p.getPriceNet()
        self.assertEqual(price_net, "47.90")
示例#12
0
    def getTotalPrice(self):
        """
        """
        cart = self._getCart()

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

        cm = ICurrencyManagement(self.context)
        return cm.priceToString(total)
示例#13
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
示例#14
0
    def _sortProductsByPrice(self, products, order=None):
        """Sorts given products by price.
        """
        if order == "desc":
            products.sort(lambda a, b: cmp(
                IPrices(b).getPriceGross(),
                IPrices(a).getPriceGross()))
        else:
            products.sort(lambda a, b: cmp(
                IPrices(a).getPriceGross(),
                IPrices(b).getPriceGross()))

        return products
示例#15
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
示例#16
0
    def process(self, order):
        """
        """
        info = dict()

        pc = IPrices(order)

        customer = order.getCustomer()

        am = IAddressManagement(customer)
        invoice_address  = am.getInvoiceAddress()
        shipping_address = am.getShippingAddress()

        info = {
            "cmd" : "_cart",
            "upload" : "1",
            "business" : "*****@*****.**",
            "currency_code" : "EUR",
            "notify_url" : "",
            "return" : "",
            "last_name" : shipping_address.getName(),
            "address1" : shipping_address.address_1,
            "city" : shipping_address.city,
            "state" : shipping_address.country_title(),
            "zip" : shipping_address.zip_code,
            "shipping_1" : order.getShippingPriceNet(),
            "tax_1" : pc.getPriceGross() - pc.getPriceNet()
        }

        im = IItemManagement(order)
        for i, item in enumerate(im.getItems()):
            j = i + 1
            name     = "item_name_%s" % j
            quantity = "quantity_%s" % j
            amount   = "amount_%s" % j

            product = item.getProduct()

            info[name]     = product.Title()
            info[quantity] = str(int(item.getProductQuantity()))
            info[amount]   = str(item.getProductPriceGross())

        # redirect to paypal
        parameters = "&".join(["%s=%s" % (k, v) for (k, v) in info.items()])

        url = PAYPAL_URL + "?" + parameters
        self.context.REQUEST.RESPONSE.redirect(url)

        return PaymentResult(NOT_PAYED)
示例#17
0
    def getPriceNet(self,
                    with_shipping=True,
                    with_payment=True,
                    with_discount=True):
        """Returns the net price of the cart. This is just a sum over net
        prices of all items of the cart plus shipping and payment.
        """
        im = IItemManagement(self.context)
        if im.hasItems() == False:
            return 0.0

        price = 0.0
        for cart_item in im.getItems():
            # NOTE: with_discount is passed here
            price += IPrices(cart_item).getPriceNet(
                with_discount=with_discount)

        if with_shipping == True:
            sm = IShippingPriceManagement(self.shop)
            shipping_price = sm.getPriceNet()
            price += shipping_price

        if with_payment == True:
            sm = IPaymentPriceManagement(self.shop)
            payment_price = sm.getPriceNet()
            price += payment_price

        return price
示例#18
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
示例#19
0
    def process(self, order=None):
        """
        """
        info = dict()

        shop = IShopManagement(self.context).getShop()
        notify_url = "%s/paypal?order=%s" % (shop.absolute_url(), order.UID())
        return_url = "%s/thank-you" % shop.absolute_url()

        pc = IPrices(order)
        price_net = "%.2f" % pc.getPriceNet()
        tax = "%.2f" % (pc.getPriceGross() - float(price_net))

        customer = order.getCustomer()
        am = IAddressManagement(customer)
        invoice_address  = am.getInvoiceAddress()
        shipping_address = am.getShippingAddress()

        site_encoding = self.context.plone_utils.getSiteEncoding()

        info = {
            "cmd" : "_xclick",
            "upload" : "1",
            "business" : shop.getPayPalId(),
            "currency_code" : "EUR",
            "notify_url" : notify_url,
            "return" : return_url,
            "first_name" : invoice_address.firstname.encode(site_encoding),
            "last_name" : invoice_address.lastname.encode(site_encoding),
            "address1" : invoice_address.address_1.encode(site_encoding),
            "address2" : "",
            "city" : invoice_address.city.encode(site_encoding),
            "state" : invoice_address.country_title().encode(site_encoding),
            "zip" : invoice_address.zip_code.encode(site_encoding),
            "no_shipping" : "1",
            "item_name" : shop.getShopOwner(),
            "amount" : price_net,
            "tax" : tax,
        }

        # redirect to paypal
        parameters = "&".join(["%s=%s" % (k, v) for (k, v) in info.items()])

        url = PAYPAL_URL + "?" + parameters
        self.context.REQUEST.RESPONSE.redirect(url)

        return PaymentResult(NOT_PAYED)
示例#20
0
文件: prices.py 项目: viona/Easyshop
 def getPriceGross(self, effective=True):
     """
     """
     if self.context.getPrice() != 0:
         base = super(ProductVariantPrices, self)
         return base.getPriceGross(effective)
     else:
         return IPrices(self.parent).getPriceGross(variant_price=False)
示例#21
0
文件: taxes.py 项目: viona/Easyshop
    def getTax(self):
        """Returns absolute tax.
        """
        price = IPrices(self.context).getPriceGross(with_discount=True)
        tax_rate = self.taxes.getTaxRate()

        tax = (tax_rate / (tax_rate + 100)) * price
        return tax
示例#22
0
文件: prices.py 项目: viona/Easyshop
 def getPriceGross(self, effective=True, variant_price=True):
     """
     """
     if self.has_variants and variant_price and \
        self.product_variant.getPrice() != 0:
         return IPrices(self.product_variant).getPriceGross(effective)
     else:
         if effective == True:
             return self._getEffectivePriceGross()
         else:
             return self._getStandardPriceGross()
示例#23
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)
示例#24
0
文件: price.py 项目: viona/Easyshop
    def isValid(self, product=None):
        """Returns True if the total price of the cart is greater than the
        entered criteria price.
        """
        shop = IShopManagement(self.context).getShop()
        cart = ICartManagement(shop).getCart()

        if cart is None:
            cart_price = 0.0
        else:
            if self.context.getPriceType() == "net":
                cart_price = IPrices(cart).getPriceForCustomer(
                    with_shipping=False, with_payment=False)
            else:
                cart_price = IPrices(cart).getPriceGross(with_shipping=False,
                                                         with_payment=False)

        cart_price = float("%.2f" % cart_price)
        if cart_price >= self.context.getPrice():
            return True
        return False
示例#25
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)
示例#26
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
示例#27
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)
示例#28
0
    def testGetPriceGross(self):
        """
        """
        p = IPrices(self.item1)
        self.assertEqual(p.getPriceGross(), 44.0)

        p = IPrices(self.item2)
        self.assertEqual(p.getPriceGross(), 57.0)
示例#29
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
示例#30
0
    def testGetPriceNet(self):
        """
        """
        p = IPrices(self.item1)
        price_net = "%.2f" % p.getPriceNet()
        self.assertEqual(price_net, "36.97")

        p = IPrices(self.item2)
        price_net = "%.2f" % p.getPriceNet()
        self.assertEqual(price_net, "47.90")
示例#31
0
文件: prices.py 项目: viona/Easyshop
    def getPriceForCustomer(self):
        """
        """
        # If the discount is by percentage, we don't have to calc the tax for
        # the discount, because the discount is a part of the already calculated
        # price, hence we can do it here.

        if self.discount.getType() == "percentage":
            price = IPrices(self.cart_item).getPriceForCustomer()
            return price * (self.discount.getValue() / 100)
        else:
            tax_rate_for_customer = self.taxes.getTaxRateForCustomer()
            price_net = self.getPriceNet()

            # We take the net price and add the customer specific taxes.
            return price_net * ((tax_rate_for_customer + 100) / 100)
示例#32
0
文件: prices.py 项目: viona/Easyshop
    def getPriceGross(self):
        """
        """
        if self.discount.getType() == "percentage":
            price = IPrices(self.cart_item).getPriceGross()
            return price * (self.discount.getValue() / 100)
        else:
            tax_rate = self.taxes.getTaxRate()
            price = self._calcTotalPrice()

            # The price entered is considered as gross price, so we simply
            # return it.
            if self.shop.getGrossPrices() == True:
                return price

            # The price entered is considered as net price. So we have to
            # calculate the gross price first.
            else:
                return price * ((tax_rate + 100) / 100)
示例#33
0
    def process(self, order=None):
        """
        """
        shop        = IShopManagement(self.context).getShop()
        customer    = ICustomerManagement(shop).getAuthenticatedCustomer()
        credit_card = IPaymentInformationManagement(customer).getSelectedPaymentInformation()

        card_num = credit_card.card_number
        exp_date = "%s/%s" % (credit_card.card_expiration_date_month,
                              credit_card.card_expiration_date_year)

        line_items = []
        for i, item in enumerate(IItemManagement(order).getItems()):
            if item.getProductTax() > 0:
                tax = "Y"
            else:
                tax = "N"

            line_items.append((
                str(i+1),
                item.getProduct().Title(),
                str(item.getProductQuantity()),
                str(item.getProductPriceGross()),
                tax,
            ))

        amount = "%.2f" % IPrices(order).getPriceForCustomer()

        cc = EasyShopCcProcessor(
            server="test.authorize.net",
            login="******",
            key="9ME22bvLnu87P4FY")

        # Used for authorizeAndCapture
        result = cc.authorizeAndCapture(
            amount = amount,
            card_num = card_num,
            exp_date = exp_date)
        if result.response == "approved":
            return PaymentResult(PAYED, _(u"Your order has been payed."))
        else:
            return PaymentResult(ERROR, _(result.response_reason))
示例#34
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
示例#35
0
    def getPriceGross(self, with_discount=False):
        """Returns the gross price for a cart item. This is just the gross
        product price plus the properties gross prices (can be positiv or 
        negative) multiply with the amount.
        """
        product = self.context.getProduct()
        price = IPrices(product).getPriceGross()

        pm = IPropertyManagement(product)
        for selected_property in self.context.getProperties():
            price += pm.getPriceGross(selected_property["id"],
                                      selected_property["selected_option"])

        price *= self.context.getAmount()

        if with_discount == True:
            discount = IDiscountsCalculation(self.context).getDiscount()
            if discount is not None:
                discount_value = getMultiAdapter(
                    (discount, self.context)).getPriceGross()
                price -= discount_value

        return price
示例#36
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(),
            }
 def testGetPriceNet(self):
     """
     """
     p = IPrices(self.shop.products.product_1)
     self.assertEqual("%.2f" % p.getPriceNet(), "18.49")
示例#38
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
示例#39
0
 def testGetPriceForCustomer(self):
     """
     """
     p = IPrices(self.cart)
     self.assertEqual(p.getPriceForCustomer(), 211.00)
示例#40
0
 def testGetPriceNet(self):
     """
     """
     p = IPrices(self.cart)
     price_net = "%.2f" % p.getPriceNet()
     self.assertEqual(price_net, "177.31")
示例#41
0
 def testGetPriceGross(self):
     """
     """
     p = IPrices(self.cart)
     self.assertEqual(p.getPriceGross(), 211.00)
示例#42
0
 def testGetPriceGross(self):
     """
     """
     pp = IPrices(self.item1)
     self.assertEqual(pp.getPriceGross(), 4536.0)
示例#43
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,
        }
示例#44
0
    def getSelectors(self):
        """
        """
        fi = self.getFormatInfo()
        products_per_line = fi.get("products_per_line")

        mtool = getToolByName(self.context, "portal_membership")

        selectors = []
        for selector in self.context.objectValues("ProductSelector"):

            # ignore thank you selection
            if selector.getId() != "thank-you":
                continue

            products_per_line = products_per_line

            lines = []
            products = []
            for index, product in enumerate(selector.getRefs()):

                if mtool.checkPermission("View", product) is None:
                    continue

                cm = ICurrencyManagement(self.context)
                price = IPrices(product).getPriceForCustomer()
                price = cm.priceToString(price)

                # image
                image = IImageManagement(product).getMainImage()
                if image is not None:
                    image = "%s/image_%s" % (image.absolute_url(),
                                             fi.get("image_size"))

                t = fi.get("text")
                if t == "description":
                    text = product.getDescription()
                elif t == "short_text":
                    text = product.getShortText()
                elif t == "text":
                    text = product.getText()
                else:
                    text = ""

                n = len(selector.getRefs())
                if index == n - 1 and n > 1 and products_per_line > 1:
                    klass = "last"
                else:
                    klass = "notlast"

                products.append({
                    "title":
                    product.Title(),
                    "short_title":
                    product.getShortTitle() or product.Title(),
                    "url":
                    product.absolute_url(),
                    "price":
                    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,
                "td_width":
                "%s%%" % (100 / products_per_line),
            })

        return selectors
示例#45
0
 def testGetPriceNet(self):
     """
     """
     pp = IPrices(self.item1)
     price_net = "%.2f" % pp.getPriceNet()
     self.assertEqual(price_net, "3811.76")
 def testGetPriceForCustomer(self):
     """
     """
     p = IPrices(self.shop.products.product_1)
     self.assertEqual("%.2f" % p.getPriceForCustomer(), "20.34")
 def testGetPriceForCustomer(self):
     """Customer has same tax rate as default
     """
     p = IPrices(self.shop.products.product_1)
     self.assertEqual("%.2f" % p.getPriceForCustomer(), "22.00")
 def testGetPriceGross(self):
     """
     """
     p = IPrices(self.order)
     self.assertEqual("%.2f" % p.getPriceGross(), "151.00")
示例#49
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
 def testGetPriceNet(self):
     """
     """
     p = IPrices(self.order)
     self.assertEqual("%.2f" % p.getPriceNet(), "126.89")
 def testGetPriceGross(self):
     """
     """
     p = IPrices(self.shop.products.product_1)
     self.assertEqual(p.getPriceGross(), 22.0)
 def testGetPriceForCustomer(self):
     """
     """
     p = IPrices(self.order)
     self.assertEqual("%.2f" % p.getPriceForCustomer(), "151.00")
示例#53
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)
示例#54
0
 def testGetPriceForCustomer(self):
     """
     """
     pp = IPrices(self.item1)
     self.assertEqual(pp.getPriceForCustomer(), 4536.0)