Exemple #1
0
    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.TableCompute().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)
Exemple #2
0
    def cfg_session(self, cfg_session, **post):
        try:
            product_tmpl = cfg_session.product_tmpl_id
        except:
            return request.redirect('/configurator')
        if post:
            custom_vals = {
                x.attribute_id.id: x.value or x.attachment_ids
                for x in cfg_session.custom_value_ids
            }
            product = cfg_session.product_tmpl_id.sudo().create_get_variant(
                cfg_session.value_ids.ids, custom_vals)
            cfg_session.sudo().unlink()
            return self.cart_update(product, post)

        def _get_product_vals(cfg_session):
            vals = [val for val in cfg_session.value_ids]
            vals += [val for val in cfg_session.custom_value_ids]
            return sorted(vals, key=lambda obj: obj.attribute_id.sequence)

        # product_obj = request.env['product.product'].with_context(
        #     active_id=product.id)

        pricelist = self.get_pricelist()

        keep = main.QueryURL('/configurator')

        # from_currency = request.env.user.with_context(
        #     active_id=product.id).company_id.currency_id
        # to_currency = pricelist.currency_id
        # compute_currency =
        # lambda price: request.env['res.currency']._compute(
        #     from_currency, to_currency, price)

        # if not request.env.context.get('pricelist'):
        #     product_obj = product_obj.with_context(pricelist=int(pricelist))
        # product = product_obj.browse(int(product))
        values = {
            'get_product_vals': _get_product_vals,
            'get_config_image': self.get_config_image,
            'product_tmpl': product_tmpl,
            # 'cfg_vars': self.config_vars(product.product_tmpl_id),
            # 'compute_currency': compute_currency,
            # 'main_object': product,
            'pricelist': pricelist,
            # 'product': product,
            'cfg_session': cfg_session,
            'keep': keep,
        }
        return request.render("website_product_configurator.cfg_session",
                              values)
Exemple #3
0
    def action_configure(self,
                         product_tmpl,
                         config_step=None,
                         category='',
                         **post):
        """ Controller called to parse the form of configurable products"""

        # TODO: Use a client-side session for the configuration values with a
        # expiration date set
        def _get_class_dependencies(value, dependencies):
            if value.id in dependencies:
                return ' '.join(str(dep) for dep in dependencies[value.id])
            return False

        # category_obj = request.env['product.public.category']

        # if category:
        #     category = category_obj.browse(int(category))
        # category = category if category.exists() else False

        cfg_err = None
        fatal_error = None
        cfg_vars = self.config_vars(product_tmpl, active_step=config_step)

        post = self.parse_config_post(product_tmpl)

        if request.httprequest.method == 'POST':
            parsed_vals = self.config_parse(product_tmpl, post, config_step)
            if parsed_vals['errors']:
                cfg_err = parsed_vals['errors']
            else:
                self.config_update(parsed_vals,
                                   cfg_session=cfg_vars['cfg_session'])

            if not cfg_vars.get('next_step') and not cfg_err:
                self.config_update(parsed_vals,
                                   cfg_session=cfg_vars['cfg_session'])
                redirect = self.config_redirect(
                    product_tmpl, config_step, post,
                    cfg_vars['cfg_session'].value_ids.ids, {
                        x.attribute_id.id: x.value or x.attachment_ids
                        for x in cfg_vars['cfg_session'].custom_value_ids
                    })
                if redirect:
                    return redirect

                if cfg_vars['cfg_session'].sudo().action_confirm():
                    return self.product_redirect(cfg_vars['cfg_session'])
                else:
                    fatal_error = 'The configurator encountered a problem, '\
                                  'please try again later'

        redirect = self.config_redirect(
            product_tmpl, config_step, post,
            cfg_vars['cfg_session'].value_ids.ids, {
                x.attribute_id.id: x.value or x.attachment_ids
                for x in cfg_vars['cfg_session'].custom_value_ids
            })
        if redirect:
            return redirect

        pricelist = self.get_pricelist()

        keep = main.QueryURL('/configurator',
                             category=category and category.id)

        vals = {
            'json': json,
            # 'category': category,
            'product_tmpl': product_tmpl,
            'pricelist': pricelist,
            'get_class_dependencies': _get_class_dependencies,
            'get_attr_classes': self.get_attr_classes,
            'get_config_image': self.get_config_image,
            'cfg_err': cfg_err,
            'keep': keep,
            'fatal_error': fatal_error,
        }

        template_name = 'website_product_configurator.product_configurator'
        vals.update({'cfg_vars': cfg_vars})
        return request.render(template_name, vals)