コード例 #1
0
    def Brand(self,
              brand=None,
              page=0,
              category=None,
              search='',
              ppg=False,
              **post):
        add_qty = int(post.get('add_qty', 1))
        Category = request.env['product.public.category']
        if category:
            category = Category.search([('id', '=', int(category))], limit=1)
            if not category or not category.can_access_from_current_website():
                raise NotFound()
        else:
            category = Category

        if ppg:
            try:
                ppg = int(ppg)
                post['ppg'] = ppg
            except ValueError:
                ppg = False
        if not ppg:
            ppg = 20

        ppr = 4

        attrib_list = request.httprequest.args.getlist('attrib')
        attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list
                         if v]
        attributes_ids = {v[0] for v in attrib_values}
        attrib_set = {v[1] for v in attrib_values}

        domain = WebsiteSale._get_search_domain(self, search, category,
                                                attrib_values)

        # Set the brand product
        if brand:
            domain += [('product_brand_ept_id.id', '=', brand.id)]
        else:
            domain += [('product_brand_ept_id', '!=', False)]

        keep = QueryURL('/shop',
                        category=category and int(category),
                        search=search,
                        attrib=attrib_list,
                        order=post.get('order'))

        pricelist_context, pricelist = WebsiteSale._get_pricelist_context(self)

        request.context = dict(request.context,
                               pricelist=pricelist.id,
                               partner=request.env.user.partner_id)

        url = "/shop"
        if search:
            post["search"] = search
        if attrib_list:
            post['attrib'] = attrib_list

        Product = request.env['product.template'].with_context(bin_size=True)

        search_product = Product.search(domain)
        website_domain = request.website.website_domain()
        categs_domain = [('parent_id', '=', False)] + website_domain
        # if search:
        #     search_categories = Category.search(
        #         [('product_tmpl_ids', 'in', search_product.ids)] + website_domain).parents_and_self
        #     categs_domain.append(('id', 'in', search_categories.ids))
        # else:
        #     search_categories = Category
        search_categories = False
        if search:
            categories = search_product.mapped('public_categ_ids')
            search_categories = Category.search(
                [('id', 'parent_of', categories.ids)] +
                request.website.website_domain())
            categs = search_categories.filtered(lambda c: not c.parent_id)
        else:
            categs = Category.search([('parent_id', '=', False)] +
                                     request.website.website_domain())
        # categs = Category.search(categs_domain)

        if category:
            url = "/shop/category/%s" % slug(category)

        product_count = len(search_product)
        pager = request.website.pager(url=url,
                                      total=product_count,
                                      page=page,
                                      step=ppg,
                                      scope=7,
                                      url_args=post)
        products = Product.search(domain,
                                  limit=ppg,
                                  offset=pager['offset'],
                                  order=WebsiteSale._get_search_order(
                                      self, post))

        ProductAttribute = request.env['product.attribute']
        # if products:
        #     # get all products without limit
        #     attributes = ProductAttribute.search([('product_tmpl_ids', 'in', search_product.ids)])
        # else:
        #     attributes = ProductAttribute.browse(attributes_ids)

        if products:
            attributes = ProductAttribute.search([
                ('attribute_line_ids.value_ids', '!=', False),
                ('attribute_line_ids.product_tmpl_id', 'in',
                 search_product.ids)
            ])
        else:
            attributes = ProductAttribute.browse(attributes_ids)

        layout_mode = request.session.get('website_sale_shop_layout_mode')
        if not layout_mode:
            if request.website.viewref(
                    'website_sale.products_list_view').active:
                layout_mode = 'list'
            else:
                layout_mode = 'grid'

        values = {
            'search': search,
            'category': category,
            'attrib_values': attrib_values,
            'attrib_set': attrib_set,
            'pager': pager,
            'pricelist': pricelist,
            'add_qty': add_qty,
            'products': products,
            'search_count': product_count,  # common for all searchbox
            'bins': TableCompute().process(products, ppg, ppr),
            'ppg': ppg,
            'ppr': ppr,
            'categories': categs,
            'attributes': attributes,
            'keep': keep,
            # 'search_categories_ids': search_categories.ids,
            'layout_mode': layout_mode,
            'brand': brand,
            'is_brand_page': True
        }
        if category:
            values['main_object'] = category
        return request.render("website_sale.products", values)
