tijojoel Posted October 30, 2017 Share Posted October 30, 2017 HI, I want to pass php variable from my module file to product.js file in themes. How to achieve it? In my module I inserted value into configuration table, I want that value to be passed into product.js file. Link to comment Share on other sites More sharing options...
bellini13 Posted October 31, 2017 Share Posted October 31, 2017 product.js is a core javascript file, or your module file? Link to comment Share on other sites More sharing options...
tijojoel Posted November 7, 2017 Author Share Posted November 7, 2017 @bellini13 Its the file inside themes/js Link to comment Share on other sites More sharing options...
bellini13 Posted November 7, 2017 Share Posted November 7, 2017 You really should create your own javascript function inside your module, as opposed to trying to customize core theme files from your custom module. Link to comment Share on other sites More sharing options...
tijojoel Posted November 8, 2017 Author Share Posted November 8, 2017 @bellini13You mean that to create js file inside module and how will I pass to product,js. I had assigned the value in smarty and called inside the js file. It is working fine now, is that correct approach? Link to comment Share on other sites More sharing options...
bellini13 Posted November 8, 2017 Share Posted November 8, 2017 You haven't even stated what changes you made to the core product.js file, or why you did that. There might be ways to accomplish it but it depends on the version of Prestashop that this change will be used on However instead of changing a core theme file product.js you should find a way to implement your javascript code inside your own module Link to comment Share on other sites More sharing options...
tijojoel Posted November 9, 2017 Author Share Posted November 9, 2017 @bellini13 I changed product.js file to make the quantity multiple by the value i had configured in the module. I am not getting any another way to do it, so only I did like this Link to comment Share on other sites More sharing options...
bellini13 Posted November 9, 2017 Share Posted November 9, 2017 Then in your module, obtain your configuration value from where ever you store it. Then add that variable to javascript using the displayHeader hook. Then product.js would have access to this variable. Link to comment Share on other sites More sharing options...
NemoPS Posted November 9, 2017 Share Posted November 9, 2017 I agree with bellini. If you really want to add it there, try using that hook, and assign with Media::addJsDef() 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