main.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. # -*- coding: utf-8 -*-
  2. # Part of Biztech Consultancy. See LICENSE file for full copyright and licensing details.
  3. import re
  4. from openerp import http
  5. from openerp.http import request
  6. from openerp.addons.website.models.website import slug
  7. from openerp.addons.website_sale.controllers import main
  8. from openerp.addons.website_sale.controllers import main as main_shop
  9. from openerp.addons.website_sale.controllers.main import QueryURL
  10. from openerp.addons.website_sale.controllers.main import website_sale
  11. from openerp.addons.website_sale.controllers.main import table_compute
  12. class KingfisherProSliderSettings(http.Controller):
  13. @http.route(['/kingfisher_pro/pro_get_options'], type='json', auth="public", website=True)
  14. def get_slider_options(self):
  15. slider_options = []
  16. option = request.env['product.category.slider.config'].search(
  17. [('active', '=', True)], order="name asc")
  18. for record in option:
  19. slider_options.append({'id': record.id,
  20. 'name': record.name})
  21. return slider_options
  22. @http.route(['/kingfisher_pro/pro_get_dynamic_slider'], type='http', auth='public', website=True)
  23. def get_dynamic_slider(self, **post):
  24. if post.get('slider-type'):
  25. slider_header = request.env['product.category.slider.config'].sudo().search(
  26. [('id', '=', int(post.get('slider-type')))])
  27. values = {
  28. 'slider_header': slider_header
  29. }
  30. if slider_header.prod_cat_type == 'product':
  31. values.update({'slider_details': slider_header.collections_product})
  32. if slider_header.prod_cat_type == 'category':
  33. values.update({'slider_details': slider_header.collections_category})
  34. values.update({'slider_type': slider_header.prod_cat_type})
  35. return request.website.render("kingfisher_pro.kingfisher_pro_pro_cat_slider_view", values)
  36. @http.route(['/kingfisher_pro/pro_image_effect_config'], type='json', auth='public', website=True)
  37. def product_image_dynamic_slider(self, **post):
  38. slider_data = request.env['product.category.slider.config'].search(
  39. [('id', '=', int(post.get('slider_type')))])
  40. values = {
  41. 's_id': slider_data.prod_cat_type + str(slider_data.id),
  42. 'counts': slider_data.no_of_counts,
  43. 'auto_rotate': slider_data.auto_rotate,
  44. 'auto_play_time': slider_data.sliding_speed,
  45. }
  46. return values
  47. @http.route(['/kingfisher_pro/blog_get_options'], type='json', auth="public", website=True)
  48. def king_blog_get_slider_options(self):
  49. slider_options = []
  50. option = request.env['blog.slider.config'].search(
  51. [('active', '=', True)], order="name asc")
  52. for record in option:
  53. slider_options.append({'id': record.id,
  54. 'name': record.name})
  55. return slider_options
  56. @http.route(['/kingfisher_pro/blog_get_dynamic_slider'], type='http', auth='public', website=True)
  57. def king_blog_get_dynamic_slider(self, **post):
  58. if post.get('slider-type'):
  59. slider_header = request.env['blog.slider.config'].sudo().search(
  60. [('id', '=', int(post.get('slider-type')))])
  61. values = {
  62. 'slider_header': slider_header,
  63. 'blog_slider_details': slider_header.collections_blog_post,
  64. }
  65. return request.website.render("kingfisher_pro.kingfisher_pro_blog_slider_view", values)
  66. @http.route(['/kingfisher_pro/blog_image_effect_config'], type='json', auth='public', website=True)
  67. def king_blog_product_image_dynamic_slider(self, **post):
  68. slider_data = request.env['blog.slider.config'].search(
  69. [('id', '=', int(post.get('slider_type')))])
  70. values = {
  71. 's_id': slider_data.no_of_counts + '-' + str(slider_data.id),
  72. 'counts': slider_data.no_of_counts,
  73. 'auto_rotate': slider_data.auto_rotate,
  74. 'auto_play_time': slider_data.sliding_speed,
  75. }
  76. return values
  77. # Multi image gallery
  78. @http.route(['/kingfisher_pro/multi_image_effect_config'], type='json', auth="public", website=True)
  79. def get_multi_image_effect_config(self):
  80. cur_website = request.website
  81. values = {
  82. 'no_extra_options': cur_website.no_extra_options,
  83. 'theme_panel_position': cur_website.thumbnail_panel_position,
  84. 'interval_play': cur_website.interval_play,
  85. 'enable_disable_text': cur_website.enable_disable_text,
  86. 'color_opt_thumbnail': cur_website.color_opt_thumbnail,
  87. 'change_thumbnail_size': cur_website.change_thumbnail_size,
  88. 'thumb_height': cur_website.thumb_height,
  89. 'thumb_width': cur_website.thumb_width,
  90. }
  91. return values
  92. # For multi product slider
  93. @http.route(['/kingfisher_pro/product_multi_get_options'], type='json', auth="public", website=True)
  94. def product_multi_get_slider_options(self):
  95. slider_options = []
  96. option = request.env['multi.slider.config'].search(
  97. [('active', '=', True)], order="name asc")
  98. for record in option:
  99. slider_options.append({'id': record.id,
  100. 'name': record.name})
  101. return slider_options
  102. @http.route(['/kingfisher_pro/product_multi_get_dynamic_slider'], type='http', auth='public', website=True)
  103. def product_multi_get_dynamic_slider(self, **post):
  104. if post.get('slider-type'):
  105. slider_header = request.env['multi.slider.config'].sudo().search(
  106. [('id', '=', int(post.get('slider-type')))])
  107. values = {
  108. 'slider_details': slider_header,
  109. 'slider_header': slider_header
  110. }
  111. return request.website.render("kingfisher_pro.kingfisher_pro_multi_cat_slider_view", values)
  112. @http.route(['/kingfisher_pro/product_multi_image_effect_config'], type='json', auth='public', website=True)
  113. def product_multi_product_image_dynamic_slider(self, **post):
  114. slider_data = request.env['multi.slider.config'].search(
  115. [('id', '=', int(post.get('slider_type')))])
  116. values = {
  117. 's_id': slider_data.no_of_collection + '-' + str(slider_data.id),
  118. 'counts': slider_data.no_of_collection,
  119. 'auto_rotate': slider_data.auto_rotate,
  120. 'auto_play_time': slider_data.sliding_speed,
  121. }
  122. return values
  123. class KingfisherProBrandSlider(website_sale):
  124. @http.route(['/shop/pager_selection/<model("product.per.page.no"):pl_id>'], type='http', auth="public", website=True)
  125. def product_page_change(self, pl_id, **post):
  126. request.session['default_paging_no'] = pl_id.name
  127. main.PPG = pl_id.name
  128. return request.redirect('/shop' or request.httprequest.referrer)
  129. @http.route(['/shop',
  130. '/shop/page/<int:page>',
  131. '/shop/category/<model("product.public.category"):category>',
  132. '/shop/category/<model("product.public.category"):category>/page/<int:page>',
  133. '/shop/brands'],
  134. type='http',
  135. auth='public',
  136. website=True)
  137. def shop(self, page=0, category=None, brand=None, search='', ppg=False, **post):
  138. cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
  139. if brand:
  140. request.context.setdefault('brand_id', int(brand))
  141. result = super(KingfisherProBrandSlider, self).shop(
  142. page=page, category=category, brand=brand, search=search, **post)
  143. sort_order = ""
  144. cat_id = []
  145. page_obj = pool.get('product.per.page.no')
  146. page_id = page_obj.search(
  147. cr, uid, [('set_default_check', '=', True)], context=context)
  148. page_no = page_obj.browse(cr, uid, page_id, context=context)
  149. if page_no:
  150. ppg = page_no.name
  151. else:
  152. ppg = main_shop.PPG
  153. product = []
  154. newproduct = []
  155. # product template object
  156. product_obj = pool.get('product.template')
  157. attrib_list = request.httprequest.args.getlist('attrib')
  158. attrib_values = [map(int, v.split("-")) for v in attrib_list if v]
  159. attributes_ids = set([v[0] for v in attrib_values])
  160. attrib_set = set([v[1] for v in attrib_values])
  161. domain = request.website.sale_product_domain()
  162. domain += self._get_search_domain(search, category, attrib_values)
  163. url = "/shop"
  164. # For Product tags
  165. keep = QueryURL('/shop', category=category and int(category), search=search,
  166. attrib=attrib_list, order=post.get('order'))
  167. if post:
  168. request.session.update(post)
  169. if search:
  170. post["search"] = search
  171. if attrib_list:
  172. post['attrib'] = attrib_list
  173. prevurl = request.httprequest.referrer
  174. if prevurl:
  175. if not re.search('/shop', prevurl, re.IGNORECASE):
  176. request.session['tag'] = ""
  177. request.session['sort_id'] = ""
  178. request.session['sortid'] = ""
  179. request.session['pricerange'] = ""
  180. request.session['min1'] = ""
  181. request.session['max1'] = ""
  182. session = request.session
  183. # for category filter
  184. if category:
  185. category = pool['product.public.category'].browse(
  186. cr, uid, int(category), context=context)
  187. url = "/shop/category/%s" % slug(category)
  188. if category != None:
  189. for ids in category:
  190. cat_id.append(ids.id)
  191. domain += ['|', ('public_categ_ids.id', 'in', cat_id),
  192. ('public_categ_ids.parent_id', 'in', cat_id)]
  193. # for tag filter
  194. if session.get('tag'):
  195. session_tag = session.get('tag')
  196. tag = session_tag[0]
  197. tags_obj = pool['biztech.product.tags']
  198. tags_ids = tags_obj.search(cr, uid, [], context=context)
  199. tags = tags_obj.browse(cr, uid, tags_ids, context=context)
  200. if tag:
  201. tag = pool['biztech.product.tags'].browse(cr, uid, int(tag), context=context)
  202. domain += [('tag_ids', '=', int(tag))]
  203. request.session["tag"] = [tag.id, tag.name]
  204. # For Product Sorting
  205. if session.get('sort_id'):
  206. session_sort = session.get('sort_id')
  207. sort = session_sort
  208. sorts_obj = pool['biztech.product.sortby']
  209. sorts_ids = sorts_obj.search(cr, uid, [], context=context)
  210. sorts = sorts_obj.browse(cr, uid, sorts_ids, context=context)
  211. sort_field = pool['biztech.product.sortby'].browse(cr, uid, int(sort), context=context)
  212. request.session['product_sort_name'] = sort_field.name
  213. order_field = sort_field.sort_on.name
  214. order_type = sort_field.sort_type
  215. sort_order = '%s %s' % (order_field, order_type)
  216. if post.get("sort_id"):
  217. request.session["sortid"] = [sort, sort_order, sort_field.name, order_type]
  218. # For Price slider
  219. product_slider_ids = []
  220. asc_product_slider_id = product_obj.search(cr, uid,
  221. [('website_published', '=', True)], limit=1, order='list_price')
  222. desc_product_slider_id = product_obj.search(cr, uid,
  223. [('website_published', '=', True)], limit=1, order='list_price desc')
  224. asc_product_slider_ids = product_obj.browse(
  225. cr, uid, asc_product_slider_id, context=context)
  226. desc_product_slider_ids = product_obj.browse(
  227. cr, uid, desc_product_slider_id, context=context)
  228. if asc_product_slider_ids:
  229. product_slider_ids.append(asc_product_slider_ids.list_price)
  230. if desc_product_slider_ids:
  231. product_slider_ids.append(desc_product_slider_ids.list_price)
  232. if product_slider_ids:
  233. if post.get("range1") or post.get("range2") or not post.get("range1") or not post.get("range2"):
  234. range1 = min(product_slider_ids)
  235. range2 = max(product_slider_ids)
  236. result.qcontext['range1'] = range1
  237. result.qcontext['range2'] = range2
  238. if session.get("min1") and session["min1"]:
  239. post["min1"] = session["min1"]
  240. if session.get("max1") and session["max1"]:
  241. post["max1"] = session["max1"]
  242. if range1:
  243. post["range1"] = range1
  244. if range2:
  245. post["range2"] = range2
  246. if range1 == range2:
  247. post['range1'] = 0.0
  248. if request.session.get('min1') or request.session.get('max1'):
  249. if request.session.get('min1'):
  250. if request.session['min1'] != None:
  251. domain += [('list_price', '>=', request.session.get('min1')),
  252. ('list_price', '<=', request.session.get('max1'))]
  253. request.session["pricerange"] = str(
  254. request.session['min1'])+"-To-"+str(request.session['max1'])
  255. newproduct = product
  256. domain += [('id', 'in', newproduct)]
  257. if session.get('min1') and session['min1']:
  258. result.qcontext['min1'] = session["min1"]
  259. result.qcontext['max1'] = session["max1"]
  260. if request.session.get('default_paging_no'):
  261. ppg = int(request.session.get('default_paging_no'))
  262. # For Collascpe category
  263. parent_category_ids = []
  264. if category:
  265. parent_category_ids = [category.id]
  266. current_category = category
  267. while current_category.parent_id:
  268. parent_category_ids.append(current_category.parent_id.id)
  269. current_category = current_category.parent_id
  270. result.qcontext['parent_category_ids'] = parent_category_ids
  271. product_count = product_obj.search_count(cr, uid, domain, context=context)
  272. pager = request.website.pager(
  273. url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
  274. product_ids = product_obj.search(
  275. cr, uid, domain, limit=ppg, offset=pager['offset'], order=sort_order, context=context)
  276. products = product_obj.browse(cr, uid, product_ids, context=context)
  277. result.qcontext.update({'product_count': product_count})
  278. result.qcontext.update({'products': products})
  279. result.qcontext.update({'category': category})
  280. result.qcontext.update({'pager': pager})
  281. result.qcontext.update({'keep': keep})
  282. result.qcontext.update({'search': search})
  283. result.qcontext.update({'bins': table_compute().process(products)})
  284. result.qcontext['brand'] = brand
  285. result.qcontext['brand_obj'] = request.env['product.brands'].search([('id', '=', brand)])
  286. return result
  287. @http.route()
  288. def cart_update_json(self, product_id, line_id=None, add_qty=None, set_qty=None, display=True):
  289. result = super(KingfisherProBrandSlider, self).cart_update_json(
  290. product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty, display=display)
  291. result.update({'kingfisher_pro.hover_total': request.website._render("kingfisher_pro.hover_total", {
  292. 'website_sale_order': request.website.sale_get_order()
  293. })
  294. })
  295. return result
  296. @http.route(['/king_pro/get_brand_slider'], type='http', auth='public', website=True)
  297. def get_brand_slider(self, **post):
  298. keep = QueryURL('/king_pro/get_brand_slider', brand_id=[])
  299. value = {
  300. 'website_brands': False,
  301. 'brand_header': False,
  302. 'keep': keep
  303. }
  304. if post.get('product_count'):
  305. brand_data = request.env['product.brands'].search(
  306. [], limit=int(post.get('product_count')))
  307. if brand_data:
  308. value['website_brands'] = brand_data
  309. if post.get('product_label'):
  310. value['brand_header'] = post.get('product_label')
  311. return request.website.render("kingfisher_pro.kingfisher_pro_brand_slider_view", value)
  312. @http.route(['/kingfisher_pro/removeattribute'], type='json', auth='public', website=True)
  313. def remove_selected_attribute(self, **post):
  314. if post.get("attr_remove"):
  315. remove = post.get("attr_remove")
  316. if remove == "pricerange":
  317. del request.session['min1']
  318. del request.session['max1']
  319. request.session[remove] = ''
  320. return True
  321. elif remove == "sortid":
  322. request.session[remove] = ''
  323. request.session["sort_id"] = ''
  324. return True
  325. elif remove == "tag":
  326. request.session[remove] = ''
  327. return True
  328. @http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True)
  329. def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
  330. cr, uid, context = request.cr, request.uid, request.context
  331. request.website.sale_get_order(force_create=1)._cart_update(product_id=int(product_id), add_qty=float(add_qty), set_qty=float(set_qty))
  332. #return request.redirect("/shop/cart")
  333. prod_obj = request.registry.get('product.product')
  334. product = prod_obj.browse(cr,uid,int(product_id),context=context)
  335. tpl_obj = request.registry('product.template')
  336. tpl_ids = tpl_obj.search(cr,uid, [('id', '=', product.product_tmpl_id.id)],context=context);
  337. template = tpl_obj.browse(cr,uid,tpl_ids, context=context)
  338. return request.redirect('/shop/product/%s' % slug(template))