Skip to Content
Menu
This question has been flagged

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

Avatar
Discard
Best Answer

Probably your problem is related to rendering this template (from website_sale/view/templates.xml):

<template id="search" name="Search hidden fields">
<form t-att-action="keep('/shop'+ ('/category/'+slug(category)) if category else '', search=0)" method="get" t-att-class="search_class">
....
</form>
</template>


UPDATE:

My sugestion, try to override (inherit)  /shop controller like this:

from openerp.addons.website_sale.controllers.main import website_sale
class Extension(website_sale):

@http.route(['/shop',
'/shop/myshop',
'/shop/page/<int:page>',
'/shop/category/<model("product.public.category"):category>',
'/shop/category/<model("product.public.category"):category>/page/<int:page>'
], type='http', auth="public", website=True)

def shop(self, page=0, category=None, search='', **post):
### do_before() !!!
_logger.info('My SHOP')
return super(Extension, self).shop(page=page, category=category, search=search, **post)


Avatar
Discard
Author

Hi Zbik! Its indeed related to it but I honestly have no clue how I can redirect it correctly.. It seems to be missing some values or something. That is really the part where I'm stuck. Any ideas?

Why do not you start with site /shop/categoryselection, without redirection from /shop? In the current situation, you have a redirect loop... /shop -> /shop/categoryselection -> /shop ->....

or you need to change /shop route ...

Author

@zbik I do start with /shop/selection, I simply redirect when the user clicks on shop (so on the controller I do request.redirect from /shop to /shop/categoryselection) and when the user is done there is a submit button. After clicking on this button the user should see all products that match the filter but I'm not sure how.. By the way you can see the full code here: https://github.com/Yenthe666/Dev/tree/master/aa_houbolak

Answer updated

Related Posts Replies Views Activity
0
Jun 24
682
4
Oct 20
4314
2
Mar 16
3257
3
Jun 24
22044
0
Feb 18
3406