What is the use of getJsonConfig()
method?
What does this method do? What is the meaning of the below line in view.phtml
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
The getJsonConfig
of the product block returns the js configuration for product price changing.
It returns different values depending on product type (simple, configurable, bundle) or if it has options or not, and depending on the tax settings.
The json it returns is then picked up buy the OptionsPrice
js "class" in varien/js/product.js
and changes the price in the browser depending on your selections.
For example, when you select an option for a configurable product, the price is changed accordingly. The same thing happens when you change a bundle product options.
by $this->getJsonConfig()
$this
refer to block which you have define in layout
If you see in app/design/frontend/rwd/default/layout/catalog.xml file
between <catalog_product_view />
tag you will find below code
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
So in view.phtml $this refer block
app/code/core/Mage/Catalog/Block/Product/View.php
you can find public function getJsonConfig()
there
this will create a product price json as you see in function getJsonConfig()
will create json including tire price and all
$this->getJsonConfig() The method is part of
class Mage_Catalog_Block_Product_View
/**
* Get JSON encoded configuration array which can be used for JS dynamic
* price calculation depending on product options
*
* @return string
*/
public function getJsonConfig()
{
}
*/