コード例 #2
0
ファイル: amp_main.py プロジェクト: dionisiotorres/googletag
    def shop_amp(self, page=0, category=None, search='', ppg=False, **post):
        if request.website.is_amp_enable:
            add_qty = int(post.get('add_qty', 1))
            Category = request.env['product.public.category']
            if category:
                category = Category.search([('id', '=', int(category))],
                                           limit=1)
                if not category or not category.can_access_from_current_website(
                ):
                    raise NotFound()
            else:
                category = Category

            page_no = request.env['product.per.page.no'].sudo().search([
                ('set_default_check', '=', True)
            ])
            if page_no:
                ppg = int(page_no.name)
            else:
                ppg = result.qcontext['ppg']

            ppr = request.env['website'].get_current_website().shop_ppr or 4

            attrib_list = request.httprequest.args.getlist('attrib')
            attrib_values = [[int(x) for x in v.split("-")]
                             for v in attrib_list if v]
            attributes_ids = {v[0] for v in attrib_values}
            attrib_set = {v[1] for v in attrib_values}

            domain = self._get_search_domain(search, category, attrib_values)
            if request.session.get('default_paging_no'):
                ppg = int(request.session.get('default_paging_no'))
            keep = QueryURL('/shop/amp',
                            category=category and int(category),
                            search=search,
                            attrib=attrib_list,
                            order=post.get('order'))

            pricelist_context, pricelist = WebsiteSale._get_pricelist_context(
                self)

            request.context = dict(request.context,
                                   pricelist=pricelist.id,
                                   partner=request.env.user.partner_id)

            url = "/shop/amp"
            if search:
                post["search"] = search
            if attrib_list:
                post['attrib'] = attrib_list

            Product = request.env['product.template'].with_context(
                bin_size=True)

            search_product = Product.search(domain)
            website_domain = request.website.website_domain()
            categs_domain = [('parent_id', '=', False)] + website_domain
            if search:
                search_categories = Category.search(
                    [('product_tmpl_ids', 'in', search_product.ids)] +
                    website_domain).parents_and_self
                categs_domain.append(('id', 'in', search_categories.ids))
            else:
                search_categories = Category
            categs = Category.search(categs_domain)

            if category:
                url = "/shop/amp/category/%s" % slug(category)

            product_count = len(search_product)
            pager = request.website.pager(url=url,
                                          total=product_count,
                                          page=page,
                                          step=ppg,
                                          scope=7,
                                          url_args=post)
            products = Product.search(domain,
                                      limit=ppg,
                                      offset=pager['offset'],
                                      order=self._get_search_order(post))

            ProductAttribute = request.env['product.attribute']
            if products:
                # get all products without limit
                attributes = ProductAttribute.search([
                    ('product_tmpl_ids', 'in', search_product.ids)
                ])
            else:
                attributes = ProductAttribute.browse(attributes_ids)

            layout_mode = request.session.get('website_sale_shop_layout_mode')
            if not layout_mode:
                if request.website.viewref(
                        'website_sale.products_list_view').active:
                    layout_mode = 'list'
                else:
                    layout_mode = 'grid'

            values = {
                'search': search,
                'category': category,
                'attrib_values': attrib_values,
                'attrib_set': attrib_set,
                'pager': pager,
                'pricelist': pricelist,
                'add_qty': add_qty,
                'products': products,
                'search_count': product_count,  # common for all searchbox
                'bins': TableCompute().process(products, ppg, ppr),
                'ppg': ppg,
                'ppr': ppr,
                'categories': categs,
                'attributes': attributes,
                'keep': keep,
                'search_categories_ids': search_categories.ids,
                'layout_mode': layout_mode,
            }
            if category:
                values['main_object'] = category
            return request.render("theme_scita.apm_shop_page_view", values)
        else:
            raise NotFound()