Tusa Products Posted May 23, 2017 Share Posted May 23, 2017 Hello all. I'm having troubles getting product.tpl and product-details.tpl to access the $logged variable, as referenced in many threads over many forums whose solutions I've been attempting to implement all day. What I'm trying to accomplish in product.tpl is to prevent loading product-details.tpl unless the user is logged in. The simplest way I've tried to implement it is this: {if $logged} {block name='product_details'} {include file='catalog/_partials/product-details.tpl'} {/block} {/if} However, $logged is always shown as false, even when the a customer is logged in, meaning that this is always hidden. I am using Prestashop 1.7 with a modified theme, but the only references to the $logged variable are as normal in the Cookie.php. Having read up on the issue a bunch, I am thinking that my issue is that product.tpl is reading from Product.php and not the cookie, but I've not had any luck getting product.tpl to do anything useful. Any help anyone could give would be great. Thank you. Link to comment Share on other sites More sharing options...
BalzoT Posted May 23, 2017 Share Posted May 23, 2017 Hi there I think you have typed the variable wrong. try {if $is_logged} Link to comment Share on other sites More sharing options...
Tusa Products Posted May 23, 2017 Author Share Posted May 23, 2017 Hi there I think you have typed the variable wrong. try {if $is_logged} Thank you. That was one of the suggested solutions from my reading. $is_logged and $is_Logged produce the same lack of result. Link to comment Share on other sites More sharing options...
BalzoT Posted May 23, 2017 Share Posted May 23, 2017 By taking a look at Prestashop 1.7 code I found this snippet of code beeing used. {if $customer.is_logged && !$customer.is_guest} Hope this is the case ! 1 Link to comment Share on other sites More sharing options...
Tusa Products Posted May 24, 2017 Author Share Posted May 24, 2017 (edited) Brilliant. Just tried this, and it works perfectly. Thank you very much. It looks like Prestashop went from utilizing global variables in smarty to using customer variables between 1.6 and 1.7. Edited May 24, 2017 by Tusa Products (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted May 24, 2017 Share Posted May 24, 2017 I think the problem with this approach is that you only cover one price display scenario, i.e. best sales/featured/etc etc.... I'm new to template inheritance so I'm curious if the one solution worked for price display 'everywhere"? 1 Link to comment Share on other sites More sharing options...
Tusa Products Posted May 24, 2017 Author Share Posted May 24, 2017 (edited) I think the problem with this approach is that you only cover one price display scenario, i.e. best sales/featured/etc etc.... I'm new to template inheritance so I'm curious if the one solution worked for price display 'everywhere"? In my particular scenario it's not necessary, but based on BalzoT's post, I went into classes/Customer.php, where $is_guest is defined. Also defined in that file is $id_default_group. I haven't tried it, but it should work similarly based on a customer's default group rather than just a logged in, logged out situation. Edit to add: In fact, looking deeper through, you could pare down your settings to a number of very specific levels should you so choose without having to define your own variables. In classes/controller/FrontController.php, where the is_logged seems to be defined, there are a number of other fields which you could use via smarty with $customer. A few I noticed at a glance were $customer.gender, $customer.id_risk (from the risk setting in the back end for customers). Even as specific as $customer.id_customer if you want to tailor specific content to specific customers. Not much need in a retail situation for that, but it could be beneficial in a fully Business to Business set up, as mine is. Edited May 24, 2017 by Tusa Products (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now