123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- # -*- coding: utf-8 -*-
- # Part of AppJetty. See LICENSE file for full copyright and licensing details.
- import re
- from openerp import http
- from openerp.http import request
- from openerp.addons.website.models.website import slug
- from openerp.addons.website_sale.controllers import main
- from openerp.addons.website_sale.controllers import main as main_shop
- from openerp.addons.website_sale.controllers.main import QueryURL
- from openerp.addons.website_sale.controllers.main import website_sale
- from openerp.addons.website_sale.controllers.main import table_compute
- class KingfisherProSliderSettings(http.Controller):
- @http.route(['/kingfisher_pro/pro_get_options'], type='json', auth="public", website=True)
- def get_slider_options(self):
- slider_options = []
- option = request.env['product.category.slider.config'].search(
- [('active', '=', True)], order="name asc")
- for record in option:
- slider_options.append({'id': record.id,
- 'name': record.name})
- return slider_options
- @http.route(['/kingfisher_pro/pro_get_dynamic_slider'], type='http', auth='public', website=True)
- def get_dynamic_slider(self, **post):
- if post.get('slider-type'):
- slider_header = request.env['product.category.slider.config'].sudo().search(
- [('id', '=', int(post.get('slider-type')))])
- values = {
- 'slider_header': slider_header
- }
- if slider_header.prod_cat_type == 'product':
- values.update({'slider_details': slider_header.collections_product})
- if slider_header.prod_cat_type == 'category':
- values.update({'slider_details': slider_header.collections_category})
- values.update({'slider_type': slider_header.prod_cat_type})
- return request.website.render("kingfisher_pro.kingfisher_pro_pro_cat_slider_view", values)
- @http.route(['/kingfisher_pro/pro_image_effect_config'], type='json', auth='public', website=True)
- def product_image_dynamic_slider(self, **post):
- slider_data = request.env['product.category.slider.config'].search(
- [('id', '=', int(post.get('slider_type')))])
- values = {
- 's_id': slider_data.prod_cat_type + str(slider_data.id),
- 'counts': slider_data.no_of_counts,
- 'auto_rotate': slider_data.auto_rotate,
- 'auto_play_time': slider_data.sliding_speed,
- }
- return values
- @http.route(['/kingfisher_pro/blog_get_options'], type='json', auth="public", website=True)
- def king_blog_get_slider_options(self):
- slider_options = []
- option = request.env['blog.slider.config'].search(
- [('active', '=', True)], order="name asc")
- for record in option:
- slider_options.append({'id': record.id,
- 'name': record.name})
- return slider_options
- @http.route(['/kingfisher_pro/blog_get_dynamic_slider'], type='http', auth='public', website=True)
- def king_blog_get_dynamic_slider(self, **post):
- if post.get('slider-type'):
- slider_header = request.env['blog.slider.config'].sudo().search(
- [('id', '=', int(post.get('slider-type')))])
- values = {
- 'slider_header': slider_header,
- 'blog_slider_details': slider_header.collections_blog_post,
- }
- return request.website.render("kingfisher_pro.kingfisher_pro_blog_slider_view", values)
- @http.route(['/kingfisher_pro/blog_image_effect_config'], type='json', auth='public', website=True)
- def king_blog_product_image_dynamic_slider(self, **post):
- slider_data = request.env['blog.slider.config'].search(
- [('id', '=', int(post.get('slider_type')))])
- values = {
- 's_id': slider_data.no_of_counts + '-' + str(slider_data.id),
- 'counts': slider_data.no_of_counts,
- 'auto_rotate': slider_data.auto_rotate,
- 'auto_play_time': slider_data.sliding_speed,
- }
- return values
- # Multi image gallery
- @http.route(['/kingfisher_pro/multi_image_effect_config'], type='json', auth="public", website=True)
- def get_multi_image_effect_config(self):
- cur_website = request.website
- values = {
- 'no_extra_options': cur_website.no_extra_options,
- 'theme_panel_position': cur_website.thumbnail_panel_position,
- 'interval_play': cur_website.interval_play,
- 'enable_disable_text': cur_website.enable_disable_text,
- 'color_opt_thumbnail': cur_website.color_opt_thumbnail,
- 'change_thumbnail_size': cur_website.change_thumbnail_size,
- 'thumb_height': cur_website.thumb_height,
- 'thumb_width': cur_website.thumb_width,
- }
- return values
- # For multi product slider
- @http.route(['/kingfisher_pro/product_multi_get_options'], type='json', auth="public", website=True)
- def product_multi_get_slider_options(self):
- slider_options = []
- option = request.env['multi.slider.config'].search(
- [('active', '=', True)], order="name asc")
- for record in option:
- slider_options.append({'id': record.id,
- 'name': record.name})
- return slider_options
- @http.route(['/kingfisher_pro/product_multi_get_dynamic_slider'], type='http', auth='public', website=True)
- def product_multi_get_dynamic_slider(self, **post):
- if post.get('slider-type'):
- slider_header = request.env['multi.slider.config'].sudo().search(
- [('id', '=', int(post.get('slider-type')))])
- values = {
- 'slider_details': slider_header,
- 'slider_header': slider_header
- }
- return request.website.render("kingfisher_pro.kingfisher_pro_multi_cat_slider_view", values)
- @http.route(['/kingfisher_pro/product_multi_image_effect_config'], type='json', auth='public', website=True)
- def product_multi_product_image_dynamic_slider(self, **post):
- slider_data = request.env['multi.slider.config'].search(
- [('id', '=', int(post.get('slider_type')))])
- values = {
- 's_id': slider_data.no_of_collection + '-' + str(slider_data.id),
- 'counts': slider_data.no_of_collection,
- 'auto_rotate': slider_data.auto_rotate,
- 'auto_play_time': slider_data.sliding_speed,
- }
- return values
- class KingfisherProBrandSlider(website_sale):
- @http.route(['/shop/pager_selection/<model("product.per.page.no"):pl_id>'], type='http', auth="public", website=True)
- def product_page_change(self, pl_id, **post):
- request.session['default_paging_no'] = pl_id.name
- main.PPG = pl_id.name
- return request.redirect('/shop' or request.httprequest.referrer)
- @http.route(['/shop',
- '/shop/page/<int:page>',
- '/shop/category/<model("product.public.category"):category>',
- '/shop/category/<model("product.public.category"):category>/page/<int:page>',
- '/shop/brands'],
- type='http',
- auth='public',
- website=True)
- def shop(self, page=0, category=None, brand=None, search='', ppg=False, **post):
- cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
- if brand:
- request.context.setdefault('brand_id', int(brand))
- result = super(KingfisherProBrandSlider, self).shop(
- page=page, category=category, brand=brand, search=search, **post)
- sort_order = ""
- cat_id = []
- page_obj = pool.get('product.per.page.no')
- page_id = page_obj.search(
- cr, uid, [('set_default_check', '=', True)], context=context)
- page_no = page_obj.browse(cr, uid, page_id, context=context)
- if page_no:
- ppg = page_no.name
- else:
- ppg = main_shop.PPG
- product = []
- newproduct = []
- # 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"
- # For Product tags
- keep = QueryURL('/shop', category=category and int(category), search=search,
- attrib=attrib_list, order=post.get('order'))
- if post:
- request.session.update(post)
- if search:
- post["search"] = search
- if attrib_list:
- post['attrib'] = attrib_list
- 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(
- cr, uid, int(category), context=context)
- 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(cr, uid, [], context=context)
- tags = tags_obj.browse(cr, uid, tags_ids, context=context)
- if tag:
- tag = pool['biztech.product.tags'].browse(cr, uid, int(tag), context=context)
- domain += [('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(cr, uid, [], context=context)
- sorts = sorts_obj.browse(cr, uid, sorts_ids, context=context)
- sort_field = pool['biztech.product.sortby'].browse(cr, uid, int(sort), context=context)
- 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 = product_obj.search(cr, uid, [], context=context)
- products_slider = product_obj.browse(cr, uid, product_slider_ids, context=context)
- product_withprice = products_slider._product_template_price(products_slider, domain)
- if product_withprice:
- if post.get("range1") or post.get("range2") or not post.get("range1") or not post.get("range2"):
- range1 = min(product_withprice.values())
- range2 = max(product_withprice.values())
- 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 range1:
- post["range2"] = range1
- if request.session.get('min1') or request.session.get('max1'):
- if request.session.get('min1'):
- if request.session['min1'] != None:
- for prod_id in product_withprice:
- if product_withprice.get(prod_id) >= float(request.session['min1']) and product_withprice.get(prod_id) <= float(request.session['max1']):
- product.append(prod_id)
- request.session["pricerange"] = str(
- request.session['min1'])+"-To-"+str(request.session['max1'])
- newproduct = product
- domain += [('id', 'in', newproduct)]
- 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'))
- # For Collascpe category
- parent_category_ids = []
- if category:
- parent_category_ids = [category.id]
- current_category = category
- while current_category.parent_id:
- parent_category_ids.append(current_category.parent_id.id)
- current_category = current_category.parent_id
- result.qcontext['parent_category_ids'] = parent_category_ids
- product_count = product_obj.search_count(cr, uid, domain, context=context)
- pager = request.website.pager(
- url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
- product_ids = product_obj.search(
- cr, uid, domain, limit=ppg, offset=pager['offset'], order=sort_order, context=context)
- products = product_obj.browse(cr, uid, product_ids, context=context)
- result.qcontext.update({'product_count': product_count})
- result.qcontext.update({'products': products})
- result.qcontext.update({'category': category})
- result.qcontext.update({'pager': pager})
- result.qcontext.update({'keep': keep})
- result.qcontext.update({'search': search})
- result.qcontext.update({'bins': table_compute().process(products)})
- result.qcontext['brand'] = brand
- result.qcontext['brand_obj'] = request.env['product.brands'].search([('id', '=', brand)])
- return result
- @http.route()
- def cart_update_json(self, product_id, line_id=None, add_qty=None, set_qty=None, display=True):
- result = super(KingfisherProBrandSlider, self).cart_update_json(
- product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty, display=display)
- result.update({'kingfisher_pro.hover_total': request.website._render("kingfisher_pro.hover_total", {
- 'website_sale_order': request.website.sale_get_order()
- })
- })
- return result
- @http.route(['/king_pro/get_brand_slider'], type='http', auth='public', website=True)
- def get_brand_slider(self, **post):
- keep = QueryURL('/king_pro/get_brand_slider', brand_id=[])
- value = {
- 'website_brands': False,
- 'brand_header': False,
- 'keep': keep
- }
- if post.get('product_count'):
- brand_data = request.env['product.brands'].search(
- [], limit=int(post.get('product_count')))
- if brand_data:
- value['website_brands'] = brand_data
- if post.get('product_label'):
- value['brand_header'] = post.get('product_label')
- return request.website.render("kingfisher_pro.kingfisher_pro_brand_slider_view", value)
- @http.route(['/kingfisher_pro/removeattribute'], type='json', auth='public', website=True)
- def remove_selected_attribute(self, **post):
- if post.get("attr_remove"):
- remove = post.get("attr_remove")
- if remove == "pricerange":
- del request.session['min1']
- del request.session['max1']
- request.session[remove] = ''
- return True
- elif remove == "sortid":
- request.session[remove] = ''
- request.session["sort_id"] = ''
- return True
- elif remove == "tag":
- request.session[remove] = ''
- return True
|