public function productDataToJson(Varien_Event_Observer $observer)
{
$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$jsonFilePath = Mage::getBaseDir().'/jsondata';
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$productMediaConfig = Mage::getModel('catalog/product_media_config');
foreach ($ids as $id) {
$productsArr = array();
$products = $category->load($id)
->getProductCollection()
->addAttributeToSelect('*')
->addStoreFilter(Mage::app()->getStore()->getId());
$i = 0;
foreach ($products as $_product) {
$baseImageUrl = $productMediaConfig->getMediaUrl($_product->getImage());
$smallImageUrl = $productMediaConfig->getMediaUrl($_product->getSmallImage());
$thumbnailUrl = $productMediaConfig->getMediaUrl($_product->getThumbnail());
$heroImageUrl = $productMediaConfig->getMediaUrl($_product->getProductHero());
$productUrlPath = $baseUrl.$_product->getData('url_key');
$categoryName = $category->getName();
$productsArr[$i] = array_merge($_product->getData(), array('category_ids' => $_product->getCategoryIds(),'price'=>Mage::helper('core')->currency($_product->getFinalPrice(), true, false),'size'=>$_product->getAttributeText('size'),'color'=>$_product->getAttributeText('color2'),'brand'=>$_product->getAttributeText('brand')));
$productsArr[$i]['image'] = $baseImageUrl;
$productsArr[$i]['small_image'] = $smallImageUrl;
$productsArr[$i]['thumbnail'] = $thumbnailUrl;
$productsArr[$i]['product_hero'] = $heroImageUrl;
$productsArr[$i]['url_path'] = $productUrlPath;
$productsArr[$i]['category_names'] = $categoryName;
$i++;
//echo '<pre>';print_r($productsArr);exit;
}
$jsonData = Mage::helper('core')->jsonEncode($productsArr);
file_put_contents($jsonFilePath.'/c_' . $id . '_node.json', $jsonData);
}
}
Also need lables of all attributes, like if I create any attribute, I can get it in my json file. how can I get this in my function?