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

Support variations in ad-hoc way

parent fdf2b59c
......@@ -54,6 +54,14 @@
"""\n
Add resource to shopping cart.\n
\n
TODO:\n
- support generic variations beyond size and variation\n
(through introspection of resource) also in\n
SaleOrder_viewShoppingCartRenderer and\n
SaleOrder_viewShoppingCartWidgetRenderer\n
- implement form validation and parameter retrieval using Base_edit\n
- Resource_viewAsShop should be select through portal types\n
"""\n
request = container.REQUEST\n
if resource is None:\n
......@@ -64,7 +72,7 @@ if form_id is not None:\n
form = getattr(context, form_id, None)\n
quantity = int(request.get(\'field_your_buy_quantity\'))\n
# FIXME:\n
# this handling of validation errors should be automatically handled by the \n
# this handling of validation errors should be automatically handled by the\n
# button itself\n
try:\n
params = form.validate_all_to_request(request)\n
......@@ -84,31 +92,45 @@ if form_id is not None:\n
shopping_cart = context.SaleOrder_getShoppingCart()\n
shopping_cart_items = context.SaleOrder_getShoppingCartItemList()\n
\n
# Add-hoc access to parameters (use instead Base_edit)\n
# and quick dirty hack\n
# XXX - This must be rewritten to support any variation dimensions\n
# (not only size and variation)\n
size = request.form.get(\'field_variation_box_your_size\', \'\')\n
variation = request.form.get(\'field_variation_box_your_variation\', None)\n
\n
## check if we don\'t have already such a resource in cart\n
line_found=False\n
for order_line in shopping_cart_items:\n
if order_line.getResource() == resource.getRelativeUrl():\n
new_quantity = int(order_line.getQuantity()) + quantity\n
if new_quantity <= 0:\n
## remove items with zero quantity\n
shopping_cart.manage_delObjects(order_line)\n
else:\n
order_line.setQuantity(new_quantity)\n
line_found=True\n
break\n
if (not variation or order_line.getVariation() == variation)\\\n
and (not size or order_line.getSize() == size):\n
new_quantity = int(order_line.getQuantity()) + quantity\n
if new_quantity <= 0:\n
## remove items with zero quantity\n
shopping_cart.manage_delObjects(order_line)\n
else:\n
order_line.setQuantity(new_quantity)\n
line_found=True\n
break\n
\n
if line_found == False:\n
if not line_found:\n
## new Resource so add it to shopping cart\n
order_line = shopping_cart.newContent(portal_type=\'Sale Order Line\')\n
order_line.setResource(resource.getRelativeUrl())\n
order_line.setQuantity(quantity)\n
if variation: order_line.setVariation(variation)\n
if size: order_line.setSize(size)\n
order_line.setPrice(context.getPrice(context=order_line))\n
\n
if( context.getPortalType() == \'Product\'):\n
context.Base_redirect(\'Resource_viewAsShop\',\n
keep_items={\'portal_status_message\':context.Base_translateString("Added to cart.")})\n
keep_items={\'portal_status_message\':context.Base_translateString("Added to cart."),\n
\'variation\':variation})\n
else:\n
context.Base_redirect(\'view\',\n
keep_items={\'portal_status_message\':context.Base_translateString("Added to cart.")})\n
keep_items={\'portal_status_message\':context.Base_translateString("Added to cart."),\n
\'variation\':variation})\n
]]></string> </value>
......
......@@ -187,8 +187,14 @@
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Do whatever is necessary to finalize an order.\n
This script is called after customer completes shopping.\n
Do whatever is necessary to finalize an order. This script\n
is called after customer completes shopping (and payment).\n
\n
TODO:\n
- support generic variations\n
- rename buyer to supplier (everywhere)\n
- clean up python style such as space in "a = b" inside function calls\n
(hint: add global syntax and lexical analysis to ERP5 scripts)\n
"""\n
from DateTime import DateTime\n
request = context.REQUEST\n
......@@ -201,32 +207,33 @@ customer = shopping_cart.SaleOrder_getShoppingCartCustomer()\n
buyer = shopping_cart.SaleOrder_getShoppingCartBuyer()\n
\n
if isAnon:\n
# create first an account for user\n
# Create first an account for user\n
msg = translateString("You need to create an account to continue. If you already have please login.")\n
web_site.Base_redirect(\'login_form\', \\\n
keep_items={\'portal_status_message\': msg})\n
return\n
\n
#Check if payment is sucessfull\n
# Check if payment is sucessfull (comment the if buyer line and uncoment the next to be able to test)\n
if buyer is None:\n
raise ValueError, "Impossible to finalize and order not payed"\n
# if False:\n
raise ValueError, "Impossible to finalize an order which was not payed before"\n
\n
portal_type = "Sale %s" % shopping_cart.getPortalType()\n
portal_type = shopping_cart.getPortalType()\n
module = context.getDefaultModule(portal_type)\n
sale_order = module.newContent(portal_type=portal_type,\n
destination_value = customer,\n
destination_section_value = customer,\n
destination_decision_value = customer,\n
source_section_value = buyer,\n
source_value = buyer,\n
start_date = DateTime(),\n
received_date = DateTime(),\n
comment = shopping_cart.getComment(),\n
# set order default currency,\n
default_price_currency = web_site.WebSite_getShoppingCartDefaultCurrency().getRelativeUrl(),\n
# set trade condition\n
specialise_value = web_site.SaleOrder_getDefaultTradeCondition()\n
)\n
destination_value = customer,\n
destination_section_value = customer,\n
destination_decision_value = customer,\n
source_section_value = buyer,\n
source_value = buyer,\n
start_date = DateTime(),\n
received_date = DateTime(),\n
comment = shopping_cart.getComment(),\n
# set order default currency,\n
default_price_currency = web_site.WebSite_getShoppingCartDefaultCurrency().getRelativeUrl(),\n
# set trade condition\n
specialise_value = web_site.SaleOrder_getDefaultTradeCondition()\n
)\n
\n
for order_line in shopping_cart_item_list:\n
resource = order_line.getResourceValue()\n
......@@ -235,14 +242,18 @@ for order_line in shopping_cart_item_list:\n
aggregate_list = order_line.getAggregateList(),\n
quantity = order_line.getQuantity(),\n
price = order_line.getPrice(),\n
title = resource.getTitle())\n
title = resource.getTitle(),\n
variation=order_line.getVariation(),\n
size=order_line.getSize(),\n
)\n
\n
# order it\n
sale_order.order()\n
sale_order.activate().order()\n
\n
# clean up shopping cart\n
context.SaleOrder_getShoppingCart(action=\'reset\')\n
\n
# Display nice message\n
context.Base_redirect(\'SaleOrder_viewThankYouMessage\')\n
</string> </value>
</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