eggification
[Portfolio.git] / Products / Portfolio / skins / shipping_set_control.py
diff --git a/Products/Portfolio/skins/shipping_set_control.py b/Products/Portfolio/skins/shipping_set_control.py
new file mode 100755 (executable)
index 0000000..64db789
--- /dev/null
@@ -0,0 +1,30 @@
+##parameters=**kw
+from Products.Portfolio.utils import translate
+_ = lambda msg : translate(msg, context)
+
+kg = lambda name : kw.get(name, '').strip()
+
+mandatoryFields = [
+         ('shipping_fullname', _('Please enter a name.'))
+       , ('shipping_address', _('Please enter an address.'))
+       , ('shipping_city', _('Please enter a city.'))
+       , ('shipping_zipcode', _('Please enter zip code.'))
+       , ('shipping_country', _('Please enter a country.'))
+       ]
+
+shippingInfo = {}
+for name, failMessage in mandatoryFields :
+       value = kg(name)
+       shippingInfo[name] = value
+       if not value :
+               return context.setStatus(False, failMessage)
+
+session = context.REQUEST.SESSION
+sg = session.get
+cart = sg('cart', None)
+
+if cart is None :
+       return context.setStatus(False, _('No cart found. Your session may have expired.'))
+
+cart.setShippingInfo(**shippingInfo)
+return context.setStatus(True, _('Shipping informations saved.'))
\ No newline at end of file