Jump to content

how to pass smarty variable in other module's js file ?


Recommended Posts

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

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

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

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

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

 

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

  • 2 years later...
  • 1 month later...

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

  • 1 year later...
  • 3 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...