NishantVadgama Posted May 8, 2014 Share Posted May 8, 2014 hello I want to pass my smarty variable in stores default module blockcart's ajax-cart.js file. how can i do this..? Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2014 Share Posted May 8, 2014 can you explain what you're trying to achieve? im confused a little, you said that you want to use smarty variable in ajax-cart.js file? or what? Link to comment Share on other sites More sharing options...
NishantVadgama Posted May 8, 2014 Author Share Posted May 8, 2014 can you explain what you're trying to achieve? im confused a little, you said that you want to use smarty variable in ajax-cart.js file? or what? yes i want to check in ajax-cart.js file that my module is enable or disable by passing smarty variable in that, or any other way i can check it..? Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2014 Share Posted May 8, 2014 in your store-contacts.tpl create code like <script> var myVariable = {$your_smarty_variable}; </script> then in ajax-cart.js file you can use myVariable variable 1 Link to comment Share on other sites More sharing options...
NishantVadgama Posted May 8, 2014 Author Share Posted May 8, 2014 in your store-contacts.tpl create code like <script> var myVariable = {$your_smarty_variable}; </script> then in ajax-cart.js file you can use myVariable variable that is i already know but my problem is how can i pass smarty i.e "{$your_smarty_variable};" for that i have to modify its php file Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2014 Share Posted May 8, 2014 okay so what tpl file you want to modify? you said about stores module you mean stores page? or stores block? Link to comment Share on other sites More sharing options...
NishantVadgama Posted May 8, 2014 Author Share Posted May 8, 2014 okay so what tpl file you want to modify? you said about stores module you mean stores page? or stores block? Prestashop_root_1.6.0.6\themes\default-bootstrap\js\modules\blockcart\ajax-cart.js in this file i want to pass smarty variable so that i have to modify its php as following file. Prestashop_root_1.6.0.6\modules\blockcart\blockcart.php there is only way that modify above file and assign smarty variable that uses in js file. Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2014 Share Posted May 8, 2014 im asking about template file, you have to include script to .tpl file where you want to display it? you want it to display globally? for whole website? Link to comment Share on other sites More sharing options...
NishantVadgama Posted May 8, 2014 Author Share Posted May 8, 2014 when click on add to cart button on product page item goes to cart using ajax-cart.js by calling following method //for product page 'add' button... $(document).on('click', '#add_to_cart button', function(e){ e.preventDefault(); ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val()); }); i want to do like //for product page 'add' button... $(document).on('click', '#add_to_cart button', function(e){ e.preventDefault(); if({$isMyModuleEnable}) ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null,$('#allow_partial_payment').val());//with one extra parameter else ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val());//default }); i hope now u can understand what i want to do with ajax-cart.js Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2014 Share Posted May 8, 2014 okay so in this case it must be global variable. you can define it for example in header.tpl file use code there that i suggested to use <script> var myVariable = {$your_smarty_variable}; </script> then in classes/controllers/FrontController.php you have to define this variable $your_smarty_variable in function: public function init() { } add this code to assign variable to smarty array $this->context->smarty->assign('your_smarty_variable', "value of variable"); Link to comment Share on other sites More sharing options...
NishantVadgama Posted May 8, 2014 Author Share Posted May 8, 2014 okay so in this case it must be global variable. you can define it for example in header.tpl file use code there that i suggested to use <script> var myVariable = {$your_smarty_variable}; </script> then in classes/controllers/FrontController.php you have to define this variable $your_smarty_variable in function: public function init() { } add this code to assign variable to smarty array $this->context->smarty->assign('your_smarty_variable', "value of variable"); Thank You for your quick response... i understand what u trying to say but in this case how can i define smarty variable in blockcart (other module's) php file ...? that is my problem dear Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2014 Share Posted May 8, 2014 in the same way as you did for other modules. just add $this->context->smarty->assign('your_smarty_variable', "value of variable"); to the hook of the module. Link to comment Share on other sites More sharing options...
marcin_jaworski Posted October 28, 2016 Share Posted October 28, 2016 In .tpl you can use: {addJsDef js_var_name=$smarty_var} That create global js var. Link to comment Share on other sites More sharing options...
Radhanatha Posted December 8, 2016 Share Posted December 8, 2016 Hi, Both prestashop1.6 and prestashop1.7 the below line are not working . <script>var myVariable = {$your_smarty_variable};</script> But below line is working in prestahsop1.6 not in prestahsop1.7. {addJsDef js_var_name=$smarty_var} please suggest me. Thanks Radha Link to comment Share on other sites More sharing options...
TinyStore Posted February 14, 2018 Share Posted February 14, 2018 I'm doing something similar and the init function needs a return: public function init() { $this->context->smarty->assign('your_smarty_variable', "value of variable"); return parent::init(); } Link to comment Share on other sites More sharing options...
re ma Posted May 26, 2018 Share Posted May 26, 2018 On Prestashop 1.7 you can use Media::addJsDef(array(JSVAR=>JSVALUE)); 1 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