[FIX] website_sale: pager and breadcrum keep search and filter. Filter keep search and category. Links for category

bzr revid: chm@openerp.com-20140212115516-3izdv7cszgh2n3l4
This commit is contained in:
Christophe Matthieu 2014-02-12 12:55:16 +01:00
parent ac03ba3095
commit ed785f0783
4 changed files with 57 additions and 48 deletions

View File

@ -248,7 +248,7 @@ class website(osv.osv):
pmin = pmax - scope if pmax - scope > 0 else 1
def get_url(page):
_url = "%spage/%s/" % (url, page)
_url = "%spage/%s/" % (url, page) if page > 1 else url
if url_args:
_url = "%s?%s" % (_url, werkzeug.url_encode(url_args))
return _url

View File

@ -383,13 +383,13 @@
<template id="pager" name="Pager">
<ul t-if="pager['page_count'] > 1" t-attf-class="#{ classname or '' } pagination" t-att-style="style or ''">
<li t-att-class=" 'disabled' if pager['page']['num'] == 1 else '' ">
<a t-att-href="'%s?%s' % (pager['page_previous']['url'],keep_query('*')) if pager['page']['num'] != 1 else ''">Prev</a>
<a t-att-href=" pager['page_previous']['url'] if pager['page']['num'] != 1 else ''">Prev</a>
</li>
<t t-foreach="pager['pages']" t-as="page">
<li t-att-class=" 'active' if page['num'] == pager['page']['num'] else '' "> <a t-att-href="'%s?%s' % (page['url'],keep_query('*'))" t-raw="page['num']"></a></li>
<li t-att-class=" 'active' if page['num'] == pager['page']['num'] else '' "> <a t-att-href="page['url']" t-raw="page['num']"></a></li>
</t>
<li t-att-class=" 'disabled' if pager['page']['num'] == pager['page_count'] else '' ">
<a t-att-href="'%s?%s' % (pager['page_next']['url'],keep_query('*')) if pager['page']['num'] != pager['page_count'] else ''">Next</a>
<a t-att-href="pager['page_next']['url'] if pager['page']['num'] != pager['page_count'] else ''">Next</a>
</li>
</ul>
</template>

View File

