jahyax Posted November 15, 2013 Share Posted November 15, 2013 Good day, the following is my code in product controller: if (isset($this->product->unity) && $this->product->unity) { $this->context->cookie->__set($uty_opt, 'w_prc'); } and in product.tpl , I am trying to display the cookie if it is already set my code is <input type="text" value="{$uty_opt}" /> cookie value doesn't seems to appear ''''''''''My Goal''''''' Link to comment Share on other sites More sharing options...
El Patron Posted November 15, 2013 Share Posted November 15, 2013 $this->context->cookie->your_tag = __set($uty_opt, 'w_prc'); then pass your_tag in smarty array from product controller $this->smarty->assign('your_tag', $this->context->cookie->your_tag); in your .tpl file you can access the variable with $your_tag 1 Link to comment Share on other sites More sharing options...
El Patron Posted November 15, 2013 Share Posted November 15, 2013 note: creating a one off hack is one thing. Make sure that you investigate hook processing, i.e. rather than 'hack' core find a hook that will allow you to insert your code. I realize hooks are not always in the place you need them. But let's say you have a 'great' hack, if you accomplish without changing base code, you will end up with a 'portable' module that won't get 'lost' when you upgrade (productcontroller)...heck best case scenario is you can list it on addon's and make some money. learn more here http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5 Link to comment Share on other sites More sharing options...
jahyax Posted November 18, 2013 Author Share Posted November 18, 2013 $this->context->cookie->your_tag = __set($uty_opt, 'w_prc'); then pass your_tag in smarty array from product controller $this->smarty->assign('your_tag', $this->context->cookie->your_tag); in your .tpl file you can access the variable with $your_tag thanks, I will try with these. 1 Link to comment Share on other sites More sharing options...
jahyax Posted November 18, 2013 Author Share Posted November 18, 2013 El Patron, i did try your code suggestion I get this instead on product.tpl Fatal error: Call to undefined function __set() in ..../controllers\front\ProductController.php Link to comment Share on other sites More sharing options...
El Patron Posted November 18, 2013 Share Posted November 18, 2013 El Patron, i did try your code suggestion I get this instead on product.tpl Fatal error: Call to undefined function __set() in ..../controllers\front\ProductController.php the function __set was used in your original example, I assumed you had that function already coded...if not then you will need to build that function.... Link to comment Share on other sites More sharing options...
jahyax Posted November 18, 2013 Author Share Posted November 18, 2013 the function __set was used in your original example, I assumed you had that function already coded...if not then you will need to build that function.... sorry, __set, was something I researched in the internet, when I try to use it, i had no error, I was assuming it is a valid prestashop method in setting up a cookie.. sorry for the confusion What I really want to achieve is to Make a custom or additional cookie for the front page(product.tpl) that will hold a value. Link to comment Share on other sites More sharing options...
El Patron Posted November 18, 2013 Share Posted November 18, 2013 $this->context->cookie->your_tag = 'some value' then pass your_tag in smarty array from product controller $this->smarty->assign('your_tag', $this->context->cookie->your_tag); in your .tpl file you can access the variable with $your_tag revised without the function call Link to comment Share on other sites More sharing options...
jahyax Posted November 18, 2013 Author Share Posted November 18, 2013 (edited) El Patron, this is current what i have on my codes.. ProductController: if (isset($this->product->unity) && $this->product->unity) { $this->context->cookie->your_tag = 'some value' $this->smarty->assign('your_tag', $this->context->cookie->your_tag); } and on product.tpl {$your_tag} and I am getting 'Fatal error: Call to a member function assign() on a non-object in controllers\front\ProductController.php' Am I missing something? Edited November 18, 2013 by jahyax (see edit history) Link to comment Share on other sites More sharing options...
joseantgv Posted April 14, 2016 Share Posted April 14, 2016 El Patron, this is current what i have on my codes.. ProductController: if (isset($this->product->unity) && $this->product->unity) { $this->context->cookie->your_tag = 'some value' $this->smarty->assign('your_tag', $this->context->cookie->your_tag); } and on product.tpl {$your_tag} and I am getting 'Fatal error: Call to a member function assign() on a non-object in controllers\front\ProductController.php' Am I missing something? Try with: $this->context->smarty->assign('your_tag', $this->context->cookie->your_tag); 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