Posted By

TheJasonParker on 01/12/11


Tagged

magento


Versions (?)

Mass enable categories


 / Published in: PHP
 

URL: http://www.sonassi.com/knowledge-base/magento-knowledge-base/quick-script-to-mass-enable-categories-in-magento/

Create a CSV with a maximum of 1 column, with just the Magento category ID.

  1. <?php
  2.  
  3. define('MAGENTO', realpath(dirname(__FILE__)));
  4. require_once MAGENTO . '/app/Mage.php';
  5. umask(0);
  6. Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
  7.  
  8. $file = fopen(MAGENTO . "/var/import/categoriesToEnable.csv", 'r');
  9.  
  10. while (($line = fgetcsv($file)) !== FALSE) {
  11. $cats = explode(",",$line[1]);
  12. foreach ($cats as $cat) {
  13. $newcats[$cat] = true;
  14. }
  15. }
  16.  
  17. // Activate the categories it is in
  18. foreach ($newcats as $cat=>$value) {
  19.  
  20. if ($value && !empty($cat)) {
  21.  
  22. try {
  23.  
  24. $_category = Mage::getModel('catalog/category')->load($cat);
  25.  
  26. if ($_category->getIsActive() === "0" || !$_category->getIsActive()) {
  27. $_category->setIsActive(1);
  28. $_category->save();
  29. echo "<br />Enabled ".$_category->getName();
  30. unset($_category);
  31. }
  32.  
  33. } catch(Exception $e) {
  34. echo " Caught Cat Insert exception: ", $e->getMessage();
  35. }
  36. }
  37.  
  38. }
  39.  
  40. ?>

Report this snippet  

You need to login to post a comment.