php – 在Magento中获取所有类别的数组
发布时间:2020-12-13 22:41:05 所属栏目:PHP教程 来源:网络整理
导读:我希望能够通过API调用以获取所有类别的数组,其中包含URL键等详细信息.最终的目标将是这样的阵列 $massage_cats=array( array("entity_id"=78,"name"="Massage Oils and Tools","url_key"="massage-oils-and-tools","url_path"="essential-accessories/massa
我希望能够通过API调用以获取所有类别的数组,其中包含URL键等详细信息.最终的目标将是这样的阵列
$massage_cats=array( array("entity_id"=>78,"name"=>"Massage Oils and Tools","url_key"=>"massage-oils-and-tools","url_path"=>"essential-accessories/massage-oils-and-tools.html"),array("entity_id"=>79,"name"=>"Massage Oils","url_key"=>"massage-oils","url_path"=>"essential-accessories/massage-oils-and-tools/massage-oils.html") ); 所以我想说出类似的东西 $massage_cats= array(); $allcats = Mage::getModel('catalog/cats?')->loadAll(); foreach($allcats $k=>$item){ array_push($massage_cats,$item->loadDetails()); } 我知道这完全是弥补而不是真正的API,但这基本上是目标.我确实需要输出.关于代码实现需求的想法?
这将获得您的价值观.你可以从这里建立你的阵列.
$categories = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect('id') ->addAttributeToSelect('name') ->addAttributeToSelect('url_key') ->addAttributeToSelect('url') ->addAttributeToSelect('is_active'); foreach ($categories as $category) { if ($category->getIsActive()) { // Only pull Active categories $entity_id = $category->getId(); $name = $category->getName(); $url_key = $category->getUrlKey(); $url_path = $category->getUrl(); } } 编辑 我在MagentoCommerce.com的帖子中对此进行了调整.您可以使用此代码: $category = Mage::getModel('catalog/category'); $tree = $category->getTreeModel(); $tree->load(); $ids = $tree->getCollection()->getAllIds(); if ($ids){ foreach ($ids as $id){ $cat = Mage::getModel('catalog/category'); $cat->load($id); $entity_id = $cat->getId(); $name = $cat->getName(); $url_key = $cat->getUrlKey(); $url_path = $cat->getUrlPath(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |