<?php
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/../web/app/Mage.php';
Mage::app();
$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$categories = array();
$result = array();
if ($ids) {
foreach ($ids as $id) {
$category->load($id);
$categories[$id]['name'] = $category->getName();
$categories[$id]['path'] = $category->getPath();
}
foreach ($ids as $id) {
$path = explode('/', $categories[$id]['path']);
$string = '';
foreach ($path as $pathId) {
$string.= $categories[$pathId]['name'] . '/';
$cnt++;
}
$string = rtrim($string, '/');
$string = str_replace('Root Catalog/Default Category/', '', $string);
$result[] = $string;
}
}
asort($result);
foreach($result as $category) {
echo $category . PHP_EOL;
}
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/../web/app/Mage.php';
Mage::app();
$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$categories = array();
$result = array();
if ($ids) {
foreach ($ids as $id) {
$category->load($id);
$categories[$id]['name'] = $category->getName();
$categories[$id]['path'] = $category->getPath();
}
foreach ($ids as $id) {
$path = explode('/', $categories[$id]['path']);
$string = '';
foreach ($path as $pathId) {
$string.= $categories[$pathId]['name'] . '/';
$cnt++;
}
$string = rtrim($string, '/');
$string = str_replace('Root Catalog/Default Category/', '', $string);
$result[] = $string;
}
}
asort($result);
foreach($result as $category) {
echo $category . PHP_EOL;
}
Comments
Post a Comment