Commit bf6d7927 authored by Jérome Perrin's avatar Jérome Perrin

commerce: update session after modifying shopping cart content

when using a RAM cache for session, we can modify the temp objects directly
and the changes are kept, because the same object kept in RAM is accessed by
subsequent requests, but when using memcached every request get a different
object, so we need to put back the object in the session so that the new
version is saved in cache, so that subsequent requests use the modified object
parent 608635ea
...@@ -88,6 +88,9 @@ if not line_found: ...@@ -88,6 +88,9 @@ if not line_found:
method_id(category) method_id(category)
order_line.setPrice(context.getPrice(supply_path_type=["Sale Supply Line", "Sale Supply Cell"], context=order_line)) order_line.setPrice(context.getPrice(supply_path_type=["Sale Supply Line", "Sale Supply Cell"], context=order_line))
context.WebSection_updateShoppingCartTradeCondition(shopping_cart, None) context.WebSection_updateShoppingCartTradeCondition(shopping_cart, None)
context.getPortalObject().portal_sessions[session_id].update(shopping_cart=shopping_cart)
if checkout: if checkout:
website = context.getWebSiteValue() website = context.getWebSiteValue()
if website is not None: if website is not None:
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
- use Base_edit and a real ERP5 Form in order to benefit from - use Base_edit and a real ERP5 Form in order to benefit from
field reusability and property validation field reusability and property validation
""" """
translateString = context.Base_translateString portal = context.getPortalObject()
translateString = portal.Base_translateString
if field_my_buy_quantity is None: if field_my_buy_quantity is None:
field_my_buy_quantity = context.REQUEST.get("field_my_buy_quantity", None) field_my_buy_quantity = context.REQUEST.get("field_my_buy_quantity", None)
...@@ -44,7 +45,7 @@ if field_my_shipping_method not in ['', None]: ...@@ -44,7 +45,7 @@ if field_my_shipping_method not in ['', None]:
line = getattr(shopping_cart, 'shipping_method', None) line = getattr(shopping_cart, 'shipping_method', None)
if line is not None: if line is not None:
shopping_cart.manage_delObjects(line.getId()) shopping_cart.manage_delObjects(line.getId())
shipping = context.getPortalObject().restrictedTraverse(field_my_shipping_method) shipping = portal.restrictedTraverse(field_my_shipping_method)
# create new shipping method order line # create new shipping method order line
shopping_cart.newContent( shopping_cart.newContent(
id='shipping_method', id='shipping_method',
...@@ -57,7 +58,9 @@ if field_my_comment is not None: ...@@ -57,7 +58,9 @@ if field_my_comment is not None:
shopping_cart.setComment(field_my_comment) shopping_cart.setComment(field_my_comment)
context.WebSection_updateShoppingCartTradeCondition(shopping_cart, field_my_payment_mode, preserve=True) context.WebSection_updateShoppingCartTradeCondition(shopping_cart, field_my_payment_mode, preserve=True)
portal.portal_sessions[container.REQUEST['session_id']].update(shopping_cart=shopping_cart)
if redirect: if redirect:
# Hardcode redirection. # Hardcode redirection.
return context.Base_redirect("WebSection_viewShoppingCart", \ return context.Base_redirect("WebSection_viewShoppingCart", \
......
""" """
Update Trade Condition with the appropriated Trade Condition. Update Trade Condition with the appropriated Trade Condition.
""" """
portal = context.getPortalObject()
if payment_mode is None and preserve: if payment_mode is None and preserve:
current_trade_condition = shopping_cart.getSpecialiseValue() current_trade_condition = shopping_cart.getSpecialiseValue()
if current_trade_condition is not None: if current_trade_condition is not None:
...@@ -16,7 +17,7 @@ if context.REQUEST.get("loyalty_reward", "") == "enable" and context.getSiteLoya ...@@ -16,7 +17,7 @@ if context.REQUEST.get("loyalty_reward", "") == "enable" and context.getSiteLoya
if payment_mode: if payment_mode:
reference = '%s_%s' % (reference, payment_mode.lower()) reference = '%s_%s' % (reference, payment_mode.lower())
sale_trade_condition = context.portal_catalog.getResultValue( sale_trade_condition = portal.portal_catalog.getResultValue(
portal_type='Sale Trade Condition', portal_type='Sale Trade Condition',
reference='%' + reference + '%', reference='%' + reference + '%',
validation_state='published', validation_state='published',
...@@ -27,3 +28,6 @@ if sale_trade_condition: ...@@ -27,3 +28,6 @@ if sale_trade_condition:
shopping_cart.setSpecialiseValue(sale_trade_condition.getObject()) shopping_cart.setSpecialiseValue(sale_trade_condition.getObject())
else: else:
shopping_cart.setSpecialise(context.WebSection_getDefaultTradeCondition()) shopping_cart.setSpecialise(context.WebSection_getDefaultTradeCondition())
portal.portal_sessions[container.REQUEST['session_id']].update(shopping_cart=shopping_cart)
...@@ -71,6 +71,7 @@ else: ...@@ -71,6 +71,7 @@ else:
shopping_cart = context.SaleOrder_getShoppingCart() shopping_cart = context.SaleOrder_getShoppingCart()
if shopping_cart is not None: if shopping_cart is not None:
shopping_cart.manage_setLocalRoles(user_id, ['Owner']) shopping_cart.manage_setLocalRoles(user_id, ['Owner'])
portal.portal_sessions[container.REQUEST['session_id']].update(shopping_cart=shopping_cart)
""" """
response = context.REQUEST.RESPONSE response = context.REQUEST.RESPONSE
......
...@@ -43,12 +43,14 @@ for order_line in shopping_cart_items: ...@@ -43,12 +43,14 @@ for order_line in shopping_cart_items:
line_found=True line_found=True
break break
if line_found == False: if not line_found:
## new Resource so add it to shopping cart ## new Resource so add it to shopping cart
order_line = shopping_cart.newContent(portal_type='Sale Order Line') order_line = shopping_cart.newContent(portal_type='Sale Order Line')
order_line.setResource(resource.getRelativeUrl()) order_line.setResource(resource.getRelativeUrl())
order_line.setQuantity(quantity) order_line.setQuantity(quantity)
context.getPortalObject().portal_sessions[request['session_id']].update(shopping_cart=shopping_cart)
if( context.getPortalType() == 'Product'): if( context.getPortalType() == 'Product'):
context.Base_redirect('Resource_viewAsShop', context.Base_redirect('Resource_viewAsShop',
keep_items={'portal_status_message':context.Base_translateString("Added to cart.")}) keep_items={'portal_status_message':context.Base_translateString("Added to cart.")})
......
""" """
Delete a shopping cart item. Delete a shopping cart item.
""" """
portal = context.getPortalObject()
translateString = context.Base_translateString translateString = portal.Base_translateString
shopping_cart = context.SaleOrder_getShoppingCart() shopping_cart = context.SaleOrder_getShoppingCart()
if field_my_order_line_id is not None: if field_my_order_line_id is not None:
...@@ -11,5 +11,6 @@ if field_my_order_line_id is not None: ...@@ -11,5 +11,6 @@ if field_my_order_line_id is not None:
else: else:
portal_status_message = "Please select an item." portal_status_message = "Please select an item."
portal.portal_sessions[container.REQUEST['session_id']].update(shopping_cart=shopping_cart)
context.Base_redirect(form_id, \ context.Base_redirect(form_id, \
keep_items={'portal_status_message': translateString(portal_status_message, mapping={})}) keep_items={'portal_status_message': translateString(portal_status_message, mapping={})})
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