Export categories with ID's


/ Published in: PHP
Save to your folder(s)

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!


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.