def select_template(self, **kw): template_obj = request.env['product.template'] templates = template_obj.search([('config_ok', '=', True)]) tmpl_ext_id = 'website_product_configurator.product_configurator_list' style_obj = request.env['product.style'] styles = style_obj.search([]) keep = main.QueryURL('/configurator') values = { 'templates': templates, 'bins': main.table_compute().process(templates), 'styles': styles, 'keep': keep, 'rows': main.PPR, 'style_in_product': lambda style, product: style.id in [ s.id for s in product.website_style_ids], } return request.render(tmpl_ext_id, values)
def calculate_grid(self, products): return table_compute().process(products)
def shop(self, page=0, category=None, search='', **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry domain = request.website.sale_product_domain() if search.startswith("sku"): search_list = search.split("-") grado = search_list[1] if not search_list[1] == "all" else "-" ancho = search_list[2] if not search_list[2] == "all" else "-" alto = search_list[3] if not search_list[3] == "all" else "-" aro = search_list[4] if not search_list[4] == "all" else "" cantidad = search_list[5] clasification = search_list[6] select_search = "{}%{}%{}%{}".format(grado, ancho, alto, aro) if "qty0510" in cantidad: domain += ['&', '&', ("qty_available", ">=", 5), ("qty_available", "<=", 10)] elif "qty1025" in cantidad: domain += ['&', '&', ("qty_available", ">=", 10), ("qty_available", "<=", 25)] elif "qty2550" in cantidad: domain += ['&', '&', ("qty_available", ">=", 25), ("qty_available", "<=", 50)] elif "qty5000" in cantidad: domain += ['&', ("qty_available", ">", 50)] if "clap" in clasification: domain += [('clasification', '=', "p")] elif "clag" in clasification: domain += [('clasification', '=', "g")] elif "clas" in clasification: domain += [('clasification', '=', "s")] elif "clab" in clasification: domain += [('clasification', '=', "b")] if select_search: domain += ['|', '|', '|', ('name', 'ilike', select_search), ('description', 'ilike', select_search), ('description_sale', 'ilike', select_search), ('product_variant_ids.default_code', 'ilike', select_search)] if category: domain += [('public_categ_ids', 'child_of', int(category))] else: if search: domain += ['|', '|', '|', ('name', 'ilike', search), ('description', 'ilike', search), ('description_sale', 'ilike', search), ('product_variant_ids.default_code', 'ilike', search)] if category: domain += [('public_categ_ids', 'child_of', int(category))] attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) if attrib_values: attrib = None ids = [] for value in attrib_values: if not attrib: attrib = value[0] ids.append(value[1]) elif value[0] == attrib: ids.append(value[1]) else: domain += [('attribute_line_ids.value_ids', 'in', ids)] attrib = value[0] ids = [value[1]] if attrib: domain += [('attribute_line_ids.value_ids', 'in', ids)] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse(cr, uid, context['pricelist'], context) product_obj = pool.get('product.template') url = "/shop" product_count = product_obj.search_count(cr, uid, domain, context=context) if search: post["search"] = search if category: category = pool['product.public.category'].browse(cr, uid, int(category), context=context) url = "/shop/category/%s" % slug(category) 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='website_published desc, website_sequence desc', context=context) products = product_obj.browse(cr, uid, product_ids, context=context) style_obj = pool['product.style'] style_ids = style_obj.search(cr, uid, [], context=context) styles = style_obj.browse(cr, uid, style_ids, context=context) category_obj = pool['product.public.category'] category_ids = category_obj.search(cr, uid, [], context=context) categories = category_obj.browse(cr, uid, category_ids, context=context) categs = filter(lambda x: not x.parent_id, categories) attributes_obj = request.registry['product.attribute'] attributes_ids = attributes_obj.search(cr, uid, [], context=context) attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context) from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib', i) for i in attribs]), } return request.website.render("website_sale.products", values)
def shop(self, page=0, category=None, search='', ppg=False, **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry result = super(CrafitoEcommerceShop, self).shop(page=page, category=category, search=search, **post) sort_order = "" cat_id = [] ppg = 18 product = [] newproduct = [] # product template object product_obj = pool['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['sort_id'] = "" 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 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 = [] asc_product_slider_ids = product_obj.search(cr, uid, [], limit=1, order='list_price', context=context) asc_products_slider = product_obj.browse(cr, uid, asc_product_slider_ids, context=context) desc_product_slider_ids = product_obj.search(cr, uid, [], limit=1, order='list_price desc', context=context) desc_products_slider = product_obj.browse(cr, uid, desc_product_slider_ids, context=context) if asc_products_slider and asc_products_slider.list_price: product_slider_ids.append(asc_products_slider.list_price) if desc_products_slider and desc_products_slider.list_price: product_slider_ids.append(desc_products_slider.list_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: slid_product_ids = product_obj.search( cr, uid, [('list_price', '>=', request.session.get('min1')), ('list_price', '<=', request.session.get('max1')) ], context=context) slid_products = product_obj.browse(cr, uid, slid_product_ids, context=context) for prod_id in slid_products: if prod_id.list_price >= float( request.session['min1'] ) and prod_id.list_price <= float( request.session['max1']): product.append(prod_id.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"] 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) # 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 result.qcontext.update({ 'product_count': product_count, 'products': products, 'category': category, 'pager': pager, 'bins': table_compute().process(products) }) return result
def shop(self, page=0, category=None, search='', seller=None, **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry domain = request.website.sale_product_domain() if search: for srch in search.split(" "): domain += ['|', '|', '|', ('name', 'ilike', srch), ('description', 'ilike', srch), ('description_sale', 'ilike', srch), ('product_variant_ids.default_code', 'ilike', srch)] if category: domain += [('public_categ_ids', 'child_of', int(category))] if seller: domain += [('section_id', '=', int(seller))] attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int,v.split("-")) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) if attrib_values: attrib = None ids = [] for value in attrib_values: if not attrib: attrib = value[0] ids.append(value[1]) elif value[0] == attrib: ids.append(value[1]) else: domain += [('attribute_line_ids.value_ids', 'in', ids)] attrib = value[0] ids = [value[1]] if attrib: domain += [('attribute_line_ids.value_ids', 'in', ids)] keep = QueryURL('/shop', category=category and int(category), search=search, seller=seller and int(seller), attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse(cr, uid, context['pricelist'], context) product_obj = pool.get('product.template') url = "/shop" product_count = product_obj.search_count(cr, uid, domain, context=context) if search: post["search"] = search if category: category = pool['product.public.category'].browse(cr, uid, int(category), context=context) url = "/shop/category/%s" % slug(category) 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='website_published desc, website_sequence desc', context=context) products = product_obj.browse(cr, uid, product_ids, context=context) style_obj = pool['product.style'] style_ids = style_obj.search(cr, uid, [], context=context) styles = style_obj.browse(cr, uid, style_ids, context=context) category_obj = pool['product.public.category'] category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)], context=context) categs = category_obj.browse(cr, uid, category_ids, context=context) attributes_obj = request.registry['product.attribute'] attributes_ids = attributes_obj.search(cr, uid, [], context=context) attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context) from_currency = pool.get('product.price.type')._get_field_currency(cr, uid, 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib',i) for i in attribs]), } return request.website.render("website_sale.products", values)
def shop(self, page=0, ppg=False, house_type=False, gemeente=False, min_price=False, max_price=False, slaapkamers=False, soort_bebouwing=False, tuin=False, terras=False, garage=False, zwembad=False, lift=False, **post): old_sold = super(website_houses, self).shop(page=page, ppg=PPG, post=post) old_qcontext = old_sold.qcontext product_obj = http.request.env["product.template"] attribute_obj = http.request.env["xx.house.attribute"] filtered_products_list = product_obj.search([]) if house_type: filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('xx_house_type', '=', house_type) ]) post["house_type"] = house_type if gemeente: gemeente_string = gemeente post["gemeente"] = gemeente gem = "Ditisgeenechtegemeente" zip = "" words = gemeente_string.split() for word in words: if product_obj.search([('xx_city', 'ilike', word)]): gem = word else: if product_obj.search([('xx_zip', '=ilike', word)]): zip = word filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), '|', ('xx_zip', '=ilike', zip), ('xx_city', 'ilike', gem) ]) if min_price: filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('xx_current_price', '>=', min_price) ]) post["min_price"] = min_price if max_price: filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('xx_current_price', '<=', max_price) ]) post["max_price"] = max_price if slaapkamers: if slaapkamers == "4": attribute_list = attribute_obj.search([('name', 'ilike', "slaapkamer"), ('xx_value', '>=', 5)]) else: attribute_list = attribute_obj.search([ ('name', 'ilike', "slaapkamer"), ('xx_value', '=', int(slaapkamers) + 1) ]) house_id_set = set() for attr in attribute_list: house_id_set.add(attr.xx_house.id) house_id_list = list(house_id_set) filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('id', 'in', house_id_list) ]) post["slaapkamers"] = slaapkamers if soort_bebouwing: filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('xx_building_type', '=', soort_bebouwing) ]) post["soort_bebouwing"] = soort_bebouwing if tuin: attribute_list = attribute_obj.search([ ('name', 'ilike', tuin), '!', ('xx_value', 'ilike', 'nee') ]) house_id_set = set() for attr in attribute_list: house_id_set.add(attr.xx_house.id) house_id_list = list(house_id_set) filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('id', 'in', house_id_list) ]) post["tuin"] = tuin if terras: attribute_list = attribute_obj.search([ ('name', 'ilike', terras), '!', ('xx_value', 'ilike', 'nee') ]) house_id_set = set() for attr in attribute_list: house_id_set.add(attr.xx_house.id) house_id_list = list(house_id_set) filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('id', 'in', house_id_list) ]) post["terras"] = terras if garage: attribute_list = attribute_obj.search([ ('name', 'ilike', garage), '!', ('xx_value', 'ilike', 'nee') ]) house_id_set = set() for attr in attribute_list: house_id_set.add(attr.xx_house.id) house_id_list = list(house_id_set) filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('id', 'in', house_id_list) ]) post["garage"] = garage if zwembad: attribute_list = attribute_obj.search([ ('name', 'ilike', zwembad), '!', ('xx_value', 'ilike', 'nee') ]) house_id_set = set() for attr in attribute_list: house_id_set.add(attr.xx_house.id) house_id_list = list(house_id_set) filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('id', 'in', house_id_list) ]) post["zwembad"] = zwembad if lift: attribute_list = attribute_obj.search([ ('name', 'ilike', lift), '!', ('xx_value', 'ilike', 'nee') ]) house_id_set = set() for attr in attribute_list: house_id_set.add(attr.xx_house.id) house_id_list = list(house_id_set) filtered_products_list = product_obj.search([ ('id', 'in', filtered_products_list._ids), ('id', 'in', house_id_list) ]) post["lift"] = lift new_product_count = len(filtered_products_list._ids) pager = request.website.pager(url="/shop", total=new_product_count, page=page, step=PPG, scope=7, url_args=post) new_product_ids = product_obj.search( [('id', 'in', filtered_products_list._ids)], limit=PPG, offset=pager['offset'], order='website_published desc, website_sequence desc') house_type = [] for h_type in http.request.env['xx.house.type'].search([]): house_type.append(h_type.name) values = { 'search': old_qcontext.get('search'), 'category': old_qcontext.get('category'), 'attrib_values': old_qcontext.get('attrib_values'), 'attrib_set': old_qcontext.get('attrib_set'), 'pager': pager, 'pricelist': old_qcontext.get('pricelist'), 'products': new_product_ids, 'bins': table_compute().process(new_product_ids, PPG), 'rows': PPR, 'styles': old_qcontext.get('styles'), 'categories': old_qcontext.get('categs'), 'attributes': old_qcontext.get('attributes'), 'compute_currency': old_qcontext.get('compute_currency'), 'keep': old_qcontext.get('keep'), 'parent_category_ids': old_qcontext.get('parent_category_ids'), 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib', i) for i in attribs]), 'house_types': house_type } return request.website.render("website_sale.products", values)
def products(self, page=0, category=None, search='', **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) domain = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/product', category=category and int(category), search=search, attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse( cr, uid, context['pricelist'], context) product_obj = pool.get('product.template') url = "/shop" product_count = product_obj.search_count(cr, uid, domain, context=context) if search: post["search"] = search if category: category = pool['product.public.category'].browse(cr, uid, int(category), context=context) url = "/product/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list 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='website_published desc, website_sequence desc', context=context) products = product_obj.browse(cr, uid, product_ids, context=context) style_obj = pool['product.style'] style_ids = style_obj.search(cr, uid, [], context=context) styles = style_obj.browse(cr, uid, style_ids, context=context) category_obj = pool['product.public.category'] category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)], context=context) categs = category_obj.browse(cr, uid, category_ids, context=context) attributes_obj = request.registry['product.attribute'] attributes_ids = attributes_obj.search(cr, uid, [], context=context) attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context) from_currency = pool.get('product.price.type')._get_field_currency( cr, uid, 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute( cr, uid, from_currency, to_currency, price, context=context) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib', i) for i in attribs]), } return request.website.render("website_product.products", values)
def shop(self, page=0, category=None, condition=None, search='', **post): """replaced to add current delivery_condition TODO: compute values in a dedicated method""" cr, uid, context, pool = request.cr, request.uid, request.context, request.registry domain = request.website.sale_product_domain(context=context) if search: for srch in search.split(" "): domain += [ '|', '|', '|', ('name', 'ilike', srch), ('description', 'ilike', srch), ('description_sale', 'ilike', srch), ('product_variant_ids.default_code', 'ilike', srch) ] if category: domain += [('public_categ_ids', 'child_of', int(category))] category_obj = pool['product.public.category'] categ_domain = [('parent_id', '=', False)] url = "/shop" if condition: categs_ids = category_obj.search( cr, uid, [('condition_id', '=', condition.id)], context=context) #get only products with that delivery condition _logger.debug("shop page condition : %d", condition) domain += [('public_categ_ids', 'in', categs_ids)] categ_domain += [('condition_id', '=', condition.id)] url += "/type/%s" % slug(condition) #primary categs with that delivery condition #todo : assume that child categ have same delivery condition than parent ? attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [map(int, v.split("-")) for v in attrib_list if v] attrib_set = set([v[1] for v in attrib_values]) if attrib_values: attrib = None ids = [] for value in attrib_values: if not attrib: attrib = value[0] ids.append(value[1]) elif value[0] == attrib: ids.append(value[1]) else: domain += [('attribute_line_ids.value_ids', 'in', ids)] attrib = value[0] ids = [value[1]] if attrib: domain += [('attribute_line_ids.value_ids', 'in', ids)] keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse( cr, uid, context['pricelist'], context) product_obj = pool.get('product.template') product_count = product_obj.search_count(cr, uid, domain, context=context) if search: post["search"] = search if category: category = pool['product.public.category'].browse(cr, uid, int(category), context=context) url += "/category/%s" % slug(category) 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='website_published desc, website_sequence desc', context=context) products = product_obj.browse(cr, uid, product_ids, context=context) style_obj = pool['product.style'] style_ids = style_obj.search(cr, uid, [], context=context) styles = style_obj.browse(cr, uid, style_ids, context=context) category_ids = category_obj.search(cr, uid, categ_domain, context=context) categs = category_obj.browse(cr, uid, category_ids, context=context) attributes_obj = request.registry['product.attribute'] attributes_ids = attributes_obj.search(cr, uid, [], context=context) attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context) from_currency = pool.get('product.price.type')._get_field_currency( cr, uid, 'list_price', context) to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute( cr, uid, from_currency, to_currency, price, context=context) # delivery_condition = request.website.sale_get_delivery_condition() values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib', i) for i in attribs]), } values.update({ 'delivery_condition': delivery_condition, #for the description 'chosen_condition': condition }) #for correct links return request.website.render("website_sale.products", values)
def shop(self, category=None, page=0, filters='', search='', **post): cr, uid, context = request.cr, request.uid, request.context product_obj = request.registry.get('product.template') domain = request.registry.get('website').ecommerce_get_product_domain() if search: domain += [ '|', ('name', 'ilike', search), ('description', 'ilike', search) ] if category: domain.append(('product_variant_ids.public_categ_id', 'child_of', category.id)) if filters: filters = simplejson.loads(filters) if filters: ids = self.attributes_to_ids(filters) domain.append(('id', 'in', ids or [0])) product_count = product_obj.search_count(cr, uid, domain, context=context) pager = request.website.pager(url="/shop/", total=product_count, page=page, step=ecommerce.PPG, scope=7, url_args=post) request.context['pricelist'] = self.get_pricelist() pids = product_obj.search(cr, uid, domain, limit=ecommerce.PPG + 10, offset=pager['offset'], order=self._order, context=context) products_nofilter = product_obj.browse(cr, uid, pids, context=context) products = [ product for product in products_nofilter if product.product_variant_ids[0].virtual_available > 0 and not product.product_variant_ids[0].is_delivery ] styles = [] try: style_obj = request.registry.get('product.style') style_ids = style_obj.search(request.cr, request.uid, [], context=request.context) styles = style_obj.browse(request.cr, request.uid, style_ids, context=request.context) except: pass category_obj = request.registry.get('product.public.category') category_ids = category_obj.search(cr, uid, [], context=context) categories = category_obj.browse(cr, uid, category_ids, context=context) categs = filter(lambda x: not x.parent_id, categories) values = { 'products': products, 'bins': ecommerce.table_compute().process(products), 'rows': ecommerce.PPR, 'range': range, 'search': { 'search': search, 'category': category and category.id, 'filters': filters, }, 'pager': pager, 'styles': styles, '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], } return request.website.render("website_sale.products", values)
def shop(self, page=0, category=None, search='', ppg=False, **post): cr, uid, context, pool = request.cr, SUPERUSER_ID, request.context, request.registry if ppg: try: ppg = int(ppg) except ValueError: ppg = PPG post["ppg"] = ppg else: ppg = PPG 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 = self._get_search_domain(search, category, attrib_values) keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) if not context.get('pricelist'): pricelist = self.get_pricelist() context['pricelist'] = int(pricelist) else: pricelist = pool.get('product.pricelist').browse(cr, uid, context['pricelist'], context) url = "/shop" if search: post["search"] = search if category: category = pool['product.public.category'].browse(cr, uid, int(category), context=context) url = "/shop/category/%s" % slug(category) if attrib_list: post['attrib'] = attrib_list style_obj = pool['product.style'] style_ids = style_obj.search(cr, uid, [], context=context) styles = style_obj.browse(cr, uid, style_ids, context=context) category_obj = pool['product.public.category'] category_ids = category_obj.search(cr, uid, [('parent_id', '=', False)], context=context) categs = category_obj.browse(cr, uid, category_ids, context=context) product_obj = pool.get('product.template') attrib_domain = [] left_search_attrib = { 'attrib_products': [], 'attrib_wheels': [], 'attrib_model': [] } main_search_attrib = { 'brand_id': "", 'model_id' : "", 'size_id': "" } main_search_value = { 'brand_id': pool["sb.brands"].search_read(cr, uid, [],['name'] ,context=context), 'model_id': "", 'size_id': pool["sb.model.size"].search_read(cr, uid, [],['name'] ,context=context), } if post.get("attrib_products"): wheel_att = post.get("attrib_products").split("-") left_search_attrib['attrib_products'] = wheel_att attrib_domain += [('sb_type', 'in', wheel_att)] if post.get("attrib_wheels"): attrib_wheels = post.get("attrib_wheels").split("-") attrib_wheels = [int(x) for x in attrib_wheels] left_search_attrib['attrib_wheels'] = attrib_wheels attrib_domain += [('size_id', 'in', attrib_wheels)] if post.get("attrib_model"): attrib_model = post.get("attrib_model").split("-") attrib_model = [int(x) for x in attrib_model] left_search_attrib['attrib_model'] = attrib_model attrib_domain += [('model_id', 'in', attrib_model)] if post.get('domain_search'): make_id, model_id, size_id = post.get('domain_search').split("-") attrib_domain += [ ('make_id', '=', int(make_id)), ('model_id', '=', int(model_id)), ('size_id', '=', int(size_id)) ] main_search_value['model_id'] = pool['sb.vehicle.model'].search_read(cr, uid, [('brand_id', '=', int(make_id))], ['name']) main_search_attrib = { 'brand_id': int(make_id), 'model_id' : int(model_id), 'size_id': int(size_id) } if attrib_domain: vales = pool['product.product'].search_read(cr, uid, attrib_domain, ['product_tmpl_id']) domain += [('id', 'in',[x['product_tmpl_id'][0] for x in vales])] 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 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='website_published desc, website_sequence desc', context=context) products = product_obj.browse(cr, uid, product_ids, context=context) attributes_obj = request.registry['product.attribute'] if product_ids: attributes_ids = attributes_obj.search(cr, uid, [('attribute_line_ids.product_tmpl_id', 'in', product_ids)], context=context) attributes = attributes_obj.browse(cr, uid, attributes_ids, context=context) from_currency = pool['res.users'].browse(cr, uid, uid, context=context).company_id.currency_id to_currency = pricelist.currency_id compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context) sb_brand_ids = pool["sb.brands"].search_read(cr, uid, [],['name'] ,context=context) product_wheel_size = request.env['sb.model.size'].sudo().search([]) product_vehicle_model = request.env['sb.brands'].sudo().search([]) values = { 'search': search, 'category': category, 'attrib_values': attrib_values, 'attrib_set': attrib_set, 'pager': pager, 'pricelist': pricelist, 'products': products, 'bins': table_compute().process(products, ppg), 'rows': PPR, 'styles': styles, 'categories': categs, 'attributes': attributes, 'compute_currency': compute_currency, 'keep': keep, 'parent_category_ids': parent_category_ids, 'style_in_product': lambda style, product: style.id in [s.id for s in product.website_style_ids], 'attrib_encode': lambda attribs: werkzeug.url_encode([('attrib',i) for i in attribs]), 'sb_brand_ids': sb_brand_ids, 'p_wheel_size': product_wheel_size, 'p_vehicle_model': product_vehicle_model, 'left_search_attrib':left_search_attrib, 'main_search_attrib': main_search_attrib, 'main_search_value': main_search_value, } if category: values['main_object'] = category return request.website.render("website_sale.products", values)