Hi guys,
I want to change the default behaviour from the webshop but I'm not entirely sure how to do this.
When the user clicks on 'shop' I want it to redirect to another page, where the user has to choose a value from the dropdown. After the users chooses an item from the dropdown and clicks on the submit button he should be send to the shop and should only see products that meet this criteria.
I've first made a controller that redirects:
#Make a redirect first. @http.route(['/shop'], type='http', auth="public", website=True) def redirect(self, **post): return request.redirect("/shop/categoryselection")
Then I made a new controller for the new view like this:
#Page that shows dropdown for all kind of finishing types @http.route(['/shop/categoryselection'], type='http', auth="public", website=True) def categoryselection(self, **post): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry order = request.website.sale_get_order() finishing_ids = pool['sale.order.finishing'].search(cr, uid, [('website_publish', '=', True)], context=context) afwerkingen = pool['sale.order.finishing'].browse(cr, uid, finishing_ids, context=context) values = dict(order=order, afwerkingen=afwerkingen) if post: _logger.warning("in if post:") if post.get('afwerking'): _logger.warning("in if post.get") order.write({'afwerkingpicker': int(post.get('afwerking'))}) return request.redirect("/shop") return request.website.render("website_sale.products", values)
The new page has the following XML to render it:
<template id="categoryselection"> <t t-call="website.layout"> <div id="wrap"> <div class="container oe_website_sale"> <h1 class="mb32">Kies een categorie</h1> <div class="row"> <form method="post" class=""> <div class="row bg-info" style="padding:15px;margin-top:30px;border-radius:15px;"> <div class="form-inline form-group"> <label for="afwerking" class="h4">Type afwerking</label> <br /> <select id="afwerking" name="afwerking" class="form-control"> <t t-foreach="afwerkingen" t-as="afwerking"> <option t-att-value='afwerking.id'> <span t-field="afwerking.name" /> </option> </t> </select> </div> </div> <input type="submit" class='btn btn-primary pull-right' value='Bevestigen'/> </form> </div> </div> </div> </t> </template>
However this request.website.render gives me the following error:
QWebException: "'NoneType' object is not callable" while evaluating "keep('/shop'+ ('/category/'+slug(category)) if category else '', search=0)"
I'm not quite sure how I should fix this and then my second question is also.. how can I only show the products that meet the selected value from the dropdown? The selection is filled with data from the model sale.order.finishing and on my product view I made a Many2many that links to sale.order.finishing so that the user can choose which product belongs to which finishing.
The product view:
<!-- Inherit product view and add Many2many --> <record id="product.product_template_only_form_view_inherit" model="ir.ui.view"> <field name="name">product.template.product.inherit</field> <field name="model">product.template</field> <field name="inherit_id" ref="product.product_template_only_form_view"/> <field name="arch" type="xml"> <xpath expr="//field[@name='description']" position="before"> <group> <field name="afwerkingpickerProduct"/> </group> </xpath> </field> </record>
and the python code behind this view:
#Add many2many (for finishing on product) to product.template class aa_houbolak_finishing_in_product_model(models.Model): _inherit = 'product.template' afwerkingpickerProduct = fields.Many2many('sale.order.finishing','product_finishing_rel','src_id_finishing','dest_id_finishing',string='Afwerking(en):')
Thanks,
Yenthe