Created
April 10, 2017 14:19
-
-
Save krillo/6014831728786d21bdca5963bf316e7e to your computer and use it in GitHub Desktop.
Magento1: All active categories, save to csv-file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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