Commit 0bd9e1cc authored by Jean-Paul Smets's avatar Jean-Paul Smets Committed by Xiaowu Zhang

Implement shopping cart with temp portal types

Also improved comments and docstring including TODO.
parent 0cf1daab
...@@ -50,8 +50,16 @@ ...@@ -50,8 +50,16 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>""" \n <value> <string>"""\n
Add resource to current (or to be created shopping cart). \n Create a new shopping cart if needed. Return\n
shopping cart for current customer. Set all local roles\n
permissins so that shopping cart can be modified by anonymous.\n
\n
TODO:\n
- handle reset with another method\n
(more explicit, less risky)\n
- decide whether to keep or remove new_shopping_cart parameter\n
(is it really useful to create a new shopping cart here)\n
"""\n """\n
from DateTime import DateTime\n from DateTime import DateTime\n
\n \n
...@@ -61,28 +69,44 @@ session_id = request.get(\'session_id\', None)\n ...@@ -61,28 +69,44 @@ session_id = request.get(\'session_id\', None)\n
portal_sessions = context.portal_sessions\n portal_sessions = context.portal_sessions\n
\n \n
if session_id is None:\n if session_id is None:\n
## first call so generate session_id and send back via cookie\n # first call so generate session_id and send back via cookie\n
now = DateTime()\n now = DateTime()\n
session_id = context.Base_generateSessionID(max_long=20)\n session_id = context.Base_generateSessionID(max_long=20)\n
request.RESPONSE.setCookie(\'session_id\', session_id, expires=(now +expire_timeout_days).fCommon(), path=\'/\')\n request.RESPONSE.setCookie(\'session_id\', session_id, expires=(now +expire_timeout_days).fCommon(), path=\'/\')\n
\n \n
if action==\'reset\':\n if action==\'reset\':\n
## reset cart \n # reset cart and return (a separate method would be better XXX)\n
return portal_sessions.manage_delObjects(session_id)\n
\n
# take shopping cart for this customer\n
shopping_cart_id = \'shopping_cart\'\n
session = portal_sessions[session_id]\n
\n
# some cleanup could be required if the shopping cart\n
# comes from a previous user with same session\n
if shopping_cart_id in session.keys():\n
shopping_cart = session[shopping_cart_id]\n
if not shopping_cart.SaleOrder_isShoppingCartConsistent():\n
portal_sessions.manage_delObjects(session_id)\n portal_sessions.manage_delObjects(session_id)\n
else:\n
## take shopping cart for this customer\n
shopping_cart_id = \'shopping_cart\'\n
session = portal_sessions[session_id]\n session = portal_sessions[session_id]\n
if not shopping_cart_id in session.keys():\n \n
# create shopping cart\n
if not shopping_cart_id in session.keys():\n
from Products.ERP5Type.Document import newTempOrder\n from Products.ERP5Type.Document import newTempOrder\n
web_site = context.getWebSiteValue()\n web_site = context.getWebSiteValue()\n
shopping_cart = newTempOrder(portal_sessions, shopping_cart_id)\n shopping_cart = context.sale_order_module.newContent(portal_type="Sale Order", id=shopping_cart_id, temp_object=1, container=portal_sessions)\n
# Set usable security for Anonymous\n
shopping_cart.manage_role("Anonymous", ["Access contents information",\n
"Add portal content",\n
"Delete objects",\n
"Modify portal content",\n
"View"])\n
shopping_cart.setPriceCurrency(web_site.WebSite_getShoppingCartDefaultCurrency().getRelativeUrl())\n shopping_cart.setPriceCurrency(web_site.WebSite_getShoppingCartDefaultCurrency().getRelativeUrl())\n
session[shopping_cart_id] = shopping_cart\n session[shopping_cart_id] = shopping_cart\n
\n \n
## return just a part of session for shopping cart\n ## return just a part of session for shopping cart\n
shopping_cart = session[shopping_cart_id]\n shopping_cart = session[shopping_cart_id]\n
return shopping_cart\n return shopping_cart\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment