Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save krillo/6014831728786d21bdca5963bf316e7e to your computer and use it in GitHub Desktop.
Save krillo/6014831728786d21bdca5963bf316e7e to your computer and use it in GitHub Desktop.
Magento1: All active categories, save to csv-file
<?php
/**
* allActiveCategories.php
*
* Gets all active catgories and writes them to a file "categories.csv"
* Put this in your magento 1 webroot and run from your browser
* krillo
*/
require __DIR__ . '/app/Mage.php';
Mage::app(Mage_Core_Model_App::ADMIN_STORE_ID)->setUseSessionInUrl(false);
$cat = array();
$cats = array();
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter();
foreach ($categories as $category){
echo $category->getId() . ' ' . $category->getName() . '<br>';
$cat['id'] = $category->getId();
$cat['name'] = $category->getName();
$cat['url_key'] = $category->getUrlKey();
$cat['url_path'] = $category->getUrlPath();
$cats[$category->getId()] = $cat;
}
//print_r($cats);
$file = fopen("categories.csv","w");
foreach ($cats as $row){
fputcsv($file,$row);
}
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment