Forked from tegansnyder/CategoryTreePathExportMagento.php
Created
October 22, 2015 13:55
-
-
Save korbax/d1b44b18973057e614d8 to your computer and use it in GitHub Desktop.
Export Category Tree and Paths for Magento
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 | |
define('MAGENTO', realpath(dirname(__FILE__))); | |
require_once MAGENTO . '/app/Mage.php'; | |
Mage::app(); | |
$category = Mage::getModel ('catalog/category'); | |
$tree = $category->getTreeModel(); | |
$tree->load(); | |
$ids = $tree->getCollection()->getAllIds(); | |
$categories = array(); | |
$x = 0; | |
if ($ids) { | |
$file = "var/import/catwithid.csv"; | |
file_put_contents($file,'"id","name","path","path_ids","url"' . PHP_EOL); | |
foreach ( $ids as $id ) { | |
$url_key = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), true); | |
$path = explode('/', $categories[$id]['path']); | |
$fpath = ''; | |
foreach ($path as $pathId) { | |
$fpath .= $categories[$pathId]['name'] . '/'; | |
} | |
$path_ids = implode(',', $path); | |
$string = '"' . $id . '","' . $category->load($id)->getName() . '","' . $fpath . '","' . $path_ids . '"' . $url_key . '"' . PHP_EOL; | |
file_put_contents($file,$string,FILE_APPEND); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment