I am using a ecommerce webpage, with mobicraft template. When trying to search for a article, the rendered page, and the links, of the pager are incorrect. The code itself, without using the theme is working correctly, so the problem lies in the template and i've extended the theme controller with my custom one. The function i am calling is defined in the website.pager. I've logged the results, and the ones before the return in the website.pager are correct, but when i log them in my function, they are incorrect, so are the ones in the webpage.
Here is what the website.pager returns as pages:
'pages': [{'url': '/shop?range2=163.93&range1=0.01&search=ar', 'num': 1}, {'url': '/shop/page/2?range2=163.93&range1=0.01&search=ar', 'num': 2}, {'url': '/shop/page/3?range2=163.93&range1=0.01&search=ar', 'num': 3}, {'url': '/shop/page/4?range2=163.93&range1=0.01&search=ar', 'num': 4}, {'url': '/shop/page/5?range2=163.93&range1=0.01&search=ar', 'num': 5}]
here is what, the logger prints in my function:
'pages': [{'url': '/shop', 'num': 1}, {'url': '/shop/page/2', 'num': 2}, {'url': '/shop/page/3', 'num': 3}, {'url': '/shop/page/4', 'num': 4}, {'url': '/shop/page/5', 'num': 5}]
here is my full function:
@http.route()
def shop(self, page=0, category=None, brand=None, search='', ppg=False, **post):
context, pool = request.context, request.env
if brand:
request.context.setdefault('brand_id', int(brand))
result = super(ThememobicraftBrandSlider, self).shop(
page=page, category=category, brand=brand, search=search, **post)
sort_order = ""
cat_id = []
page_no = request.env['product.per.page.no'].search([('set_default_check', '=', True)])
if page_no:
ppg = page_no.name
else:
ppg = main_shop.PPG
# product template object
product_obj = pool.get('product.template')
attrib_list = request.httprequest.args.getlist('attrib')
attrib_values = [map(int, v.split("-")) for v in attrib_list if v]
attributes_ids = set([v[0] for v in attrib_values])
attrib_set = set([v[1] for v in attrib_values])
domain = request.website.sale_product_domain()
domain += self._get_search_domain(search, category, attrib_values)
url = "/shop"
if post:
request.session.update(post)
prevurl = request.httprequest.referrer
if prevurl:
if not re.search('/shop', prevurl, re.IGNORECASE):
request.session['tag'] = ""
request.session['sort_id'] = ""
request.session['sortid'] = ""
request.session['pricerange'] = ""
request.session['min1'] = ""
request.session['max1'] = ""
session = request.session
# for category filter
if category:
category = pool['product.public.category'].browse(int(category))
url = "/shop/category/%s" % slug(category)
if category != None:
for ids in category:
cat_id.append(ids.id)
domain += ['|', ('public_categ_ids.id', 'in', cat_id),
('public_categ_ids.parent_id', 'in', cat_id)]
# for tag filter
if session.get('tag'):
session_tag = session.get('tag')
tag = session_tag[0]
tags_obj = pool['biztech.product.tags']
tags_ids = tags_obj.search([], )
tags = tags_obj.browse(tags_ids)
if tag:
tag = pool['biztech.product.tags'].browse(int(tag))
domain += [('biztech_tag_ids', '=', int(tag))]
request.session["tag"] = [tag.id, tag.name]
# For Product Sorting
if session.get('sort_id'):
session_sort = session.get('sort_id')
sort = session_sort
sorts_obj = pool['biztech.product.sortby']
sorts_ids = sorts_obj.search([], )
sorts = sorts_obj.browse(sorts_ids)
sort_field = pool['biztech.product.sortby'].browse(int(sort))
request.session['product_sort_name'] = sort_field.name
order_field = sort_field.sort_on.name
order_type = sort_field.sort_type
sort_order = '%s %s' % (order_field, order_type)
if post.get("sort_id"):
request.session["sortid"] = [
sort, sort_order, sort_field.name, order_type]
# For Price slider
product_slider_ids = []
asc_product_slider_obj = product_obj.search([('website_published', '=', True)], limit=1, order='list_price')
desc_product_slider_obj = product_obj.search([('website_published', '=', True)], limit=1,
order='list_price desc')
if asc_product_slider_obj:
product_slider_ids.append(asc_product_slider_obj.website_price)
if desc_product_slider_obj:
product_slider_ids.append(desc_product_slider_obj.website_price)
if product_slider_ids:
if post.get("range1") or post.get("range2") or not post.get("range1") or not post.get("range2"):
range1 = min(product_slider_ids)
range2 = max(product_slider_ids)
result.qcontext['range1'] = range1
result.qcontext['range2'] = range2
if session.get("min1") and session["min1"]:
post["min1"] = session["min1"]
if session.get("max1") and session["max1"]:
post["max1"] = session["max1"]
if range1:
post["range1"] = range1
if range2:
post["range2"] = range2
if range1 == range2:
post['range1'] = 0.0
if request.session.get('min1') or request.session.get('max1'):
if request.session.get('min1'):
if request.session['min1'] != None:
domain += [('list_price', '>=', request.session.get('min1')),
('list_price', '<=', request.session.get('max1'))]
request.session["pricerange"] = str(
request.session['min1']) + "-To-" + str(request.session['max1'])
if session.get('min1') and session['min1']:
result.qcontext['min1'] = session["min1"]
result.qcontext['max1'] = session["max1"]
if request.session.get('default_paging_no'):
ppg = int(request.session.get('default_paging_no'))
product_count = product_obj.search_count(domain)
# popravek za pager, če je dodan search
if search and 'search' not in post:
post['search'] = search
_logger.error(u'Post: {}'.format(post))
# here is the problem
pager = request.website.pager(
url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
product_ids = product_obj.search(domain, limit=ppg, offset=pager['offset'], order=sort_order)
_logger.error(u'Pager: {}'.format(pager['pages']))
result.qcontext.update({'product_count': product_count})
result.qcontext.update({'products': product_ids})
result.qcontext.update({'category': category})
result.qcontext.update(
{'bins': TableCompute().process(product_ids, ppg)})
result.qcontext['brand'] = brand
result.qcontext['brand_obj'] = request.env['product.brands'].sudo().search([('id', '=', brand)])
_logger.error(u'Result: '.format(result.qcontext['pager']))
return result