main.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. # -*- coding: utf-8 -*-
  2. # Part of BiztechCS. See LICENSE file for full copyright and licensing details.
  3. import re
  4. from odoo import http
  5. from odoo.http import request
  6. from odoo.addons.website.models.website import slug
  7. from odoo.addons.website.controllers.main import QueryURL
  8. from odoo.addons.website_sale.controllers import main
  9. from odoo.addons.website_sale.controllers import main as main_shop
  10. from odoo.addons.website_sale.controllers.main import WebsiteSale
  11. from odoo.addons.website_sale.controllers.main import TableCompute
  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.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.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.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(WebsiteSale):
  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. if brand:
  139. req_ctx = request.context.copy()
  140. req_ctx.setdefault('brand_id', int(brand))
  141. request.context = req_ctx
  142. result = super(KingfisherProBrandSlider, self).shop(
  143. page=page, category=category, brand=brand, search=search, **post)
  144. sort_order = ""
  145. cat_id = []
  146. ppg = main_shop.PPG
  147. product_tmp = []
  148. newproduct = []
  149. product_price = []
  150. # product template object
  151. product_obj = request.env['product.template']
  152. attrib_list = request.httprequest.args.getlist('attrib')
  153. attrib_values = [map(int, v.split("-")) for v in attrib_list if v]
  154. attributes_ids = set([v[0] for v in attrib_values])
  155. attrib_set = set([v[1] for v in attrib_values])
  156. domain = request.website.sale_product_domain()
  157. domain += self._get_search_domain(search, category, attrib_values)
  158. url = "/shop"
  159. if post:
  160. request.session.update(post)
  161. prevurl = request.httprequest.referrer
  162. if prevurl:
  163. if not re.search('/shop', prevurl, re.IGNORECASE):
  164. request.session['tag'] = ""
  165. request.session['sort_id'] = ""
  166. request.session['sortid'] = ""
  167. request.session['pricerange'] = ""
  168. request.session['min1'] = ""
  169. request.session['max1'] = ""
  170. session = request.session
  171. # for category filter
  172. if category:
  173. category = request.env['product.public.category'].browse(int(category))
  174. url = "/shop/category/%s" % slug(category)
  175. if category != None:
  176. for ids in category:
  177. cat_id.append(ids.id)
  178. domain += ['|', ('public_categ_ids.id', 'in', cat_id),
  179. ('public_categ_ids.parent_id', 'in', cat_id)]
  180. # for tag filter
  181. if session.get('tag'):
  182. session_tag = session.get('tag')[0]
  183. tag = session_tag
  184. if tag:
  185. tag = request.env['biztech.product.tags'].browse(int(tag))
  186. domain += [('biztech_tag_ids', '=', int(tag))]
  187. request.session["tag"] = [tag.id, tag.name]
  188. # For Product Sorting
  189. if session.get('sort_id'):
  190. session_sort = session.get('sort_id')
  191. sort = session_sort
  192. sort_field = request.env['biztech.product.sortby'].browse(int(sort))
  193. request.session['product_sort_name'] = sort_field.name
  194. order_field = sort_field.sort_on.name
  195. order_type = sort_field.sort_type
  196. sort_order = '%s %s' % (order_field, order_type)
  197. if post.get("sort_id"):
  198. request.session["sortid"] = [sort, sort_order, sort_field.name, order_type]
  199. # For Price slider
  200. product_withprice = product_obj.search([])
  201. for product in product_withprice:
  202. product_price.append(product.website_price)
  203. if product_withprice:
  204. if post.get("range1") or post.get("range2") or not post.get("range1") or not post.get("range2"):
  205. range1 = min(product_price)
  206. range2 = max(product_price)
  207. result.qcontext['range1'] = range1
  208. result.qcontext['range2'] = range2
  209. if session.get("min1") and session["min1"]:
  210. post["min1"] = session["min1"]
  211. if session.get("max1") and session["max1"]:
  212. post["max1"] = session["max1"]
  213. if range1:
  214. post["range1"] = range1
  215. if range1:
  216. post["range2"] = range1
  217. if request.session.get('min1') or request.session.get('max1'):
  218. if request.session.get('min1'):
  219. if request.session['min1'] != None:
  220. for prod_id in product_withprice:
  221. if prod_id.website_price >= float(request.session['min1']) and prod_id.website_price <= float(request.session['max1']):
  222. product_tmp.append(prod_id.id)
  223. request.session["pricerange"] = str(
  224. request.session['min1'])+"-To-"+str(request.session['max1'])
  225. newproduct = product_tmp
  226. domain += [('id', 'in', newproduct)]
  227. if session.get('min1') and session['min1']:
  228. result.qcontext['min1'] = session["min1"]
  229. result.qcontext['max1'] = session["max1"]
  230. if request.session.get('default_paging_no'):
  231. ppg = int(request.session.get('default_paging_no'))
  232. product_count = product_obj.search_count(domain)
  233. pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
  234. products = product_obj.search(domain, limit=ppg, offset=pager['offset'], order=sort_order)
  235. result.qcontext.update({'product_count': product_count,
  236. 'products': products,
  237. 'category': category,
  238. 'pager': pager,
  239. 'bins': TableCompute().process(products, ppg)})
  240. result.qcontext['brand'] = brand
  241. result.qcontext['brand_obj'] = request.env['product.brands'].search([('id', '=', brand)])
  242. return result
  243. @http.route()
  244. def cart_update_json(self, product_id, line_id=None, add_qty=None, set_qty=None, display=True):
  245. result = super(KingfisherProBrandSlider, self).cart_update_json(
  246. product_id, line_id, add_qty, set_qty, display)
  247. order = request.website.sale_get_order()
  248. result.update({'kingfisher_pro.hover_total': request.env['ir.ui.view'].render_template("kingfisher_pro.hover_total", {
  249. 'website_sale_order': order })
  250. })
  251. return result
  252. @http.route(['/king_pro/get_brand_slider'], type='http', auth='public', website=True)
  253. def get_brand_slider(self, **post):
  254. keep = QueryURL('/king_pro/get_brand_slider', brand_id=[])
  255. value = {
  256. 'website_brands': False,
  257. 'brand_header': False,
  258. 'keep': keep
  259. }
  260. if post.get('product_count'):
  261. brand_data = request.env['product.brands'].search(
  262. [], limit=int(post.get('product_count')))
  263. if brand_data:
  264. value['website_brands'] = brand_data
  265. if post.get('product_label'):
  266. value['brand_header'] = post.get('product_label')
  267. return request.render("kingfisher_pro.kingfisher_pro_brand_slider_view", value)
  268. @http.route(['/kingfisher_pro/removeattribute'], type='json', auth='public', website=True)
  269. def remove_selected_attribute(self, **post):
  270. if post.get("attr_remove"):
  271. remove = post.get("attr_remove")
  272. if remove == "pricerange":
  273. del request.session['min1']
  274. del request.session['max1']
  275. request.session[remove] = ''
  276. return True
  277. elif remove == "sortid":
  278. request.session[remove] = ''
  279. request.session["sort_id"] = ''
  280. return True
  281. elif remove == "tag":
  282. request.session[remove] = ''
  283. return True