Exemple #1
0
 def update(self):
     context = aq_inner(self.context)
     self.txnid = self.request.get('txnid', None)
     self.errors = {}
     unwanted = ('_authenticator', 'form.button.Submit',
                 'form.button.Enquiry')
     if ('form.button.Submit' in self.request
             or 'form.button.Enquiry' in self.request):
         form = self.request.form
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         formdata = {}
         formerrors = {}
         errorIdx = 0
         accept = self.request.get('terms-accept', None)
         if accept is None:
             errorIdx += 1
             formerrors['terms-accept'] = _(u"You need to accept that you "
                                            u"have read and understood the "
                                            u"terms of use.")
         for value in form:
             if value not in unwanted:
                 formdata[value] = form[value]
         formdata['enquiry'] = self.request.get('form.button.Enquiry', None)
         if errorIdx > 0:
             self.errors = formerrors
             IStatusMessage(self.request).add(
                 _(u"Required input missing"),
                 type='error')
         else:
             self._process_order(formdata)
Exemple #2
0
 def update(self):
     context = aq_inner(self.context)
     self.errors = {}
     unwanted = ('_authenticator', 'form.button.Submit')
     required = self.required_fields()
     if 'form.button.Submit' in self.request:
         form = self.request.form
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         formdata = {}
         formerrors = {}
         errorIdx = 0
         for value in form:
             if value not in unwanted:
                 formdata[value] = form[value]
                 if value in required and not form[value]:
                     error = {}
                     error['active'] = True
                     error['msg'] = _(u"This field is required")
                     formerrors[value] = error
                     errorIdx += 1
                 else:
                     error = {}
                     error['active'] = False
                     error['msg'] = form[value]
                     formerrors[value] = error
         if errorIdx > 0:
             self.errors = formerrors
         else:
             self._storeCheckoutData(formdata)
 def update(self):
     context = aq_inner(self.context)
     wipe_cart()
     self.context_url = context.absolute_url()
     IStatusMessage(self.request).addStatusMessage(
         _(u"Remove item from cart executed. This is not yet implemented"),
         type="info")
     redirect_url = self.context_url + '/@@cart'
     return self.request.response.redirect(redirect_url)
 def update(self):
     context = aq_inner(self.request)
     self.context_url = context.absolute_url()
     item = self.request.get('item.uuid', None)
     qty = self.request.get('quantity', None)
     IStatusMessage(self.request).addStatusMessage(
         _(u"Add item to cart executed: %s %s ") % (item, qty),
         type="info")
     redirect_url = self.context_url() + '/@@cart'
     return self.request.response.redirect(redirect_url)
 def update(self):
     context = aq_inner(self.context)
     #self.context_url = context.absolute_url()
     if 'form.button.Submit' in self.request:
         updater = getUtility(ICartUpdaterUtility)
         item_uuid = self.request.get('item_uuid', None)
         item = updater.delete(item_uuid)
         if not item:
             IStatusMessage(self.request).addStatusMessage(
                 _(u"Item could not be removed from the shopping cart. "
                   u"Please try again. If the error should persist, please "
                   u"contact the shop owner"),
                 type="error")
             return self.request.response.redirect(context.absolute_url())
         else:
             IStatusMessage(self.request).addStatusMessage(
                 _(u"Item has been removed from the shopping cart"),
                 type="info")
             return_url = context.absolute_url() + '/@@cart'
             return self.request.response.redirect(return_url)
 def update(self):
     context = aq_inner(self.context)
     self.context_url = context.absolute_url()
     pstate = getMultiAdapter((context, self.request),
                              name=u"plone_portal_state")
     self.portal_url = pstate.portal_url()
     self.uuid = IUUID(context, None)
     unwanted = ('_authenticator', 'form.button.Submit',
                 'form.button.Clear')
     if 'form.button.Clear' in self.request:
         authenticator = getMultiAdapter((context, self.request),
                                         name=u"authenticator")
         if not authenticator.verify():
             raise Unauthorized
         wipe_cart()
         IStatusMessage(self.request).addStatusMessage(
             _(u"Your shopping cart has successfully been purged"),
             type="info")
         return self.request.response.redirect(self.context_url)
     if 'form.button.Submit' in self.request:
         self.errors = {}
         item = self.request.get('item.uuid', None)
         quantity = self.request.get('item.quantity', None)
         form = self.request.form
         idx = 0
         for item in form:
             if item not in unwanted:
                 fieldname = item.split('.')
                 uuid = fieldname[0]
                 quantity = form[item]
                 if quantity is None or quantity is '':
                     self.errors[item] = _(u"Quantity must be given")
                 else:
                     updater = getUtility(ICartUpdaterUtility)
                     updater.add(uuid, quantity)
                     idx += 1
         IStatusMessage(self.request).add(
             _(u"%s cart items successfully updated") % idx,
             type="info")
         redirect_url = self.context_url + '/@@cart'
         return self.request.response.redirect(redirect_url)
