def previous_label(self): for component in self.components: if hasattr(component, 'previous_label'): return component.previous_label if self.laststep: return _(u'Print') return _(u'Previous step')
def update(self): self.statusmessages = IStatusMessage(self.request) try: amount = int(self.request.get('cartAmount', 1)) except: self.statusmessages.addStatusMessage(_(u'Please specify an amount'), 'error') return self.added = self.removed = 0 adapter = IShoppingCart(self.context) if self.request.get('cartAdd', None): self.added += adapter.add(self.request.get('cartAdd', None), amount) elif self.request.get('cartVariation', None): self.added += adapter.addVariation(self.request.get('cartVariation', None), amount) if not self.added: self.statusmessages.addStatusMessage(_(u'Please select a variation'), 'error') elif self.request.get('cartRemove', None): self.removed -= adapter.remove(self.request.get('cartRemove', None), self.request.get('cartRemoveAmount', None)) elif self.request.get('cartEdit', None): a, r = adapter.edit(self.request.get('cartEdit', None)) self.added += a self.removed += r self.addStatusMessages()
def next_label(self): for component in self.components: if hasattr(component, 'next_label'): return component.next_label if self.laststep: return _(u'Continue shopping') if self.stepid == len(self.steps) - 2: return _(u'Send order') return _(u'Next step')
def addStatusMessages(self): if self.added > 1: self.statusmessages.addStatusMessage(_(u'Added ${count} items to cart', mapping={'count': self.added}), 'info') elif self.added == 1: self.statusmessages.addStatusMessage(_(u'Added item to cart'), 'info') if self.removed > 1: self.statusmessages.addStatusMessage(_(u'Removed ${count} items from cart', mapping={'count': self.removed}), 'info') elif self.removed == 1: self.statusmessages.addStatusMessage(_(u'Removed item from cart'), 'info')
def __call__(self): self.request.set('disable_border', True) self.errors = {} props = getToolByName(self.context, 'portal_properties').pcommerce_properties if self.request.form.has_key('pcommerce_save'): adapter = ITaxes(self.context) taxes = [] raw = self.request.form.get('taxes', []) for tax in raw: if not tax.has_key('remove') or not tax['remove']: try: tax = {'id': tax['id'], 'tax': float(tax['tax']), 'zone': tax['zone'], 'taxname': tax['taxname']} if tax['zone'] == '': self.errors[tax['id']] = _(u'Please provide a zone name') elif tax['taxname'] == '': self.errors[tax['id']] = _(u'Please provide a tax name') if not self.errors.has_key(tax['id']): taxes.append(tax) except: self.errors[tax['id']] = _(u'Please enter a floating point number (e.g. 7.6)') for prop in self.properties: self.values[prop] = self.request.form.get(prop, '') taxincl = None tax = self.request.form.get('taxincl.tax', '') taxname = self.request.form.get('taxincl.taxname', '') try: if taxname == '' and tax != '': self.errors['taxincl'] = _(u'Please provide a tax name') else: if tax == '': tax = 0.0 taxincl = (float(tax), taxname) except: self.errors['taxincl'] = _(u'Please enter a floating point number (e.g. 7.6)') if not self.errors: adapter.edit(taxes) adapter.taxincl = taxincl IStatusMessage(self.request).addStatusMessage(_p('Properties saved'), 'info') for prop in self.properties: if prop == 'columns': self.values[prop] = int(self.values[prop]) props._setPropValue(prop, self.values[prop]) else: IStatusMessage(self.request).addStatusMessage(_p(u'Please correct the indicated errors'), 'error') for prop in self.properties: self.values[prop] = props.getProperty(prop, '') return self.template()
def order_fields(self): """Fields and fieldnames to show in tables (order overviews / details). { 'field_id': '', 'field_name': _("label_", default=""), 'sortable': True }, """ fields = [ { 'field_id': 'orderid', 'field_name': _("label_order_id", default="Order id"), 'sortable': True }, { 'field_id': 'userid', 'field_name': _("label_user_id", default="User id"), 'sortable': True }, { 'field_id': 'date', 'field_name': _("label_date", default="Date"), 'sortable': True }, { 'field_id': 'currency', 'field_name': _("label_currency", default="Currency"), 'sortable': True }, { 'field_id': 'totalincl', 'field_name': _("label_price_total", default="Price total"), 'field_converter': self._totalincl_converter, 'sortable': True }, { 'field_id': 'state', 'field_name': _("label_order_state", default="Order status"), 'sortable': True }, { 'field_id': 'zone', 'field_name': _("label_zone", default="Zone"), 'field_converter': self._zone_converter, 'sortable': True }, { 'field_id': 'address', 'field_name': _("label_address", default="Address"), 'field_converter': self._address_converter, 'sortable': True }, { 'field_id': 'products', 'field_name': _("label_products", default="Products"), 'field_converter': self._products_converter, 'sortable': False }, { 'field_id': 'shipmentids', 'field_name': _("label_shipmentids", default="Shipment id's"), 'field_converter': self._shipmentids_converter, 'sortable': False }, ] return fields
def _translate_order_status_id(self, status_id): """ """ order_status_string = { 1: _('label_initialized', default="Initialized"), 2: _('label_sent', default="Sent"), 3: _('label_processed', default="Processed"), 4: _('label_failed', default="Failed"), 5: _('label_cancelled', default="Cancelled"), } return order_status_string[status_id]
def __call__(self): self.errors = {} if self.request.form.get('stock.submitted', None) is not None: from Products.statusmessages.interfaces import IStatusMessage statusmessage = IStatusMessage(self.request) if self.store(): statusmessage.add(_(u'Stock information successfully stored')) return self.request.RESPONSE.redirect('%s/@@stock' % self.context.absolute_url()) else: statusmessage.add(_(u'Failed to save some stock information'), u'error') return self.template()
def validate(self): self.errors = {} valid = True for shipmentids, products in self._shipmentgroups().items(): if len(shipmentids) > 1: key = tuple([p.UID() for p in products]) if not self.selection.has_key(key): self.errors[shipmentids] = _(u'Please select a shipment method.') valid = False elif not self.selection[key] in shipmentids: self.errors[shipmentids] = _(u'Please select a shipment method.') valid = False return valid
def getMessageCustomer(self, mapping): return _('email_customer_body', default=\ """Dear ${name} Your order has been successfully registered. Please find a complete overview of your order below. Order ID: ${orderid} ${cart} Currency: ${currency} Address: ${address} Payment: ${payment} Shipment: ${shipments} If you have any questions concerning your purchase do not hesitate to contact us at ${from_email}. Best regards ${from_name}""", mapping=mapping)
def __call__(self): registry = IOrderRegistry(self.context) cart = getMultiAdapter((self.context, self.request), name='cart') if cart.outofstock: statusmessage = IStatusMessage(self.request) statusmessage.addStatusMessage(_(u'You have items in your cart, which are either out of stock or of which are not enough available in stock. Please adjust your cart to proceed.'), 'error') return self.request.RESPONSE.redirect('%s/@@cart' % self.context.absolute_url()) return super(Checkout, self).__call__()
def __call__(self): registry = IOrderRegistry(self.context) registry.fail(self.request.SESSION.get(ORDER_SESSION_KEY, 0)) statusmessage = IStatusMessage(self.request) statusmessage.addStatusMessage( _('message_checkout_failed', default=u'Check out failed'), 'error') return self.request.RESPONSE.redirect('%s/@@cart' % self.context.absolute_url())
def validate(self): self.errors = {} if self.request.form.get('gtc'): return True self.errors['gtc'] = _( 'The general terms and conditions have to be accepted to finish your check out.' ) return False
def mailInfo(self, order, lang=None, customer=False): data = order.paymentdata address = data.as_customer and order.address or data.address if customer: return _('invoice_mailinfo_customer', default="""Billing address ${address}""", mapping=dict(address=address.mailInfo(self.context.REQUEST, lang, customer))) else: return _('invoice_mailinfo', default="""Billing address ${address} To process the invoice payment click the following link ${link} To cancel the invoice payment process and fail the order click the following link ${link_failed}""", mapping=dict(address=address.mailInfo(self.context.REQUEST, lang, customer), link='%s/processInvoice?orderid=%s' % (self.context.absolute_url(), order.orderid), link_failed='%s/processInvoice?orderid=%s&failed=1' % (self.context.absolute_url(), order.orderid)))
def __call__(self): registry = IOrderRegistry(self.context) registry.fail(self.request.SESSION.get(ORDER_SESSION_KEY, 0)) statusmessage = IStatusMessage(self.request) statusmessage.addStatusMessage(_('message_checkout_failed', default=u'Check out failed'), 'error') return self.request.RESPONSE.redirect( '%s/@@cart' % self.context.absolute_url())
def steps(context): return ({ 'name': _('Address'), 'components': ('address', ) }, { 'name': _('Shipment'), 'components': ('shipments', ) }, { 'name': _('Shipment'), 'components': ('shipment', ) }, { 'name': _('Payment'), 'components': ('payments', ) }, { 'name': _('Payment'), 'components': ('payment', ) }, { 'name': _('Overview'), 'components': ( 'overview', 'gtc', ) }, { 'name': _('Confirmation'), 'components': ('confirmation', ) })
def __call__(self): order = IOrder(self.context) m = len(order.processed_steps) and max(order.processed_steps) or 0 order.processed_steps = tuple( [n for n in order.processed_steps if n != m]) statusmessage = IStatusMessage(self.request) statusmessage.addStatusMessage(_(u'Payment canceled'), 'error') return self.request.RESPONSE.redirect('%s/@@checkout?stepid=%s' % (self.context.absolute_url(), m))
def validate(self): self.error = None if len(self._payments()) == 1: return True id = self.request.form.get('payment_id') if id is not None and self._payments().has_key(id): return True self.error = _(u'Please select a payment method.') return False
def mailInfo(self, order, lang=None, customer=False): data = order.shipmentdata["pcommerce.shipment.swisspost"] address = data.as_customer and order.address or data.address return _( "swisspost_mailinfo", default="""SwissPost shipment address ${address}""", mapping=dict(address=address.mailInfo(self.context.REQUEST, lang, customer)), )
def __call__(self): order = IOrder(self.context) m = len(order.processed_steps) and max(order.processed_steps) or 0 order.processed_steps = tuple( [n for n in order.processed_steps if n != m]) statusmessage = IStatusMessage(self.request) statusmessage.addStatusMessage(_(u'Payment canceled'), 'error') return self.request.RESPONSE.redirect('%s/@@checkout?stepid=%s' % ( self.context.absolute_url(), m))
def steps(context): return ({'name':_('Address'), 'components':('address',)}, {'name':_('Shipment'), 'components':('shipments',)}, {'name':_('Shipment'), 'components':('shipment',)}, {'name':_('Payment'), 'components':('payments',)}, {'name':_('Payment'), 'components':('payment',)}, {'name':_('Overview'), 'components':('overview', 'gtc',)}, {'name':_('Confirmation'), 'components':('confirmation',)})
def _products_converter(self, value, order): rows = [] for product in value: cells = [str(i) for i in product[1:5]] cells.append(str(product[3]*product[4])) rows.append('</td><td>'.join(cells)) return ''' <table class="listing"> <thead> <tr><th>%s</th></tr> </thead> <tbody> <tr><td>%s</td></tr> </tbody> </table>''' % ('</th><th>'.join((translate(_(u'No'), context=self.request), translate(_(u'Product'), context=self.request), translate(_(u'Amount'), context=self.request), translate(_(u'Price'), context=self.request), translate(_(u'Price total'), context=self.request))), '</td></tr><tr><td>'.join(rows))
def __call__(self, orderid, failed=False): orderid = int(orderid) registry = IOrderRegistry(self.context) order = registry.getOrder(orderid) if order is not None and order.paymentid == 'pcommerce.payment.invoice': pre_state = order.state order.paymentdata.state = FAILED if failed or pre_state is FAILED else SUCCESS processor = IPaymentProcessor(self.context) result = processor.processOrder(orderid, 'pcommerce.payment.invoice') msg = (_('Processing the order failed'), 'error') if pre_state is config.PROCESSED or pre_state is config.FAILED: msg = (_('Order already processed'), 'error') elif failed and order.state is config.FAILED: msg = (_('Order successfully canceled'), 'info') elif not failed and order.state is config.PROCESSED: msg = (_('Order successfully processed'), 'info') self.request.response.redirect('%s/order-details?order_id=%s' % (self.context.absolute_url(), orderid)) else: msg = (_('Order not found'), 'error') self.request.response.redirect('%s/manage-orders' % self.context.absolute_url()) IStatusMessage(self.request).add(*msg)
def __call__(self): self.request.set('disable_border', 1) self.errors = {} self.cart = IShoppingCart(self.context) if not len(self.cart): statusmessage = IStatusMessage(self.request) statusmessage.addStatusMessage( _(u'You have not yet added any ' 'products to your cart'), 'error') return self.request.RESPONSE.redirect('%s/@@cart' % self.context.absolute_url()) if self.request.form.get('checkout.cancel', None): return getMultiAdapter((self.context, self.request), name=u'checkout.cancel')() self.stepid = int(self.request.form.get('checkout.stepid', 0)) temp_state = None registry = IOrderRegistry(self.context) self.order = registry.getOrder( self.request.SESSION.get(ORDER_SESSION_KEY, 0)) if self.order is not None and self.order.state != INITIALIZED: temp_state = self.order.state self.order.state = INITIALIZED self.order = IOrder(self.context) self._stepid_validator() if self.request.form.get('checkout.next') and \ self.stepid < len(self.steps) - 1: self.next() elif self.request.form.get('checkout.previous') and self.stepid > 0: self.previous() elif self.request.get('stepid'): self.gotostep(int(self.request.get('stepid', 0))) if self.redirect is not None: return self.request.RESPONSE.redirect(self.redirect) html = self.template() if temp_state is not None: self.order.state = temp_state if self.laststep: registry = IOrderRegistry(self.context) registry.send(self.order.orderid) self.cart.clear() return html
def __call__(self): self.request.set('disable_border', 1) self.errors = {} self.cart = IShoppingCart(self.context) if not len(self.cart): statusmessage = IStatusMessage(self.request) statusmessage.addStatusMessage(_(u'You have not yet added any ' 'products to your cart'), 'error') return self.request.RESPONSE.redirect('%s/@@cart' % self.context.absolute_url()) if self.request.form.get('checkout.cancel', None): return getMultiAdapter((self.context, self.request), name=u'checkout.cancel')() self.stepid = int(self.request.form.get('checkout.stepid', 0)) temp_state = None registry = IOrderRegistry(self.context) self.order = registry.getOrder(self.request.SESSION.get( ORDER_SESSION_KEY, 0)) if self.order is not None and self.order.state != INITIALIZED: temp_state = self.order.state self.order.state = INITIALIZED self.order = IOrder(self.context) self._stepid_validator() if self.request.form.get('checkout.next') and \ self.stepid < len(self.steps) - 1: self.next() elif self.request.form.get('checkout.previous') and self.stepid > 0: self.previous() elif self.request.get('stepid'): self.gotostep(int(self.request.get('stepid', 0))) if self.redirect is not None: return self.request.RESPONSE.redirect(self.redirect) html = self.template() if temp_state is not None: self.order.state = temp_state if self.laststep: registry = IOrderRegistry(self.context) registry.send(self.order.orderid) self.cart.clear() return html
def store(self): provider = IStock(self.context) stockable = self.stockable() for item in stockable: try: value = int(self.request.form.get(item['key'], 0)) if not item.has_key('objs'): provider.setStock(value) else: provider.setVariationStock(value, item['objs']) except: self.errors[item['key']] = _(u'There was an error when saving this stock entry') return len(self.errors) == 0
def mailInfo(self, request, lang=None, customer=False): address = [(self.salutation and translate((self.salutation == 'mr' and _('Mr.') or _('Mrs. / Ms.')), context=request, target_language=lang) +' ' or '') + self.firstname +' '+ self.lastname, self.company, self.address1, self.address2, self.zip + (self.zip is not None and ' ') + self.city, self.country, self.zone] address = [value for value in address if value] address.append('') address.append(self.email) if self.phone: address.append(self.phone) return '\n'.join(address)
def getMessage(self, mapping): return _('email_order_body', default=\ """New order by ${name} Orderid: ${orderid} ${cart} Currency: ${currency} Address: ${address} Payment: ${payment} Shipment: ${shipments} """, mapping=mapping)
def cancel_label(self): for component in self.components: if hasattr(component, 'cancel_label'): return component.cancel_label return _(u'Cancel checkout')
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 = 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)
from Products.Archetypes.public import * from Products.SingleKeywordWidget.widget import SingleKeywordWidget from pcommerce.core.content.product import Product, ProductSchema from pcommerce.core.interfaces import IVariation from pcommerce.core import PCommerceMessageFactory as _ from pcommerce.core.config import PROJECTNAME VariationSchema = Schema(( StringField(name='type', required=1, searchable=True, widget=SingleKeywordWidget( label=_(u'Type'), format='radio', )), BooleanField(name='addPrice', languageIndependent=True, widget=BooleanWidget(label=_(u'Additional price'), )), )) + ProductSchema.copy() VariationSchema['creators'].widget.visible = 0 VariationSchema.changeSchemataForField('no', 'overrides') VariationSchema.changeSchemataForField('text', 'overrides') VariationSchema.changeSchemataForField('relatedItems', 'overrides') VariationSchema.moveField('title', before='type') VariationSchema.moveField('addPrice', after='price') VariationSchema.moveField('effectiveDate', after='imageCaption') VariationSchema.moveField('expirationDate', after='effectiveDate')
def mailInfo(self, order, lang=None, customer=False): return _('paypal_mailinfo', default=u"Payment processed over Paypal")
from Products.CMFCore.permissions import View from Products.ATContentTypes.content.document import ATDocumentBase, ATDocumentSchema from pcommerce.core.interfaces import IProduct from pcommerce.core import PCommerceMessageFactory as _ from pcommerce.core.config import PROJECTNAME from Products.CMFPlone.interfaces import INonStructuralFolder from Products.CMFPlone import PloneMessageFactory as _p from zope.schema.interfaces import IVocabularyFactory ProductSchema = ATDocumentSchema.copy() + Schema(( StringField(name='no', searchable=1, widget=StringWidget(label=_('No'), )), FixedPointField(name='price', languageIndependent=True, widget=DecimalWidget(label=_(u'Price'), )), BooleanField(name='new', languageIndependent=True, widget=BooleanWidget(label=_(u'New product'), )), BooleanField(name='hot', languageIndependent=True, widget=BooleanWidget(label=_(u'Hot product'), )), LinesField(name='shipments', required=True, multiValued=True, widget=MultiSelectionWidget( label=_(u'label_shipment_methods', default=u'Shipment methods'),
def mailInfo(self, order, lang=None, customer=False): data = order.shipmentdata['pcommerce.shipment.parcel'] address = data.as_customer and order.address or data.address return _('parcel_mailinfo', default="""parcel shipment address ${address}""", mapping=dict(address=address.mailInfo(self.context.REQUEST, lang, customer)))
def mailInfo(self, order, lang=None, customer=False): return _('Instantly setup after successful payment')
class PaypalPayment(object): implements(IPaymentMethod, IPaypalPayment) adapts(Interface) title = _(u'Paypal') description = _('Payment using Paypal') icon = u'++resource++pcommerce_payment_paypal_icon.gif' logo = u'++resource++pcommerce_payment_paypal_logo.gif' def __init__(self, context): self.context = context self.props = getToolByName(self.context, 'portal_properties').paypal_properties def __getattr__(self, name): if self.props.hasProperty(name): return self.props.getProperty(name) raise AttributeError def mailInfo(self, order, lang=None, customer=False): return _('paypal_mailinfo', default=u"Payment processed over Paypal") def verifyPayment(self, order): """""" # TODO: Done before, not yet needed return True def get_paypal_interface_obj(self): context = self.context props = getToolByName(context, 'portal_properties').paypal_properties #TODO: Need to be moved in configlet with description # Enter your test account's API details here. You'll need the 3-token # credentials, not the certificate stuff. #CONFIG = PayPalConfig(API_USERNAME = "******", # API_PASSWORD = "******", # API_SIGNATURE = "AuyTYUFGIfqpMeM0seVte", # DEBUG_LEVEL=0) CONFIG = PayPalConfig(API_USERNAME=props.api_username, API_PASSWORD=props.api_password, API_SIGNATURE=props.api_signature, API_ENVIRONMENT=props.test and 'SANDBOX' or 'PRODUCTION', DEBUG_LEVEL=0) return PayPalInterface(config=CONFIG) 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
from zope.interface import implements from Products.Archetypes.public import * from pcommerce.core.interfaces import IPrice from pcommerce.core import PCommerceMessageFactory as _ from pcommerce.core.config import PROJECTNAME PriceSchema = BaseContent.schema.copy() + Schema(( FixedPointField( name='price', required=1, languageIndependent=True, widget=DecimalWidget( label=_(u'Price'), ) ), )) for field in ('description', 'creators','allowDiscussion','contributors','location','subject','language','rights','title',): if PriceSchema.has_key(field): PriceSchema[field].widget.visible = 0 PriceSchema['title'].required = False class Price(BaseContent): """ A Price """ implements(IPrice)
def mailInfo(self, order, lang=None, customer=False): return _('Goods are picked up by the customer')
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 mailInfo(self, order, lang=None, customer=False): return _('docdata_mailinfo', default=u"Payment processed over Docdata")
class Assignment(base.Assignment): implements(IShoppingCartPortlet) title = _(u'Shopping cart')
def __call__(self): self.request.set('disable_border', True) self.errors = {} props = getToolByName(self.context, 'portal_properties').pcommerce_properties if self.request.form.has_key('pcommerce_save'): adapter = ITaxes(self.context) taxes = [] raw = self.request.form.get('taxes', []) for tax in raw: if not tax.has_key('remove') or not tax['remove']: try: tax = { 'id': tax['id'], 'tax': float(tax['tax']), 'zone': tax['zone'], 'taxname': tax['taxname'] } if tax['zone'] == '': self.errors[tax['id']] = _( u'Please provide a zone name') elif tax['taxname'] == '': self.errors[tax['id']] = _( u'Please provide a tax name') if not self.errors.has_key(tax['id']): taxes.append(tax) except: self.errors[tax['id']] = _( u'Please enter a floating point number (e.g. 7.6)') for prop in self.properties: self.values[prop] = self.request.form.get(prop, '') taxincl = None tax = self.request.form.get('taxincl.tax', '') taxname = self.request.form.get('taxincl.taxname', '') try: if taxname == '' and tax != '': self.errors['taxincl'] = _(u'Please provide a tax name') else: if tax == '': tax = 0.0 taxincl = (float(tax), taxname) except: self.errors['taxincl'] = _( u'Please enter a floating point number (e.g. 7.6)') if not self.errors: adapter.edit(taxes) adapter.taxincl = taxincl IStatusMessage(self.request).addStatusMessage( _p('Properties saved'), 'info') for prop in self.properties: if prop == 'columns': self.values[prop] = int(self.values[prop]) props._setPropValue(prop, self.values[prop]) else: IStatusMessage(self.request).addStatusMessage( _p(u'Please correct the indicated errors'), 'error') for prop in self.properties: self.values[prop] = props.getProperty(prop, '') return self.template()
from AccessControl import ClassSecurityInfo from zope.interface import implements from Products.Archetypes.public import * from pcommerce.core.interfaces import IPrice from pcommerce.core import PCommerceMessageFactory as _ from pcommerce.core.config import PROJECTNAME PriceSchema = BaseContent.schema.copy() + Schema( (FixedPointField(name='price', required=1, languageIndependent=True, widget=DecimalWidget(label=_(u'Price'), )), )) for field in ( 'description', 'creators', 'allowDiscussion', 'contributors', 'location', 'subject', 'language', 'rights', 'title', ): if PriceSchema.has_key(field): PriceSchema[field].widget.visible = 0