def variation_items(self): props = getToolByName(self.context, 'portal_properties').pcommerce_properties columns = int(props.getProperty('columns', 3)) width = int(props.getProperty('thumb_width', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' items = [] i = 0 catalog = getToolByName(self.product, 'portal_catalog') variations = catalog(object_provides=IVariation.__identifier__, path={'query': '/'.join(self.product.getPhysicalPath())}) for variation in variations: col = i % columns + 1 i += 1 variation = variation.getObject() adapter = IPricing(self.product) if variation.UID() != self.context.UID(): image = None if variation.getImage(): image = {'caption': variation.getImageCaption(), 'thumb': '%s/%s' % (variation.absolute_url(), width)} items.append({'uid': variation.UID(), 'class': 'col%s' % col, 'title': '%s: %s' % (variation.getType(), variation.Title()), 'description': variation.Description() or self.product.Description(), 'price': CurrencyAware(adapter.getPrice([variation, ])), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice([variation, ]) < adapter.getBasePrice(), 'image': image, 'url': variation.absolute_url()}) return items
def posttaxcharges(self): charges = [] if getattr(self.order.paymentdata, 'posttaxcharge', 0): charges.append({ 'title': self.payment['title'], 'price': CurrencyAware( getattr(self.order.paymentdata, 'posttaxcharge', 0)) }) for shipmentid, data in self.order.shipmentdata.items(): if not data.posttaxcharge: continue for shipment in self.shipments: if shipmentid == shipment['id']: charges.append({ 'title': shipment['title'], 'number': len(self.shipments) > 1 and shipment['number'] or None, 'price': CurrencyAware(data.posttaxcharge) }) for charge in self.order.posttaxcharges: if charge.price: charges.append({ 'title': charge.title, 'price': CurrencyAware(charge.price) }) return charges
def batch(self): catalog = getToolByName(self.context, 'portal_catalog') portal_properties = getToolByName(self.context, 'portal_properties') use_view_action = portal_properties.site_properties.getProperty( 'typesUseViewActionInListings', ()) props = portal_properties.pcommerce_properties columns = int(props.getProperty('columns', 3)) width = int(props.getProperty('thumb_width', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' results = catalog(object_provides=IProduct.__identifier__, path={ 'query': '/'.join(self.context.getPhysicalPath()), 'depth': 1 }, sort_on='getObjPositionInParent') items = [] i = 0 start = (self.page - 1) * (columns * 5) end = start + columns * 5 for item in results: url = item.getURL() if item.portal_type in use_view_action: url += '/view' if start <= i < end: object = item.getObject() col = i % columns + 1 adapter = IPricing(object) image = None if object.getImage(): image = { 'caption': object.getImageCaption(), 'thumb': '%s/%s' % (item.getURL(), width) } item = { 'uid': item.UID, 'class': 'col%s' % col, 'title': item.Title, 'description': item.Description, 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': url } else: item = { 'uid': item.UID, 'title': item.Title, 'description': item.Description, 'url': url } i += 1 items.append(item) return Batch(items, columns * 5, self.page, 5)
def related_items(self): portal_properties = getToolByName(self.context, 'portal_properties') use_view_action = portal_properties.site_properties.getProperty( 'typesUseViewActionInListings', ()) props = portal_properties.pcommerce_properties columns = int(props.getProperty('columns', 3)) width = int(props.getProperty('thumb_width', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' items = [] i = 0 for item in self.product.getRelatedItems(): if IProduct.providedBy(item): col = i % columns + 1 i += 1 adapter = IPricing(item) image = None if item.getImage(): image = { 'caption': item.getImageCaption(), 'thumb': '%s/%s' % (item.absolute_url(), width) } url = item.getURL() if item.portal_type in use_view_action: url += '/view' items.append({ 'uid': item.UID(), 'class': 'col%s' % col, 'title': item.Title(), 'description': item.Description(), 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': url }) return items
def products(self): catalog = getToolByName(self.context, 'portal_catalog') portal_properties = getToolByName(self.context, 'portal_properties') use_view_action = portal_properties.site_properties.getProperty( 'typesUseViewActionInListings', ()) props = portal_properties.pcommerce_properties columns = int(props.getProperty('hot_columns', 3)) no = int(props.getProperty('no_hot_products', 6)) width = int(props.getProperty('thumb_width_hot_products', 0)) width = width and 'image/thumb?width=%s' % width or 'image_thumb' results = list( catalog(object_provides=IProduct.__identifier__, hot=True)) if not results: return None items = [] i = 0 while len(items) < no and len(results): item = results.pop(random.randrange(len(results))) object = item.getObject() col = i % columns + 1 i += 1 adapter = IPricing(object) image = None if object.getImage(): image = { 'caption': object.getImageCaption(), 'thumb': '%s/%s' % (item.getURL(), width) } url = item.getURL() if item.portal_type in use_view_action: url += '/view' item = { 'uid': item.UID, 'class': 'col%s' % col, 'title': item.Title, 'description': item.Description, 'price': CurrencyAware(adapter.getPrice()), 'base_price': CurrencyAware(adapter.getBasePrice()), 'offer': adapter.getPrice() < adapter.getBasePrice(), 'image': image, 'url': url } items.append(item) return items
def variations(self): catalog = getToolByName(self.context, 'portal_catalog') results = catalog(object_provides=IVariation.__identifier__, path={'query': '/'.join(self.product.getPhysicalPath())}) variations = {} for variation in results: if not variations.has_key(variation.getType): variations[variation.getType] = [] if not variation.getAddPrice: price_adapter = IPricing(variation.getObject()) variations[variation.getType].append({ 'uid': variation.UID, 'name': variation.Title, 'price': CurrencyAware(IPricing(self.product).getPrice([variation.getObject()])), 'price_raw': IPricing(self.product).getPrice([variation.getObject()]), 'base_price': CurrencyAware(variation.getAddPrice and self.base_price.getValue() + float(variation.getPrice) or price_adapter.getBasePrice()), 'base_price_raw':variation.getAddPrice and self.base_price.getValue() + float(variation.getPrice) or price_adapter.getBasePrice(), 'add_price': variation.getAddPrice and CurrencyAware(float(variation.getPrice)) or None, 'add_price_raw': variation.getAddPrice and float(variation.getPrice) or None, }) return [{'name': type[0], 'variations': type[1]} for type in variations.items()]
def items(self): catalog = getToolByName(self.context, 'portal_catalog') plone_view = getMultiAdapter((self.context, self.request), name=u'plone') utils = getToolByName(self.context, 'plone_utils') wftool = getToolByName(self.context, 'portal_workflow') results = catalog(object_provides=IPrice.__identifier__, path={ 'query': '/'.join(self.context.getPhysicalPath()), 'depth': 1 }) prices = [] odd = True for price in results: prices.append({ 'uid': price.UID, 'id': price.getId, 'modified': plone_view.toLocalizedTime(price.ModificationDate, long_format=1), 'state_title': wftool.getTitleForStateOnType(price.review_state, price.portal_type), 'state_class': 'state-' + utils.normalizeString(price.review_state), 'is_expired': self.context.isExpired(price), 'title_or_id': price.pretty_title_or_id(), 'table_row_class': odd and 'odd' or 'even', 'raw_price': price.getPrice, 'price': CurrencyAware(price.getPrice), 'path': price.getPath, 'relative_url': price.getURL(relative=True), 'url': { 'edit': '%s/edit' % price.getURL(), 'sharing': '%s/@@sharing' % price.getURL() } }) odd = not odd return prices
def create(self, order): """ generates an order from the cart """ member = getMultiAdapter((self.context, self.context.REQUEST), name=u'plone_portal_state').member() cart = interfaces.IShoppingCart(self.context) if not len(cart): return order.userid = member.getId() order.date = time() order.currency = CurrencyAware(0).getCurrencySymbol() products = cart.getProducts() order_products = PersistentList() price = 0 for product in products: price += product['price_raw'] * product['amount'] order_products.append( (product['uid'], product['no'], product['title'], product['amount'], product['price_raw'], [ (variation['uid'], variation['type'], variation['name']) for variation in product['variations'] ])) if order_products != order.products: order.processed_steps = () order.products = order_products order.price = price order._taxincl = interfaces.ITaxes(self.context).taxincl pretaxcharges = [] providers = getAdapters((self.context, ), interfaces.IPreTaxCharge) for name, provider in providers: pretaxcharges.append(provider.process(order)) order.pretaxcharges = tuple(pretaxcharges) posttaxcharges = [] providers = getAdapters((self.context, ), interfaces.IPostTaxCharge) for name, provider in providers: posttaxcharges.append(provider.process(order)) order.posttaxcharges = tuple(posttaxcharges) self[order.orderid] = order
def action(self, order): """""" url = '%s/' % (self.context.absolute_url()) props = getToolByName(self.context, 'portal_properties').pcommerce_properties props_paypal = getToolByName(self.context, 'portal_properties').paypal_properties portal_state = getMultiAdapter((self.context, self.context.REQUEST), name=u'plone_portal_state') lang = self.context.REQUEST.get('LANGUAGE', portal_state.default_language()) price = CurrencyAware(order.totalincl) interface = self.get_paypal_interface_obj() cart = IShoppingCart(self.context) cart_products = cart.getProducts() product_titles = [] for product in cart_products: product_titles.append(product['title'] + ' ') button_params = { 'BUTTONCODE': 'ENCRYPTED', 'BUTTONTYPE': 'BUYNOW', 'BUTTONSUBTYPE': 'SERVICES', 'BUYNOWTEXT': 'PAYNOW', 'L_BUTTONVAR0': 'notify_url=%s' % props_paypal.ipn_notify_url, 'L_BUTTONVAR1': 'amount=%.2f' % float(price.getRoundedValue()), 'L_BUTTONVAR2': 'item_name=%s' % "".join(product_titles), 'L_BUTTONVAR3': 'item_number=%s' % order.orderid, 'L_BUTTONVAR4': 'return=%s' % url + 'payment.success', 'L_BUTTONVAR5': 'cancel_return=%s' % url + 'payment.cancel', 'L_BUTTONVAR6': 'no_shipping=1', 'L_BUTTONVAR7': 'no_note=1', 'L_BUTTONVAR8': 'rm=1', 'L_BUTTONVAR11': 'currency_code=EUR' } response = interface.bm_create_button(**button_params) return response.EMAILLINK
def price(self): import logging v_uid = None product = aq_inner(self.context) if IVariation.providedBy(product): product = aq_parent(product) v_uid = self.context.UID() v_uids = self.request.get('v', '') v_uids = v_uids.split(',') v_uids = [uid for uid in v_uids if uid != ''] if not len(v_uids) and v_uid is not None: v_uids = [ v_uid, ] catalog = getToolByName(self.context, 'uid_catalog') variations = catalog(object_provides=IVariation.__identifier__, UID=v_uids) variations = [variation.getObject() for variation in variations] price = IPricing(product).getPrice(variations) return CurrencyAware(price)
def getProducts(self): """ returns list of products currently in the cart """ catalog = getToolByName(self.context, 'uid_catalog') portal_properties = getToolByName(self.context, 'portal_properties') use_view_action = portal_properties.site_properties.getProperty( 'typesUseViewActionInListings', ()) products = [] for uid, amount in self.items(): results = [ product.getObject() for product in catalog( object_provides=interfaces.IProduct.__identifier__, UID=uid) ] if results: variations = [] variations_raw = [] product = None for result in results: if interfaces.IVariation.providedBy(result): variations_raw.append(result) variation = { 'type': result.getType(), 'name': result.Title(), 'no': result.getNo(), 'add_price': None, 'add_price_raw': None, 'uid': result.UID(), 'object': result } if result.getAddPrice(): variation['add_price_raw'] =\ float(result.getPrice()) variation['add_price'] =\ CurrencyAware(result.getPrice()) variations.append(variation) if not product: product = aq_parent(result) else: product = result url = product.absolute_url() if product.portal_type in use_view_action: product_url = url + '/view' else: product_url = url price = interfaces.IPricing(product).getPrice(variations_raw) products.append({ 'title': product.Title(), 'no': product.getNo(), 'description': product.Description(), 'price': CurrencyAware(price), 'price_raw': price, 'price_total': CurrencyAware(price * amount), 'price_total_raw': price * amount, 'uid': product.UID(), 'amount': amount, 'url': product_url, 'image_url': url, 'variations': variations, 'object': product }) return products
def base_price(self): if IVariation.providedBy(self.context): return CurrencyAware(IPricing(self.product).getBasePrice([aq_inner(self.context),])) return CurrencyAware(IPricing(self.product).getBasePrice())
def _totalincl_converter(self, value, order): return CurrencyAware(value).valueToString()
def price(self): return CurrencyAware(self.cart.getPrice())
def send(self, orderid, lang=None): """ sends an order """ request = self.context.REQUEST if not self.has_key(orderid): return order = self[orderid] if order.state >= SENT: if order.orderid == request.SESSION.get(ORDER_SESSION_KEY, 0): request.SESSION.set(ORDER_SESSION_KEY, None) return portal_state = getMultiAdapter((self.context, request), name=u'plone_portal_state') address = order.address shipments = [] shipments_customer = [] product_shipment = {} id_shipment = {} i = 1 for shipmentid, products in order.shipmentids.items(): shipment = getAdapter(self.context, name=shipmentid, interface=interfaces.IShipmentMethod) info = translate(shipment.mailInfo(order), context=request, target_language=lang) if len(order.shipmentids) > 1: info = '(%s) %s' % (i, info) shipments.append(info) info_customer = translate(shipment.mailInfo(order, lang, customer=True), context=request, target_language=lang) if len(order.shipmentids) > 1: info = '(%s) %s' % (i, info_customer) shipments_customer.append(info_customer) for product in products: product_shipment[product] = i id_shipment[shipmentid] = {'title': shipment.title, 'number': i} i += 1 payment = getAdapter(self.context, name=order.paymentid, interface=interfaces.IPaymentMethod) alignment = Alignment() cart = [] cart.append([ translate(_('Product'), context=request, target_language=lang), translate(_('Amount'), context=request, target_language=lang), translate(_('Price'), context=request, target_language=lang), translate(_('Price total'), context=request, target_language=lang) ]) cart.extend(['-', '']) for product in order.products: cart.append([ len(order.shipmentids) > 1 and '%s (%s)' % (product[1], product_shipment[product[0]]) or product[1], str(product[3]), ">" + CurrencyAware(product[4]).valueToString(order.currency), ">" + CurrencyAware(product[4] * product[3]).valueToString( order.currency) ]) cart.append(product[2].decode('utf-8')) for variation in product[5]: cart.append("\t%s: %s" % (variation[1].decode('utf-8'), variation[2].decode('utf-8'))) cart.append("") cart.append('-') cart.append([ '%s:' % translate(_('Total'), context=request, target_language=lang), '', '', ">" + CurrencyAware(order.price).valueToString(order.currency) ]) cart.extend(['-', '']) if order.pretaxcharge: if order.paymentdata.pretaxcharge: cart.append([ '%s:' % translate( payment.title, context=request, target_language=lang), '', '', ">" + CurrencyAware( order.paymentdata.pretaxcharge).valueToString( order.currency) ]) for shipmentid, data in order.shipmentdata.items(): if data.pretaxcharge: cart.append([ '%s:' % (len(order.shipmentids) > 1 and '%s (%s)' % (translate(id_shipment[shipmentid]['title'], context=request, target_language=lang), id_shipment[shipmentid]['number']) or translate(id_shipment[shipmentid]['title'], context=request, target_language=lang)), '', '', ">" + CurrencyAware(data.pretaxcharge).valueToString( order.currency) ]) for charge in order.pretaxcharges: if charge.price: cart.append([ '%s:' % translate(charge.title, context=request, target_language=lang), '', '', ">" + CurrencyAware(charge.price).valueToString( order.currency) ]) cart.append('-') cart.append([ '%s:' % translate(_('Total incl. charges'), context=request, target_language=lang), '', '', ">" + CurrencyAware(order.subtotal).valueToString(order.currency) ]) cart.extend(['-', '']) if order.tax: cart.append([ order.taxname, '', '', '%(pricetax)s (%(tax)s %% - %(zone)s)' % dict(tax=order.tax, pricetax=">" + CurrencyAware( order.pricetax).valueToString(order.currency), zone=address.zone) ]) cart.append('-') cart.append([ '%s:' % translate(_('Total incl. ${taxname}', mapping=dict(taxname=order.taxname)), context=request, target_language=lang), '', '', ">" + CurrencyAware(order.total).valueToString(order.currency) ]) cart.extend(['-', '']) if order.taxincl and order.posttaxcharge is None: cart.append([ order.taxname, '', '', '%(pricetax)s (%(tax)s %% - %(zone)s)' % dict(tax=order.tax, pricetax=">" + CurrencyAware( order.pricetax).valueToString(order.currency), zone=address.zone) ]) cart.append('-') cart.append([ '%s:' % translate(_('Total incl. ${tax}% ${taxname}', mapping=dict(tax=order.taxincl, taxname=order.taxinclname)), context=request, target_language=lang), '', '', ">" + CurrencyAware(order.totalincl).valueToString(order.currency) ]) cart.extend(['-', '']) if order.posttaxcharge: if order.paymentdata.posttaxcharge: cart.append([ '%s:' % translate( payment.title, context=request, target_language=lang), '', '', ">" + CurrencyAware( order.paymentdata.posttaxcharge).valueToString( order.currency) ]) for shipmentid, data in order.shipmentdata.items(): if data.posttaxcharge: cart.append([ '%s:' % (len(order.shipmentids) > 1 and '%s (%s)' % (translate(id_shipment[shipmentid]['title'], context=request, target_language=lang), id_shipment[shipmentid]['number']) or translate(id_shipment[shipmentid]['title'], context=request, target_language=lang)), '', '', ">" + CurrencyAware(data.posttaxcharge).valueToString( order.currency) ]) for charge in order.posttaxcharges: if charge.price: cart.append([ '%s:' % translate(charge.title, context=request, target_language=lang), '', '', ">" + CurrencyAware(charge.price).valueToString( order.currency) ]) cart.append('-') if order.tax: cart.append([ '%s:' % translate(_('Total incl. charges and ${taxname}', mapping=dict(taxname=order.taxname)), context=request, target_language=lang), '', '', ">" + CurrencyAware(order.totalincl).valueToString( order.currency) ]) elif order.taxincl: cart.append([ '%s:' % translate(_('Total incl. charges and ${tax}% ${taxname}', mapping=dict(tax=order.taxincl, taxname=order.taxinclname)), context=request, target_language=lang), '', '', ">" + CurrencyAware(order.totalincl).valueToString( order.currency) ]) else: cart.append([ '%s:' % translate(_('Total incl. charges'), context=request, target_language=lang), '', '', ">" + CurrencyAware(order.totalincl).valueToString( order.currency) ]) cart.extend(['-', '']) alignment.extend(cart) # do alignment cart = alignment.alignItems(cart) email_from = getToolByName( self.context, 'portal_properties').pcommerce_properties.getProperty( 'email_address', '') if not email_from: email_from = portal_state.portal().getProperty( 'email_from_address', '') email_from_name = portal_state.portal().getProperty( 'email_from_name', '') mapping = { 'orderid': order.orderid, 'shipments': '\n\n'.join(shipments), 'payment': translate(payment.mailInfo(order, lang), context=request, target_language=lang), 'cart': '\n'.join(cart), 'currency': order.currency, 'address': address.mailInfo(request, lang), 'name': address.firstname + ' ' + address.lastname, 'from_name': email_from_name, 'from_email': email_from } mailhost = getToolByName(self.context, 'MailHost') mailhost.secureSend( translate(self.getMessage(mapping), context=request, target_language=lang), mto=email_from, mfrom='%s <%s>' % (address.firstname + ' ' + address.lastname, address.email), subject=translate(_('email_order_title', default='New order [${orderid}]', mapping={'orderid': order.orderid}), context=request, target_language=lang), charset='utf-8') mapping.update({ 'shipments': '\n\n'.join(shipments_customer), 'payment': translate(payment.mailInfo(order, lang, customer=True), context=request, target_language=lang), 'address': address.mailInfo(request, lang, True) }) mailhost.secureSend( translate(self.getMessageCustomer(mapping), context=request, target_language=lang), mto='%s <%s>' % (address.firstname + ' ' + address.lastname, address.email), mfrom='%s <%s>' % (email_from_name, email_from), subject=translate(_('email_customer_title', default='Confirmation e-mail'), context=request, target_language=lang), charset='utf-8') notify(events.OrderSentEvent(self, order)) order.state = SENT if order.orderid == request.SESSION.get(ORDER_SESSION_KEY, 0): request.SESSION.set(ORDER_SESSION_KEY, None)
def price(self): if self.order: return CurrencyAware(self.order.price) return CurrencyAware(self.cart.getPrice())
def pricetaxincl(self): if self.order: return CurrencyAware(self.order.pricetaxincl) return None
def subtotal(self): if self.order.pretaxcharge: return CurrencyAware(self.order.subtotal) return None
def total(self): if self.order: return CurrencyAware(self.order.total) return None
def totalincl(self): if self.order.posttaxcharge: return CurrencyAware(self.order.totalincl) return None