Magento – spConfig and where it can be defined and used

configurationproduct-attributestore-view

Hey everyone so in my Magento File structure, in my

app/design/frontend/base/default/template/catalog/product/view/type/options/configurable.phtml

I have:

var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
console.log("spConfig", spConfig);

And that gives me all the beautiful information I need! However why does it not show up if I call this exact same way on

app/design/frontend/default/theme424/template/catalog/product/view.phtml

The interesting thing is when I turn on Template Path Hints in Developer->Configuation->Developer panel they are both on the same page and configurable.phtml is inside the wrapper known as the view.phtml

Best Answer

You might want to look into Mage_Catalog_Block_Product_View_Type_Configurable::getJsonConfig(). That's where the json gets generated.

Every product view gets rendered in catalog/product/view.phtml. Product type specific things like a configurable option dropdown, get rendered in catalog/product/type/options/configurable.phtml.

Why you can't call $this->getJsonConfig() in configurable.phtml is because:

  • Template catalog/product/view.phtml has the block type Mage_Catalog_Block_Product_View.
  • Template catalog/product/type/options/configurable.phtml has the block type Mage_Catalog_Block_Product_View_Type_Configurable.
  • The method getJsonConfig() is defined in Mage_Catalog_Block_Product_View_Type_Configurable
Related Topic