@ -7,6 +7,7 @@ from openerp import SUPERUSER_ID
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.tools.translate import _
from openerp.addons.website.models.website import slug
PPG = 20 # Products Per Page
PPR = 4 # Products Per Row
@ -143,8 +144,8 @@ class Ecommerce(http.Controller):
return key_val
return False
@http.route(['/shop/filters/'], type='http', auth="public", website=True, multilang=True)
def filters(self, **post):
@http.route(['/shop/filters/'], type='http', auth="public", methods=['POST'], website=True, multilang=True)
def filters(self, category=None, **post):
index = []
filters = []
for key, val in post.items():
@ -169,11 +170,16 @@ class Ecommerce(http.Controller):
filters[index.index(cat_id)].append( cat[2] )
post.pop(key)
return request.redirect("/shop/?filters=%s%s%s" % (
simplejson.dumps(filters),
post.get("search") and ("&search=%s" % post.get("search")) or "",
post.get("category") and ("&category=%s" % post.get("category")) or ""
))
url = "/shop/"
if category:
category_obj = request.registry.get('product.public.category')
url = "%scategory/%s/" % (url, slug(category_obj.browse(request.cr, request.uid, int(category), context=request.context)))
if filters:
url = "%s?filters=%s" % (url, simplejson.dumps(filters))
if post.get("search"):
url = "%s%ssearch=%s" % (url, filters and "&" or "?", post.get("search"))
return request.redirect(url)
def attributes_to_ids(self, attributes):
obj = request.registry.get('product.attribute.line')
@ -209,15 +215,24 @@ class Ecommerce(http.Controller):
('name', 'ilike', search),
('description', 'ilike', search)]
if category:
domain.append(('product_variant_ids.public_categ_id', 'child_of', category.id))
domain.append(('product_variant_ids.public_categ_id', 'child_of', int(category)))
if isinstance(category, (int,str,unicode)):
category = request.registry.get('product.public.category').browse(cr, uid, int(category), context=context)
if filters:
filters = simplejson.loads(filters)
if filters:
ids = self.attributes_to_ids(filters)
domain.append(('id', 'in', ids or [0]))
url = "/shop/"
product_count = product_obj.search_count(cr, uid, domain, context=context)
pager = request.website.pager(url="/shop/", total=product_count, page=page, step=PPG, scope=7, url_args=post)
if search:
post["search"] = search
if filters:
post["filters"] = filters
if category:
url = "/shop/category/%s/" % slug(category)
pager = request.website.pager(url=url, total=product_count, page=page, step=PPG, scope=7, url_args=post)
request.context['pricelist'] = self.get_pricelist()
@ -244,11 +259,12 @@ class Ecommerce(http.Controller):
'range': range,
'search': {
'search': search,
'category': category and category.id,
'category': category,
'filters': filters,
},
'pager': pager,
'styles': styles,
'category': category,
'categories': categs,
'Ecommerce': self, # TODO fp: Should be removed
'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids],
@ -257,26 +273,20 @@ class Ecommerce(http.Controller):
@http.route(['/shop/product/<model("product.template"):product>/'], type='http', auth="public", website=True, multilang=True)
def product(self, product, search='', category='', filters='', **kwargs):
category_obj = request.registry.get('product.public.category')
category_ids = category_obj.search(request.cr, request.uid, [], context=request.context)
category_list = category_obj.name_get(request.cr, request.uid, category_ids, context=request.context)
category_list = sorted(category_list, key=lambda category: category[1])
if category:
category_obj = request.registry.get('product.public.category')
category = category_obj.browse(request.cr, request.uid, int(category), context=request.context)
request.context['pricelist'] = self.get_pricelist()
values = {
'Ecommerce': self,
'category': category,
'category_list': category_list,
'main_object': product,
'product': product,
'category': category,
'search': {
'search': search,
'category': category and str(category.id),
'category': category,
'filters': filters,
}
}

View File