Exemple #7
0
 def _storeCheckoutData(self, data):
     pstate = getMultiAdapter((self.context, self.request),
                              name=u"plone_portal_state")
     portal_url = pstate.portal_url()
     txn_id = self.get_txnid()
     cart = get_cart()
     address = cart['txn_id']
     order = address.values()[0]
     for item in data:
         order[item] = data[item]
     txn_data = {}
     txn_data[txn_id] = order
     updater = getUtility(ICartUpdaterUtility)
     updater.mark(txn_data)
     IStatusMessage(self.request).add(
         _(u"Billing address successfully updated"),
         type='info')
     success_url = portal_url + '/@@checkout?txnid=' + txn_id
     return self.request.response.redirect(success_url)
Exemple #8
0
 def _process_order(self, data):
     pstate = getMultiAdapter((self.context, self.request),
                              name=u"plone_portal_state")
     portal_url = pstate.portal_url()
     settings = self._payment_settings()
     cart = get_cart()
     txn = cart['txn_id']
     orderinfo = txn[self.txnid]
     txn_id = self._url_quote(self.txnid)
     success_url = portal_url + '/@@order-processed?oid=' + txn_id
     envelope_from = orderinfo['billing.email']
     if data['enquiry'] is None:
         order_type = _(u"order")
         subject_en = 'Chromsystems Shop: Your order'
         subject_de = 'Chromsystems Shop: Ihre Bestellung'
         mailto = ('*****@*****.**',
                   '*****@*****.**')
         cart_headline_en = _(u"Ordered products")
         cart_headline_de = _(u"Von Ihnen bestellte Produkte:")
     else:
         order_type = _(u"quotation inquiry")
         subject_en = 'Chromsystems Shop: Your quotation inquiry'
         subject_de = 'Chromsystems Shop: Ihre Angebotsanfrage'
         mailto = ('*****@*****.**',
                   '*****@*****.**')
         cart_headline_en = _(u"For the following products you will get a "
                              u"quotation:")
         cart_headline_de = _(u"Zu folgenden Produkten werden wir Ihnen "
                              u"umgehend ein Angebot unterbreiten:")
     mto = settings['shop_email']  # edit for alternative email
     options = orderinfo
     options['order_type'] = order_type
     options['language'] = self.current_lang()
     cart = self.cart()
     options['cartitems'] = cart
     if self.current_lang() == 'de':
         subject = subject_de
         options['cart_headline'] = cart_headline_de
         body = ViewPageTemplateFile("ordermail_de.pt")(self, **options)
         msg = ViewPageTemplateFile("customermail_de.pt")(self, **options)
     else:
         subject = subject_en
         options['cart_headline'] = cart_headline_en
         body = ViewPageTemplateFile("ordermail_en.pt")(self, **options)
         msg = ViewPageTemplateFile("customermail_en.pt")(self, **options)
     # send email
     mailhost = getToolByName(self.context, 'MailHost')
     for address in mailto:
         mailhost.send(body,
                       mto=address,
                       mfrom=envelope_from,
                       subject=subject,
                       charset='utf-8')
     # send order confirmation
     mailhost.send(msg,
                   mto=envelope_from,
                   mfrom=mto,
                   subject=subject,
                   charset='utf-8')
     IStatusMessage(self.request).add(
         _(u"Your email has been forwarded."),
         type='info')
     return self.request.response.redirect(success_url)