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';
foreach ($ids as $id) {
$array = array();
$products = $category->load($id)
->getProductCollection()
->addAttributeToSelect('*')
->addStoreFilter(Mage::app()->getStore()->getId());
foreach ($products as $_product) {
$array[] = array_merge($_product->getData(), array('category_ids' => $_product->getCategoryIds()));
}
$jsonData = Mage::helper('core')->jsonEncode($array);
file_put_contents($jsonFilePath.'/c_' . $id . '_node.json', $jsonData);
}
}
I have this function in an observer which creates a JSON file of all products in every category. I am trying to get the labels for the product attributes as well as the product price with appropriate currency. However, instead of getting the label I am getting the option ID.
How can I get the label for the attribute rather than the option ID, and the products price with the appropriate currency?
Best Answer
You could try this as well - IMO it's probably a lot more performant because of the fact that it's reducing the amount of queries being issued when generating your list. Let me know if you have any issues as I wasn't able to validate it.