0

I am trying to get magento price format in php file using jquery / javascript function but facing problem.

What I have tried ....

<script>
var price = 10;
var priceFormat = '<?php echo Mage::helper('core')->currency("<script>document.write(price)</script>", true, false); ?>';
console.log(priceFormat); // output 0.00
</script>

However it should be 10.00

Is this right approach to get price format? If not then how can we achieve this?

2 Answers 2

0

Using Cookie is the better solution i think.

Just write your code:

`<script> document.cookie = "myJavascriptVar = " + myJavascriptVar </script>
<?php  $myPhpVar= $_COOKIE['myJavascriptVar'];?>

var priceFormat = '<?php echo Mage::helper('core')->currency($myPhpVar, true, false); ?>';
console.log(priceFormat); `

Sorry, posted from mobile. It works .

0

What you're trying to do is pass in a string to the core helper method, where it'll be expecting a numerical value. It doesn't feel great but you could always pass in a defined number (e.g. 98.76) and then do a regex replace in JS for that number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.