Guest User

Untitled

a guest
Jul 19th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. $cat_id = 3;
  2. $category = Mage::getModel('catalog/category')->load($cat_id);
  3. $collection = $category->getProductCollection()->addAttributeToSort('position');
  4. Mage::getModel('catalog/layer')->prepareProductCollection($collection);
  5.  
  6. $collection = $category->getProductCollection()->addAttributeToSort('position')
  7. ->addAttributeToFilter('type_id', array('eq' => 'Milople Personalized Product'));
  8.  
  9. $category = new Mage_Catalog_Model_Category();
  10. $category->load(3); //this is category id
  11. $collection =
  12. $category->getProductCollection()->addAttributeToFilter('type_id',
  13. array('eq' => 'Milople Personalized Product'));
  14.  
  15. <?php
  16. set_time_limit(0);
  17. ini_set("memory_limit",-1);
  18. ini_set('max_execution_time','1800000000');
  19.  
  20. require_once '../app/Mage.php';
  21. Mage::app();
  22.  
  23. $category = Mage::getModel('catalog/category');
  24. $tree = $category->getTreeModel();
  25. $tree->load();
  26.  
  27. $ids = $tree->getCollection()->getAllIds();
  28. $fp = fopen('category-product-export.csv', 'w');
  29. $field = array('Product SKU','Category Name');
  30. fputcsv($fp, $field);
  31.  
  32. $_productCollection = Mage::getModel('catalog/product')
  33. ->getCollection()
  34. ->addAttributeToSelect('*')
  35. ->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
  36. ->load();
  37.  
  38. foreach ($_productCollection as $_product){
  39. $cats = $_product->getCategoryIds();
  40. $cnt = 0;
  41. $catName = '';
  42. foreach($cats as $id) {
  43. $category->load($id);
  44. $root = 'Root Catalog';
  45. $isRoot = strtolower($root);
  46. $categoryName = strtolower($category->getName());
  47. if($categoryName == $isRoot){
  48. continue;
  49. }
  50. $categories[$id]['name'] = $category->getName();
  51. $categories[$id]['path'] = $category->getPath();
  52.  
  53. $path = explode('/', $categories[$id]['path']);
  54. $len = count($path);
  55. $string = '';
  56. if($id > 2){
  57. foreach ($path as $k=>$pathId)
  58. {
  59. $separator = '';
  60. if($pathId > 2){
  61. $category->load($pathId);
  62. if($k != $len-1){ $separator = ' || ';}
  63. $string.= $category->getName() . $separator;
  64. }
  65.  
  66. }
  67. if($cnt > 0) {
  68. $catName.= ','.$string;
  69. } else {
  70. $catName = $string;
  71. }
  72.  
  73. $cnt++;
  74. }
  75. }
  76. //echo $catName;
  77. $field = array($_product->getSku(),$catName);
  78. fputcsv($fp, $field);
  79.  
  80. }
  81.  
  82. ?>
  83. <a href="category-product-export.csv">Download</a>
Add Comment
Please, Sign In to add comment