Created
December 7, 2017 12:01
-
-
Save olragon/5aa8d13b4d5f2be9e58c51c7fb679b7b to your computer and use it in GitHub Desktop.
Export Magento 1.x categories to csv
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 | |
| require_once 'app/Mage.php'; | |
| Mage::app(); | |
| $allCategories = Mage::getModel ( 'catalog/category' ); | |
| $categoryTree = $allCategories->getTreeModel(); | |
| $categoryTree->load(); | |
| $categoryIds = $categoryTree->getCollection()->getAllIds (); | |
| if ($categoryIds) { | |
| $outputFile = "var/export/categories.csv"; | |
| $write = fopen($outputFile, 'w'); | |
| foreach ( $categoryIds as $categoryId ) { | |
| $category = $allCategories->load($categoryId); | |
| $url_key = Mage::helper('catalog/category')->getCategoryUrlPath($allCategories->getUrlPath(), true); | |
| $path = $category->getPath(); | |
| $data = array( | |
| $categoryId, | |
| $allCategories->load($categoryId)->getName(), | |
| $path, | |
| $url_key, | |
| ); | |
| fputcsv($write, $data); | |
| } | |
| } | |
| fclose($write); | |
| ?> | |
| ~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment