<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </value>
        </item>
        <item>
            <key> <string>_bind_names</string> </key>
            <value>
              <object>
                <klass>
                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
                </klass>
                <tuple/>
                <state>
                  <dictionary>
                    <item>
                        <key> <string>_asgns</string> </key>
                        <value>
                          <dictionary>
                            <item>
                                <key> <string>name_container</string> </key>
                                <value> <string>container</string> </value>
                            </item>
                            <item>
                                <key> <string>name_context</string> </key>
                                <value> <string>context</string> </value>
                            </item>
                            <item>
                                <key> <string>name_m_self</string> </key>
                                <value> <string>script</string> </value>
                            </item>
                            <item>
                                <key> <string>name_subpath</string> </key>
                                <value> <string>traverse_subpath</string> </value>
                            </item>
                          </dictionary>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>_body</string> </key>
            <value> <string encoding="cdata"><![CDATA[

"""Add selected product to the cart and continue"""\n
portal = context.getPortalObject()\n
prefered_resource = portal.portal_preferences.getPreferredInstanceSetupResource()\n
service = portal.restrictedTraverse(prefered_resource)\n
\n
##Get item list\n
resource_list = []\n
if uids:\n
  item_list = [item.getObject() for item in portal.portal_catalog(uid=uids, portal_type="Software Release")]\n
\n
  if context.getPortalType() == "Software Release":\n
    item_list.append(context)\n
  \n
  for item in item_list:\n
    resource_list.append({\'product\': item.getAggregateValue(),\n
                          \'release\': item\n
                          })\n
\n
if len(resource_list) == 0:\n
  return context.Base_redirect(dialog_id,\n
                        keep_items={\'portal_status_message\':context.Base_translateString("Please select one service and one release.")})\n
\n
\n
##Reset the cart and get new shopping cart\n
if reset_shopping_cart:\n
  context.SaleOrder_getShoppingCart(action=\'reset\')\n
\n
shopping_cart = context.SaleOrder_getShoppingCart()\n
shopping_cart_items = context.SaleOrder_getShoppingCartItemList()\n
\n
for resource in resource_list:\n
\n
  product_url = resource[\'product\'].getRelativeUrl()\n
  release_url = resource[\'release\'].getRelativeUrl()\n
  ## check if we don\'t have already such a resource in cart\n
  line_found=False\n
  if not reset_shopping_cart:\n
    for order_line in shopping_cart_items:\n
      if product_url in order_line.getAggregateList() \\\n
         and release_url in order_line.getAggregateList():\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 not line_found:\n
    ## new Resource so add it to shopping cart\n
    order_line = shopping_cart.newContent(portal_type=\'Sale Order Line\',\n
                                          quantity=quantity,\n
                                          resource=prefered_resource,\n
                                          price=50,\n
                                          aggregate_list=[product_url,release_url])\n
    \n
##Set connected member as shopping cart customer\n
context.SaleOrder_setShoppingCartCustomer()\n
\n
##check order is ok\n
# if not shopping_cart.SaleOrder_isConsistent():\n
#   return context.Base_redirect(dialog_id,\n
#                       keep_items={\'portal_status_message\':context.Base_translateString("Please select a shipping service")})\n
\n
if kw.has_key(\'came_from\'):\n
  #we override the context to redirect the user to the next web section\n
  context = portal.restrictedTraverse(kw[\'came_from\'])\n
  \n
context.WebSection_viewNextStep()\n


]]></string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>dialog_id, uids=[], quantity = 1, reset_shopping_cart=True, **kw</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>WebSection_addSelectedItemsToShoppingCart</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
