diff --git a/bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSection_viewSelectedProductWidget.xml b/bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSection_viewSelectedProductWidget.xml index f6702b312dcc38dfb5f5080aa74659a0b0a2ba5d..f608acf1ad802c5f13bf32b1f5d746e0be38851f 100644 --- a/bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSection_viewSelectedProductWidget.xml +++ b/bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSection_viewSelectedProductWidget.xml @@ -54,13 +54,15 @@ - make it hierarchic\n -->\n </tal:block>\n -<div tal:define="site_url python:here.getWebSiteValue().absolute_url();\n +<div tal:define="web_site python: here.getWebSiteValue();\n + site_url python: web_site.absolute_url();\n current_web_section python:request.get(\'current_web_section\', here);\n shopping_cart here/SaleOrder_getShoppingCart;\n - currency_symbol python: shopping_cart.SaleOrder_getShoppingCartDefaultCurrencySymbol();"\n + currency_symbol python: shopping_cart.SaleOrder_getShoppingCartDefaultCurrencySymbol();\n + product_list python: web_site.WebSite_getProductList(limit=5);"\n i18n:translate="" i18n:domain="ui" i18n:attributes="title"\n title="Sections accessible from here." class="selected-product">\n - <tal:block tal:repeat="product python: here.WebSection_getProductList(limit=5)">\n + <tal:block tal:repeat="product python: product_list">\n <div tal:define="product_href python: \'%s/product_module/%s/%s\' % (site_url, product.getId(), \'Resource_viewAsShop\');\n price python: here.WebSection_unrestrictedGetPrice(product)">\n <a href="#" tal:attributes="href product_href">\n diff --git a/bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSite_getProductList.xml b/bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSite_getProductList.xml new file mode 100644 index 0000000000000000000000000000000000000000..daf658bd95e20c5be9554bb3e550ca8653c25435 --- /dev/null +++ b/bt5/erp5_commerce/SkinTemplateItem/portal_skins/erp5_commerce_widget_library/WebSite_getProductList.xml @@ -0,0 +1,192 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <tuple> + <global name="PythonScript" module="Products.PythonScripts.PythonScript"/> + <tuple/> + </tuple> + </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[ + +#TODO : USE CACHE\n +# The goal of this script is to get all the products from all the visible Web Sections\n +# and it must select randomly which product must be displayed for a given context.\n +from random import randrange\n +\n +web_site = context.getWebSiteValue() or context.REQUEST.get(\'current_web_site\')\n +product_list = []\n +kw[\'portal_type\'] = \'Product\'\n +kw[\'limit\'] = limit\n +\n +# Getting all the products from all the visible Web Section.\n +web_section_list = web_site.WebSite_getMainSectionList()\n +for web_section in web_section_list:\n + product_result_list = web_section.WebSection_getDocumentValueListBase(all_versions=1, all_languages=1, **kw)\n + for product in product_result_list:\n + if product.getObject() not in product_list:\n + product_list.append(product.getObject())\n +\n +if len(product_list) <= limit:\n + product_list = [x for x in product_list if x.getPortalType() == \'Product\']\n +else:\n + random_index_list = []\n + while len(random_index_list) < limit:\n + random_number = randrange(0, len(product_list))\n + if random_number not in random_index_list:\n + random_index_list.append(random_number)\n + product_list = [product_list[x] for x in random_index_list if product_list[x].getPortalType() == \'Product\']\n +return product_list\n + + +]]></string> </value> + </item> + <item> + <key> <string>_code</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string>limit=5, **kw</string> </value> + </item> + <item> + <key> <string>_proxy_roles</string> </key> + <value> + <tuple> + <string>Assignee</string> + <string>Assignor</string> + <string>Associate</string> + <string>Auditor</string> + <string>Authenticated</string> + <string>Author</string> + <string>Manager</string> + <string>Member</string> + <string>Owner</string> + <string>Reviewer</string> + </tuple> + </value> + </item> + <item> + <key> <string>errors</string> </key> + <value> + <tuple/> + </value> + </item> + <item> + <key> <string>func_code</string> </key> + <value> + <object> + <klass> + <global name="FuncCode" module="Shared.DC.Scripts.Signature"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>co_argcount</string> </key> + <value> <int>1</int> </value> + </item> + <item> + <key> <string>co_varnames</string> </key> + <value> + <tuple> + <string>limit</string> + <string>kw</string> + <string>random</string> + <string>randrange</string> + <string>_getattr_</string> + <string>context</string> + <string>web_site</string> + <string>product_list</string> + <string>_write_</string> + <string>web_section_list</string> + <string>_getiter_</string> + <string>web_section</string> + <string>_apply_</string> + <string>product_result_list</string> + <string>product</string> + <string>len</string> + <string>append</string> + <string>$append0</string> + <string>x</string> + <string>random_index_list</string> + <string>random_number</string> + <string>_getitem_</string> + </tuple> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>func_defaults</string> </key> + <value> + <tuple> + <int>5</int> + </tuple> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>WebSite_getProductList</string> </value> + </item> + <item> + <key> <string>warnings</string> </key> + <value> + <tuple/> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_commerce/bt/revision b/bt5/erp5_commerce/bt/revision index a14c1ee5ab423ef2b6365bb156245892bcd7dfa9..cd004727f2441a8c967a228d81b0bee1895a2597 100644 --- a/bt5/erp5_commerce/bt/revision +++ b/bt5/erp5_commerce/bt/revision @@ -1 +1 @@ -180 \ No newline at end of file +182 \ No newline at end of file