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")
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
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
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)
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)
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)
def testGetPriceNet(self): """ """ p = IPrices(self.shop.products.product_1) self.assertEqual("%.2f" % p.getPriceNet(), "18.49")
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)
def testGetPriceNet(self): """ """ pp = IPrices(self.item1) price_net = "%.2f" % pp.getPriceNet() self.assertEqual(price_net, "3811.76")
def testGetPriceNet(self): """ """ p = IPrices(self.order) self.assertEqual("%.2f" % p.getPriceNet(), "126.89")
def testGetPriceNet(self): """ """ p = IPrices(self.cart) price_net = "%.2f" % p.getPriceNet() self.assertEqual(price_net, "177.31")