Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to add an extra step in the webshop flow?

By
Yenthe
on 6/22/15, 10:50 AM 2,054 views

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

1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 6/28/15, 4:56 PM

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)


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?

Yenthe
on 6/29/15, 2:03 AM

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 ->....

zbik
on 6/29/15, 3:17 AM

or you need to change /shop route ...

Ahmed M.Elmubarak
on 6/29/15, 4:59 AM

@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

Yenthe
on 6/30/15, 2:07 AM

Answer updated

zbik
on 6/30/15, 12:04 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 6/22/15, 10:50 AM
Seen: 2054 times
Last updated: 6/30/15, 12:05 PM