Posted By

TheJasonParker on 01/12/11


Tagged

magento


Versions (?)

Export categories with ID's


 / Published in: PHP
 

URL: http://www.sonassi.com/knowledge-base/quick-script-to-export-categories-with-ids/

Simply save the above code in a PHP file in the base Magento directory of your store, and visit the URL in your web browser, simples!

  1. <?php
  2.  
  3. define('MAGENTO', realpath(dirname(__FILE__)));
  4. require_once MAGENTO . '/app/Mage.php';
  5. Mage::app();
  6.  
  7. $category = Mage::getModel ( 'catalog/category' );
  8. $tree = $category->getTreeModel ();
  9. $tree->load ();
  10.  
  11. $ids = $tree->getCollection ()->getAllIds ();
  12.  
  13. if ($ids) {
  14. $file = "var/import/catwithid.csv";
  15. file_put_contents($file,"catId, catName\n");
  16. foreach ( $ids as $id ) {
  17. $string = $id . ', ' .$category->load($id)->getName() . "\n";
  18. file_put_contents($file,$string,FILE_APPEND);
  19. }
  20. }
  21. ?>

Report this snippet  

You need to login to post a comment.