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 do I check when a user is login or not when he is clicked on "shop" for shopping cart eCommerce?

By
Krishna
on 7/7/16, 1:47 AM 247 views

Can i able to check like this?

<record id="shop_click" inherit_id="website_sale.menu_shop" name="is_shop_clicked">

    <xpath expr="//field[@url='/shop']" position="replace">

        <template id="login" inherit_id="auth_signup.signup" name="Sign up login">

            <t t-esc="Shop_click()">

            <xpath expr="//input[@name='redirect']" position="replace">

                <input type="hidden" name="redirect" t-att-value="redirect + '&amp;redirect=/shop' "/>

           </xpath>

      </template>

     </xpath>

</record>

1

Axel Mendoza

--Axel Mendoza--
10205
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 7/7/16, 2:29 AM

If what you wanna accomplish is to make sure that the user is logged in before use the shop checkout you could find this helpful

https://www.odoo.com/es_ES/forum/ayuda-1/question/login-feature-in-odoo-104396#answer-104427

*** Update: how to be able to make a function call inside a template ***

To be able to call a function in a template you are saying that you need to enhance the template generated code by calling a function, for that you have basically 2 ways:

1- You need to put that function inside the context of the template to be rendered. For example(taken from the controller of the module website_sale):

def get_attribute_value_ids(self, product):

...

attribute_value_ids = []

...

return attribute_value_ids

@http.route([

'/shop',

'/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):

...

compute_currency = lambda price: pool['res.currency']._compute(cr, uid, from_currency, to_currency, price, context=context)

values = {

...

'compute_currency': compute_currency,

...

'get_attribute_value_ids': self.get_attribute_value_ids

}

return request.website.render("website_sale.product", values)

2- Put the function in a model that is available already as a record value in the context of the template to be rendered so you just need to do for example:

<t t-raw="product.function_name"/>

There are others scenarios when you wanna execute some code into js or make a call to the server to execute the code in a server side controller.


Heartily thank you for your replay, can you please tell me that how to call a function inside a template

Krishna
on 7/7/16, 2:52 AM

see my answer update for more

Axel Mendoza
on 7/7/16, 3:18 AM

Hi Mendoza can you please tell me that what is product stands in "product.function_name"

Krishna
on 7/7/16, 5:15 AM

something like this:

<pre>

from openerp import models, fields

class solt_product_template(model.Model):

_inherit = 'product.template'

@api.multi

def get_function_name(self):

for el in self:

el.function_name = '<h1>Hello</h1>'

function_name = fields.Html('Description for the website footer', compute='get_function_name')

</pre>

Axel Mendoza
on 7/7/16, 5:34 AM

I didnt mean that code me just want to know that if it is something like that a variable or module.

Krishna
on 7/7/16, 5:45 AM

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

1 follower(s)

Stats

Asked: 7/7/16, 1:47 AM
Seen: 247 times
Last updated: 7/7/16, 2:29 AM