Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. public function productDataToJson(Varien_Event_Observer $observer)
  2. {
  3. $category = Mage::getModel('catalog/category');
  4. $tree = $category->getTreeModel();
  5. $tree->load();
  6. $ids = $tree->getCollection()->getAllIds();
  7. $jsonFilePath = Mage::getBaseDir().'/jsondata';
  8. $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
  9. $productMediaConfig = Mage::getModel('catalog/product_media_config');
  10. foreach ($ids as $id) {
  11. $productsArr = array();
  12. $products = $category->load($id)
  13. ->getProductCollection()
  14. ->addAttributeToSelect('*')
  15. ->addStoreFilter(Mage::app()->getStore()->getId());
  16. $i = 0;
  17. foreach ($products as $_product) {
  18. $baseImageUrl = $productMediaConfig->getMediaUrl($_product->getImage());
  19. $smallImageUrl = $productMediaConfig->getMediaUrl($_product->getSmallImage());
  20. $thumbnailUrl = $productMediaConfig->getMediaUrl($_product->getThumbnail());
  21. $heroImageUrl = $productMediaConfig->getMediaUrl($_product->getProductHero());
  22. $productUrlPath = $baseUrl.$_product->getData('url_key');
  23. $categoryName = $category->getName();
  24. $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')));
  25. $productsArr[$i]['image'] = $baseImageUrl;
  26. $productsArr[$i]['small_image'] = $smallImageUrl;
  27. $productsArr[$i]['thumbnail'] = $thumbnailUrl;
  28. $productsArr[$i]['product_hero'] = $heroImageUrl;
  29. $productsArr[$i]['url_path'] = $productUrlPath;
  30. $productsArr[$i]['category_names'] = $categoryName;
  31. $i++;
  32. //echo '<pre>';print_r($productsArr);exit;
  33. }
  34. $jsonData = Mage::helper('core')->jsonEncode($productsArr);
  35. file_put_contents($jsonFilePath.'/c_' . $id . '_node.json', $jsonData);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement