Commit f8d073aa authored by Ivan Tyagov's avatar Ivan Tyagov

Make use of RAM based Sale Order object together with portal_sessions tool.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12557 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 75aff128
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.ERP5Type.Tool.SessionTool</string>
<string>SessionTool</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>portal_sessions</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>uid</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>BTrees.Length</string>
<string>Length</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<tuple>
<string>BTrees.OOBTree</string>
<string>OOBTree</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<tuple>
<tuple>
<string>BTrees.OOBTree</string>
<string>OOBTree</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
......@@ -1510,7 +1510,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Commerce for ERP5</string> </value>
<value> <string>Commerce for ERP5 - using temp</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -70,31 +70,32 @@
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from Products.ERP5Type.Document import newTempOrderLine\n
quantity = int(context.REQUEST.get(\'field_my_buy_quantity\', 1))\n
shopping_cart = context.SaleOrder_getShoppingCart()\n
shopping_cart_items = context.SaleOrder_getShoppingCartItemList()\n
\n
if product is None:\n
product = context\n
\n
## check if we don\'t have already such a product in cart\n
line_found=False\n
for order_line in shopping_cart:\n
if order_line[\'resource\'] == product.getRelativeUrl():\n
new_quantity = int(order_line[\'quantity\']) + quantity\n
for order_line in shopping_cart_items:\n
if order_line.getResource() == product.getRelativeUrl():\n
new_quantity = int(order_line.getQuantity()) + quantity\n
if new_quantity<=0:\n
## remove items with zero quantity\n
del shopping_cart[indexof(order_line)]\n
shopping_cart.manage_delObjects(order_line)\n
else:\n
order_line[\'quantity\'] = new_quantity\n
order_line.setQuantity(new_quantity)\n
line_found=True\n
break\n
\n
if line_found == False:\n
## new Resource so add it to shopping cart\n
tmp = {}\n
tmp[\'resource\'] = product.getRelativeUrl()\n
tmp[\'quantity\'] = quantity\n
shopping_cart.append(tmp)\n
order_line = shopping_cart.newContent(portal_type=\'Sale Order Line\')\n
order_line.setResource(product.getRelativeUrl())\n
order_line.setQuantity(quantity)\n
\n
translateString = context.Base_translateString\n
context.Base_redirect(\'view\', \\\n
......@@ -144,22 +145,21 @@ context.Base_redirect(\'view\', \\\n
<value>
<tuple>
<string>product</string>
<string>Products.ERP5Type.Document</string>
<string>newTempOrderLine</string>
<string>int</string>
<string>_getattr_</string>
<string>context</string>
<string>quantity</string>
<string>shopping_cart</string>
<string>shopping_cart_items</string>
<string>None</string>
<string>False</string>
<string>line_found</string>
<string>_getiter_</string>
<string>order_line</string>
<string>_getitem_</string>
<string>new_quantity</string>
<string>_write_</string>
<string>indexof</string>
<string>True</string>
<string>tmp</string>
<string>translateString</string>
<string>dict</string>
</tuple>
......
......@@ -206,10 +206,10 @@
<key> <string>_body</string> </key>
<value> <string>translateString = context.Base_translateString\n
shopping_cart_items = context.SaleOrder_getShoppingCartItemList()\n
shopping_cart = shopping_cart_items\n
shopping_cart = context.SaleOrder_getShoppingCart()\n
\n
if field_my_order_line_id is not None:\n
del shopping_cart_items[int(field_my_order_line_id)]\n
shopping_cart.manage_delObjects(field_my_order_line_id)\n
portal_status_message = "Successfully removed from shopping cart."\n
else:\n
portal_status_message = "Please select an item."\n
......@@ -278,8 +278,6 @@ context.Base_redirect(\'SaleOrder_viewAsWeb\', \\\n
<string>shopping_cart_items</string>
<string>shopping_cart</string>
<string>None</string>
<string>_write_</string>
<string>int</string>
<string>portal_status_message</string>
<string>dict</string>
</tuple>
......
......@@ -68,9 +68,8 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n
<value> <string>""" Add resource to current (or to be created shopping cart). """\n
\n
now = DateTime()\n
request = context.REQUEST\n
expire_timeout_days = 90\n
session_id = request.get(\'session_id\', None)\n
......@@ -78,6 +77,8 @@ portal_sessions = context.portal_sessions\n
\n
if session_id is None:\n
## first call so generate session_id and send back via cookie\n
from DateTime import DateTime\n
now = DateTime()\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
\n
......@@ -91,10 +92,17 @@ else:\n
## take shopping cart for this customer\n
shopping_cart_id = \'shopping_cart\'\n
session = portal_sessions[session_id]\n
if not portal_sessions.has_key(session_id, shopping_cart_id):\n
session[shopping_cart_id] = []\n
temp_container = portal_sessions #context.getPortalObject().temp_shopping_cart\n
if not shopping_cart_id in session.keys():\n
from Products.ERP5Type.Document import newTempOrder\n
shopping_cart = newTempOrder(temp_container, shopping_cart_id)\n
shopping_cart = portal_sessions.removeAq(shopping_cart)\n
session[shopping_cart_id] = shopping_cart\n
\n
## return just a part of session for shopping cart\n
return session[shopping_cart_id]\n
shopping_cart = session[shopping_cart_id]\n
shopping_cart = portal_sessions.addAq(session[shopping_cart_id], temp_container)\n
return shopping_cart\n
</string> </value>
</item>
<item>
......@@ -113,6 +121,14 @@ else:\n
<key> <string>_params</string> </key>
<value> <string>action = \'\', new_shopping_cart=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
......@@ -139,8 +155,6 @@ else:\n
<tuple>
<string>action</string>
<string>new_shopping_cart</string>
<string>DateTime</string>
<string>now</string>
<string>_getattr_</string>
<string>context</string>
<string>request</string>
......@@ -148,9 +162,15 @@ else:\n
<string>None</string>
<string>session_id</string>
<string>portal_sessions</string>
<string>DateTime</string>
<string>now</string>
<string>shopping_cart_id</string>
<string>_getitem_</string>
<string>session</string>
<string>temp_container</string>
<string>Products.ERP5Type.Document</string>
<string>newTempOrder</string>
<string>shopping_cart</string>
<string>_write_</string>
</tuple>
</value>
......
......@@ -68,7 +68,7 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>return context.SaleOrder_getShoppingCart()\n
<value> <string>return context.SaleOrder_getShoppingCart().objectValues()\n
</string> </value>
</item>
<item>
......
......@@ -69,13 +69,15 @@
<item>
<key> <string>_body</string> </key>
<value> <string>total = 0.0\n
currency = \'\'\n
currency = None\n
\n
shopping_cart_items = context.SaleOrder_getShoppingCartItemList()\n
for order_line in shopping_cart_items:\n
resource = context.restrictedTraverse(order_line[\'resource\'])\n
total += resource.getPrice() * order_line[\'quantity\']\n
currency = context.restrictedTraverse(resource.getSupplyLinePriceCurrency())\n
resource = context.restrictedTraverse(order_line.getResource())\n
total += resource.getPrice() * order_line.getQuantity()\n
if currency is None:\n
## calculate currency only once for Sale Order\n
currency = context.restrictedTraverse(resource.getSupplyLinePriceCurrency())\n
\n
if include_currency:\n
return \'%s %s\' %(total, currency.getTitle())\n
......@@ -133,13 +135,13 @@ else:\n
<tuple>
<string>include_currency</string>
<string>total</string>
<string>None</string>
<string>currency</string>
<string>_getattr_</string>
<string>context</string>
<string>shopping_cart_items</string>
<string>_getiter_</string>
<string>order_line</string>
<string>_getitem_</string>
<string>resource</string>
<string>str</string>
</tuple>
......
......@@ -208,7 +208,7 @@
translateString = context.Base_translateString\n
shopping_cart_items = context.SaleOrder_getShoppingCartItemList()\n
shopping_cart = shopping_cart_items\n
shopping_cart = context.SaleOrder_getShoppingCart()\n
quantity = field_my_buy_quantity \n
\n
## when we have one item in shoppping cart we get \n
......@@ -220,10 +220,10 @@ counter = 0\n
for order_line in shopping_cart_items:\n
new_quantity = int(quantity[counter])\n
if new_quantity>=1:\n
order_line[\'quantity\'] = new_quantity\n
order_line.setQuantity(new_quantity)\n
else:\n
## remove it from shopping cart\n
del shopping_cart_items[counter]\n
shopping_cart.manage_delObjects(order_line.getId())\n
counter += 1\n
\n
## update back cache so we have consistent results between cache plugins\n
......@@ -300,7 +300,6 @@ context.Base_redirect(\'SaleOrder_viewAsWeb\', \\\n
<string>int</string>
<string>_getitem_</string>
<string>new_quantity</string>
<string>_write_</string>
<string>dict</string>
</tuple>
</value>
......
......@@ -427,12 +427,7 @@
<item>
<key> <string>portal_types</string> </key>
<value>
<list>
<tuple>
<string>Cache factory</string>
<string>Cache factory</string>
</tuple>
</list>
<list/>
</value>
</item>
<item>
......@@ -461,7 +456,7 @@
</item>
<item>
<key> <string>selection_name</string> </key>
<value> <string>cache_tool_cache_list_selection</string> </value>
<value> <string>session_tool_session_list_selection</string> </value>
</item>
<item>
<key> <string>sort</string> </key>
......
......@@ -67,18 +67,17 @@
</thead>\n
<tbody> \n
<tal:block tal:repeat="order_line shopping_cart_items">\n
<tr tal:define="resource python: website.restrictedTraverse(order_line[\'resource\']);\n
quantity python: int(order_line[\'quantity\']);\n
<tr tal:define="resource python: website.restrictedTraverse(order_line.getResource());\n
quantity python: int(order_line.getQuantity());\n
price python: resource.getPrice();\n
order_line_id python: shopping_cart_items.index(order_line);\n
order_line_id python: order_line.getId();\n
currency python: here.restrictedTraverse(resource.getSupplyLinePriceCurrency()).getTitle()"> \n
<td align="right">\n
<a href="" tal:attributes="href resource/absolute_url">\n
<b tal:content="resource/getTitle"/> <br/>\n
<a tal:condition="not: confirm_mode"\n
tal:attributes="href python: \'%s?field_my_order_line_id=%s\' \n
%(website.SaleOrder_deleteShoppingCartItem.absolute_url(), \n
order_line_id)"> \n
tal:attributes="href python: \'%s/SaleOrder_deleteShoppingCartItem?field_my_order_line_id=%s\' \n
%(here.absolute_url(), order_line_id)"> \n
Delete \n
</a>\n
</a>\n
......@@ -92,10 +91,10 @@
<span tal:condition="confirm_mode" tal:content="quantity"/>\n
</td>\n
<td align="right">\n
<span tal:replace="price"/><br/><span tal:replace="currency"/>\n
<span tal:replace="price"/> <span tal:replace="currency"/>\n
</td>\n
<td align="right">\n
<span tal:replace="python: price*quantity"/><br/><span tal:replace="currency"/>\n
<span tal:replace="python: price*quantity"/> <span tal:replace="currency"/>\n
</td>\n
</tr>\n
</tal:block>\n
......
......@@ -48,38 +48,38 @@
<key> <string>_text</string> </key>
<value> <string encoding="cdata"><![CDATA[
<tal:block tal:define="isAnon here/portal_membership/isAnonymousUser">\n
<p class="headlinkred">LOGIN STATUS</p>\n
\n
<tal:block tal:define="isAnon here/portal_membership/isAnonymousUser">\n
<tal:block tal:condition="isAnon">\n
<h4>You\'re not logged in.</h4>\n
I have an account:\n
<p class="article">You\'re not logged in.</p>\n
<p class="article">I have an account:</p>\n
<form action="WebSite_login">\n
<table>\n
<tr>\n
<td>Username:</td>\n
<td class="article">Username:</td>\n
<td><input name="__ac_name" size="10" tal:attributes="value python: request.get(\'__ac_name\') or \'\'"/></td>\n
</tr>\n
<tr>\n
<td>Password:</td>\n
<td class="article">Password:</td>\n
<td><input type="password" name="__ac_password" size="10"/></td>\n
</tr>\n
<tr>\n
<td><input type="hidden" name="came_from" tal:attributes="value here/absolute_url"/>\n
<input type="hidden" name="__ac_persistent" value="1"/>\n
<input type="submit" value="Login"/>\n
<input type="submit" value="Login" />\n
</td>\n
</tr>\n
</table>\n
</form>\n
\n
<a href="WebSite_newCustomerAccountForm"> I want to create an account</a>\n
<br/>\n
<a class="articlelink" href="WebSite_newCustomerAccountForm"> I want to create an account</a><br/>\n
\n
</tal:block>\n
\n
<tal:block tal:condition="not: isAnon">\n
<h4>Hello, <span tal:replace="here/portal_membership/getAuthenticatedMember"/></h4>\n
<a href="WebSite_logout"> Log out</a><br/>\n
<p class="article">Hello, <span tal:replace="here/portal_membership/getAuthenticatedMember"/></p>\n
<a class="articlelink" href="WebSite_logout"> Log out</a><br/>\n
</tal:block>\n
\n
</tal:block>
......
......@@ -48,36 +48,51 @@
<key> <string>_text</string> </key>
<value> <string encoding="cdata"><![CDATA[
<div>\n
<p class="headlinkred">SHOPPING CART</p>\n
\n
<table>\n
<tal:block tal:define="shopping_cart_items here/SaleOrder_getShoppingCartItemList;\n
empty_cart python: len(shopping_cart_items)==0;\n
website python: here.getWebSiteValue();">\n
\n
<ul tal:repeat="order_line shopping_cart_items">\n
<li tal:define="resource python: website.restrictedTraverse(order_line[\'resource\']);\n
quantity python: int(order_line[\'quantity\']);\n
<tr tal:repeat="order_line shopping_cart_items">\n
<td tal:define="resource python: website.restrictedTraverse(order_line.getResource());\n
quantity python: int(order_line.getQuantity());\n
price python: resource.getPrice();\n
currency python: here.restrictedTraverse(resource.getSupplyLinePriceCurrency()).getTitle()"> \n
\n
<a href="" tal:attributes="href resource/absolute_url">\n
<b tal:content="resource/getTitle"/> \n
</a>\n
<br/>\n
Price: <span tal:replace="price"/> <span tal:replace="currency"/>\n
<br/>\n
- quantity: <span tal:replace="quantity"/>\n
</li>\n
</ul> \n
<a class="articlelink" href="" tal:attributes="href resource/absolute_url">\n
<b tal:content="resource/getTitle"/>\n
</a>\n
<p class="article">\n
Price: <span tal:replace="price"/> <span tal:replace="currency"/><br/>\n
- quantity: <span tal:replace="quantity"/>\n
</p>\n
\n
\n
</td>\n
</tr> \n
\n
<tal:block tal:condition = "not: empty_cart">\n
<br/>\n
<b>Total price: <span tal:replace="python: here.SaleOrder_getShoppingCartTotalPrice(include_currency=True)"/> \n
</b>\n
<br/>\n
<a href="SaleOrder_viewAsWeb">Edit Shopping Cart</a><br/>\n
<a href="SaleOrder_confirmShopping">Proceed to checkout</a>\n
<tr><td><br/>\n
<p class="article">\n
<b>Total price: <span tal:replace="python: here.SaleOrder_getShoppingCartTotalPrice(include_currency=True)"/></b>\n
</p> \n
</td></tr>\n
<tr>\n
<td><a class="articlelink" href="SaleOrder_viewAsWeb">Edit Shopping Cart</a></td>\n
</tr>\n
<tr>\n
<td><a class="articlelink" href="SaleOrder_confirmShopping">Proceed to checkout</a></td>\n
</tr>\n
\n
</tal:block>\n
\n
</tal:block>
</tal:block>\n
</table>\n
\n
</div>
]]></string> </value>
</item>
......
31
\ No newline at end of file
39
\ No newline at end of file
portal_caches/erp5_session_cache
portal_caches/erp5_session_cache/**
\ No newline at end of file
portal_caches/erp5_session_cache/**
portal_sessions
\ No newline at end of file
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