@ -32,10 +32,10 @@
<!-- List of categories -->
<template id="categories_recursive" name="Category list">
<li t-att-class="category.id == search.get('category') and 'active' or ''">
<a t-attf-href="/shop/category/#{ slug(category) }/" t-field="category.name"></a>
<ul t-if="category.child_id" class="nav nav-pills nav-stacked nav-hierarchy">
<t t-foreach="category.child_id" t-as="category">
<li t-att-class="int(categ) == int(category or 0) and 'active' or ''">
<a t-attf-href="/shop/category/#{ slug(categ) }/" t-field="categ.name"></a>
<ul t-if="categ.child_id" class="nav nav-pills nav-stacked nav-hierarchy">
<t t-foreach="categ.child_id" t-as="categ">
<t t-call="website_sale.categories_recursive"/>
</t>
</ul>
@ -45,14 +45,15 @@
<!-- Product list -->
<template id="search" name="Search hidden fields">
<input type="hidden" name="category" t-att-value="search.get('category') or ''"/>
<input type="hidden" name="filters" t-att-value="search.get('filters') or ''"/>
<div class="input-group">
<input type="text" name="search" class="search-query form-control" placeholder="Search..." t-att-value="search.get('search') or ''"/>
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="fa fa-search"/></button>
</span>
</div>
<form t-attf-action="/shop/{{'category/%s/' % slug(category) if category else ''}}" method="get" t-att-class="search_class">
<input t-if="search.get('filters')" type="hidden" name="filters" t-att-value="search.get('filters')"/>
<div class="input-group">
<input type="text" name="search" class="search-query form-control" placeholder="Search..." t-att-value="search.get('search') or ''"/>
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="fa fa-search"/></button>
</span>
</div>
</form>
</template>
<template id="products_cart" name="Shopping cart">
@ -60,12 +61,12 @@
<div class="ribbon btn btn-danger">Sale</div>
</div>
<div class="oe_product_image">
<a t-attf-href="/shop/product/{{ slug(product) }}/?{{ keep_query('category', 'search', 'filters') }}">
<a t-attf-href="/shop/product/{{ slug(product) }}/?{{ keep_query('search', 'filters', category=(category and int(category)), page=(pager['page']['num'] if pager['page']['num']>1 else None)) }}">
<span t-field="product.image" t-field-options='{"widget": "image"}'/>
</a>
</div>
<section>
<h5><strong><a t-attf-href="/shop/product/{{ slug(product) }}/?{{ keep_query('category', 'search', 'filters') }}" t-field="product.name"/></strong></h5>
<h5><strong><a t-attf-href="/shop/product/{{ slug(product) }}/?{{ keep_query('search', 'filters', category=(category and int(category)), page=(pager['page']['num'] if pager['page']['num']>1 else None)) }}" t-field="product.name"/></strong></h5>
<div class="product_price" t-if="product.product_variant_ids">
<b>
<t t-if="abs(product.product_variant_ids[0].lst_price - product.product_variant_ids[0].price) &gt; 0.2">
@ -99,9 +100,8 @@
<div class="container oe_website_sale">
<div class="products_pager">
<div class="row">
<form action="/shop/" method="get" class="pagination form-inline col-md-3">
<t t-call="website_sale.search" />
</form>
<t t-set="search_class">pagination form-inline col-md-3</t>
<t t-call="website_sale.search"/>
<t t-call="website.pager"/>
</div>
</div>
@ -278,15 +278,14 @@
<div class="row">
<div class="col-sm-4">
<ol class="breadcrumb">
<li><a t-attf-href="/shop?{{ keep_query('search', 'filters') }}" onclick="history.go(-1); return false;">Products</a></li>
<li t-if="search.get('category')"><a t-attf-href="/shop/?{{ keep_query('search', 'filters', 'category') }}" t-field="category.name"/></li>
<li><a t-attf-href="/shop?{{ keep_query('search', 'filters', 'page') if not category else keep_query('search', 'filters') }}">Products</a></li>
<li t-if="category"><a t-attf-href="/shop/category/{{ slug(category) }}/?{{ keep_query('search', 'filters', 'page') }}" t-field="category.name"/></li>
<li class="active"><span t-field="product.name"/></li>
</ol>
</div>
<div class="col-sm-3">
<form action="/shop/" method="get" class="pull-right">
<t t-call="website_sale.search" />
</form>
<t t-set="search_class">pull-right</t>
<t t-call="website_sale.search"/>
</div>
<div class="col-sm-4" groups="base.group_sale_manager">
<t t-call="website.publish_management">
@ -569,8 +568,8 @@
<template id="products_categories" inherit_option_id="website_sale.products" name="Product Categories">
<xpath expr="//div[@id='products_grid_before']" position="inside">
<ul class="nav nav-pills nav-stacked mt16">
<li t-att-class=" '' if search.get('category') else 'active' "><a href="/shop/">All Products</a></li>
<t t-foreach="categories" t-as="category">
<li t-att-class=" '' if category else 'active' "><a href="/shop/">All Products</a></li>
<t t-foreach="categories" t-as="categ">
<t t-call="website_sale.categories_recursive"/>
</t>
</ul>
@ -585,7 +584,7 @@
<template id="products_attributes" inherit_id="website_sale.products" inherit_option_id="website_sale.products" name="Product attribute's Filters" groups="product.group_product_attributes">
<xpath expr="//div[@id='products_grid_before']" position="inside">
<form t-attf-action="/shop/filters/?{{ keep_query('category', 'search') }}" class="attributes" method="post">
<form t-attf-action="/shop/filters/?{{ keep_query('search', category=(category and int(category))) }}" class="attributes" method="post">
<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">