magento 获取所有分类并打印
来源:互联网 发布:林立雯淘宝店名字 编辑:程序博客网 时间:2024/05/17 01:48
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><?php$path = __DIR__;require_once $path.'/../app/Mage.php'; // 根据实际修改umask(0);Mage::app('default');Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);function nodeToArray(Varien_Data_Tree_Node $node) { $result = array(); $result['category_id'] = $node->getId(); $result['parent_id'] = $node->getParentId(); $result['name'] = $node->getName(); $result['is_active'] = $node->getIsActive(); $result['position'] = $node->getPosition(); $result['level'] = $node->getLevel(); $result['children'] = array(); foreach ($node->getChildren() as $child) { $result['children'][] = nodeToArray($child); } return $result;}function load_tree() { $tree = Mage::getResourceSingleton('catalog/category_tree') ->load(); $store = 0; $parentId = 1; $tree = Mage::getResourceSingleton('catalog/category_tree') ->load(); $root = $tree->getNodeById($parentId); if ($root && $root->getId() == 1) { $root->setName(Mage::helper('catalog')->__('Root')); } $collection = Mage::getModel('catalog/category')->getCollection() ->setStoreId($store) ->addAttributeToSelect('name') //->addAttributeToSelect('id') ->addAttributeToSelect('is_active'); $tree->addCollectionData($collection, true); return nodeToArray($root);}function print_tree($tree, $level) { $level++; foreach ($tree as $item) { if ($level > 2) { echo ' <span style="color:#CCC">|</span>'; } echo str_repeat(" ", $level) . '<span style="color:#CCC">|------</span>' . $item['name'] . '[<span style="color:#00F">' . $item['category_id'] . "</span>]<br>"; print_tree($item['children'], $level); }}$tree = load_tree();print_tree($tree['children'], 0);
注: 部分代码参考自网络
1 0
- magento 获取所有分类并打印
- magento 获取所有分类
- Magento获取所有分类列表
- Magento如何获取产品所在的所有分类?
- magento获取当前站点的所有产品分类列表
- magento 获取产品分类
- Magento 产品页获取分类
- Magento 获取当前分类名称
- magento如何获取指定分类的所有上级父类(级联至顶级)
- magento获取所有缺货产品
- 获取view的所有child view并打印类型
- magento -- 如何删除所有商品和分类
- magento 所有产品的url去掉分类,分类url不变
- Magento里显示指定分类的所有子分类
- Magento获取指定分类下的产品
- magento获取指定目录分类的子分类
- magento获取指定目录分类的子分类
- magento获取指定目录分类的子分类
- maven dependency中scope=compile 和 provided区别
- runOnUiThread
- 如何定位生产问题
- [LeetCode] 75. Sort Colors java
- 如何利用an-aw-base框架快速开发android应用application
- magento 获取所有分类并打印
- CF 387C 贪心
- Error:Execution failed for task ':app:packageDebug'...
- 利用BroadCastReceiver实现service与acvitity之间的通信(线程倒计时)
- Material Design 设计风格进阶篇 <二>
- java.lang.OutOfMemoryError: PermGen space
- 跨域与跨域访问
- 学习 DLNA
- Inception-v4, Inception-ResNet