[IMP] website_sale: attributes/filter, fix access right, add default value for filter (for custom user ecommerce with category,label...)
bzr revid: chm@openerp.com-20131105150928-ps01ziqnfgd9hu46
This commit is contained in:
parent
7f5a60f13c
commit
f318f99825
|
@ -223,19 +223,21 @@ class Ecommerce(http.Controller):
|
|||
product_ids = [id for id in product_ids if id in product_obj.search(request.cr, request.uid, [("id", 'in', product_ids)], context=request.context)]
|
||||
return product_obj.browse(request.cr, request.uid, product_ids, context=request.context)
|
||||
|
||||
def has_search_attributes(self, attribute_id, value_id=None):
|
||||
if request.httprequest.args.get('attributes'):
|
||||
attributes = simplejson.loads(request.httprequest.args['attributes'])
|
||||
def has_search_filter(self, attribute_id, value_id=None):
|
||||
if request.httprequest.args.get('filter'):
|
||||
filter = simplejson.loads(request.httprequest.args['filter'])
|
||||
else:
|
||||
attributes = []
|
||||
for key_val in attributes:
|
||||
filter = []
|
||||
for key_val in filter:
|
||||
if key_val[0] == attribute_id and (not value_id or value_id in key_val[1:]):
|
||||
return key_val
|
||||
return False
|
||||
|
||||
@website.route(['/shop/attributes/'], type='http', auth="public", multilang=True)
|
||||
def attributes(self, **post):
|
||||
attributes = []
|
||||
@website.route(['/shop/filter/'], type='http', auth="public", multilang=True)
|
||||
def filter(self, add_filter="", **post):
|
||||
filter = []
|
||||
if add_filter:
|
||||
filter = simplejson.loads(add_filter)
|
||||
index = []
|
||||
for key, val in post.items():
|
||||
cat = key.split("-")
|
||||
|
@ -248,16 +250,20 @@ class Ecommerce(http.Controller):
|
|||
_max = int(post.pop("att-%s-max" % cat[1]))
|
||||
_min = int(val)
|
||||
if (minmem != _min or maxmem != _max) and cat_id not in index:
|
||||
attributes.append([cat_id , [_min, _max] ])
|
||||
filter.append([cat_id , [_min, _max] ])
|
||||
index.append(cat_id)
|
||||
elif cat_id not in index:
|
||||
attributes.append([ cat_id, int(cat[2]) ])
|
||||
filter.append([ cat_id, int(cat[2]) ])
|
||||
index.append(cat_id)
|
||||
else:
|
||||
attributes[index.index(cat_id)].append( int(cat[2]) )
|
||||
filter[index.index(cat_id)].append( int(cat[2]) )
|
||||
post.pop(key)
|
||||
|
||||
return request.redirect("/shop/?attributes=%s&%s" % (simplejson.dumps(attributes).replace(" ", ""), urllib.urlencode(post)))
|
||||
return request.redirect("/shop/?filter=%s%s%s" % (
|
||||
simplejson.dumps(filter).replace(" ", ""),
|
||||
add_filter and "&add_filter=%s" % add_filter or "",
|
||||
post and "&%s" % urllib.urlencode(post) or ""
|
||||
))
|
||||
|
||||
def attributes_to_ids(self, attributes):
|
||||
obj = request.registry.get('product.attribute.product')
|
||||
|
@ -273,7 +279,7 @@ class Ecommerce(http.Controller):
|
|||
return [r["product_id"][0] for r in att]
|
||||
|
||||
@website.route(['/shop/', '/shop/page/<int:page>/'], type='http', auth="public", multilang=True)
|
||||
def category(self, category=0, attributes="", page=0, **post):
|
||||
def category(self, category=0, filter="", page=0, **post):
|
||||
# TDE-NOTE: shouldn't we do somethign about product_template without variants ???
|
||||
# TDE-NOTE: is there a reason to call a method category when the route is
|
||||
# basically a shop without category_id speceified ?
|
||||
|
@ -295,10 +301,10 @@ class Ecommerce(http.Controller):
|
|||
cat_id = int(category)
|
||||
domain = [('product_variant_ids.public_categ_id.id', 'child_of', cat_id)] + domain
|
||||
|
||||
if attributes:
|
||||
attributes = simplejson.loads(attributes)
|
||||
if attributes:
|
||||
ids = self.attributes_to_ids(attributes)
|
||||
if filter:
|
||||
filter = simplejson.loads(filter)
|
||||
if filter:
|
||||
ids = self.attributes_to_ids(filter)
|
||||
domain = [('id', 'in', ids or [0] )] + domain
|
||||
|
||||
step = 20
|
||||
|
|
|
@ -48,9 +48,11 @@ class attributes(osv.Model):
|
|||
'float_min': fields.function(_get_float_min, type='float', string="Min", store={
|
||||
'product.attribute.product': (_get_min_max, ['value','attribute_id'], 20),
|
||||
}),
|
||||
'visible': fields.boolean('Visible'),
|
||||
}
|
||||
_defaults = {
|
||||
'type': 'distinct'
|
||||
'type': 'distinct',
|
||||
'visible': True,
|
||||
}
|
||||
|
||||
class attributes_value(osv.Model):
|
||||
|
|
|
@ -7,4 +7,6 @@ access_product_pricelist_version_public,product.pricelist.version.public,product
|
|||
access_product_pricelist_public,product.pricelist.public,product.model_product_pricelist,base.group_public,1,0,0,0
|
||||
access_product_product_price_type_public,product.price.type.public,product.model_product_price_type,base.group_public,1,0,0,0
|
||||
access_sale_order_public,sale.order.public,model_sale_order,base.group_public,1,0,0,0
|
||||
access_sale_order_line_public,sale.order.line.public,model_sale_order_line,base.group_public,1,0,0,0
|
||||
access_sale_order_line_public,sale.order.line.public,model_sale_order_line,base.group_public,1,0,0,0
|
||||
access_product_attribute,product.attribute.public,website_sale.model_product_attribute,base.group_public,1,0,0,0
|
||||
access_product_attribute_value,product.attribute.value.public,website_sale.model_product_attribute_value,base.group_public,1,0,0,0
|
|
|
@ -67,6 +67,8 @@
|
|||
<template id="products" name="Products" page="True">
|
||||
<t t-call="website.layout">
|
||||
<t t-set="head">
|
||||
<script type="text/javascript" src="/web/static/lib/jquery.ui/js/jquery-ui-1.9.1.custom.js"></script>
|
||||
<link rel='stylesheet' href="/web/static/lib/jquery.ui/css/smoothness/jquery-ui-1.9.1.custom.css"/>
|
||||
<script type="text/javascript" src="/website_sale/static/src/js/website_sale.js"></script>
|
||||
<link rel='stylesheet' href='/website_sale/static/src/css/website_sale.css'/>
|
||||
<t t-raw="head or ''"/>
|
||||
|
@ -492,20 +494,21 @@
|
|||
</xpath>
|
||||
</template>
|
||||
|
||||
<template id="products_attributes" inherit_option_id="website_sale.products_categories" name="Product Attributes">
|
||||
<template id="products_attributes" inherit_option_id="website_sale.products_categories" name="Product Filters and Attributes">
|
||||
<xpath expr="//div[@id='categories']" position="inside">
|
||||
<form t-action="/shop/attributes/" method="post" t-keep-query="category,search">
|
||||
<form t-action="/shop/filter/" method="post" t-keep-query="category,search,add_filter">
|
||||
<ul class="nav nav-pills nav-stacked mt16">
|
||||
<t t-set="attribute_ids" t-value="Ecommerce.get_attribute_ids()"/>
|
||||
<t t-foreach="attribute_ids" t-as="attribute_id">
|
||||
<t t-if="attribute_id.visible">
|
||||
<li t-if="attribute_id.value_ids and attribute_id.type == 'distinct'">
|
||||
<div t-field="attribute_id.name"/>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<t t-foreach="attribute_id.value_ids" t-as="value_id">
|
||||
<li t-att-class="Ecommerce.has_search_attributes(attribute_id.id, value_id.id) and 'active' or ''">
|
||||
<li t-att-class="Ecommerce.has_search_filter(attribute_id.id, value_id.id) and 'active' or ''">
|
||||
<label style="margin: 0 20px;">
|
||||
<input type="checkbox" t-att-name="'att-%s-%s' % (attribute_id.id, value_id.id)"
|
||||
t-att-checked="Ecommerce.has_search_attributes(attribute_id.id, value_id.id) and 'checked' or ''"/>
|
||||
t-att-checked="Ecommerce.has_search_filter(attribute_id.id, value_id.id) and 'checked' or ''"/>
|
||||
<span style="font-weight: normal" t-field="value_id.name"/>
|
||||
</label>
|
||||
</li>
|
||||
|
@ -514,7 +517,7 @@
|
|||
</li>
|
||||
<li t-if="attribute_id.type == 'float' and attribute_id.float_min != attribute_id.float_max">
|
||||
<div t-field="attribute_id.name"/>
|
||||
<t t-set="attribute" t-value="Ecommerce.has_search_attributes(attribute_id.id)"/>
|
||||
<t t-set="attribute" t-value="Ecommerce.has_search_filter(attribute_id.id)"/>
|
||||
<div style="margin: 0 20px;" class="js_slider"
|
||||
t-att-data-id="attribute_id.id"
|
||||
t-att-data-value-min="attribute and attribute[1][0] or attribute_id.float_min"
|
||||
|
@ -522,6 +525,7 @@
|
|||
t-att-data-min="attribute_id.float_min"
|
||||
t-att-data-max="attribute_id.float_max"></div>
|
||||
</li>
|
||||
</t>
|
||||
</t>
|
||||
</ul>
|
||||
<button class="btn btn-xs btn-primary mt16">Apply filter</button>
|
||||
|
|
Loading…
Reference in New Issue