Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement