Php Magento:按订单获取产品类别
我当前正在检索当前产品在product view.phtml页面上链接到的类别列表,其中包含以下内容:Php Magento:按订单获取产品类别,php,magento,Php,Magento,我当前正在检索当前产品在product view.phtml页面上链接到的类别列表,其中包含以下内容: $cats = $_product->getCategoryIds(); 然后在页面上循环如下: foreach($cats as $category_id) { $_cat = Mage::getModel('catalog/category')->load($category_id); // do stuff } 如何检索按类别名称排序的列表 或者,我尝试了以下方
$cats = $_product->getCategoryIds();
然后在页面上循环如下:
foreach($cats as $category_id)
{
$_cat = Mage::getModel('catalog/category')->load($category_id);
// do stuff
}
如何检索按类别名称排序的列表
或者,我尝试了以下方法,但是当我在foreach语句中使用$catCollection时,会出现404错误
$catIds = $_product->getCategoryIds();
$catCollection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', $catIds)
->addAttributeToSort('name', 'ASC')
->addIsActiveFilter();
谢谢。目前无法测试此功能,但此功能适用于您: 这样做,而不是你的foreach让他们的秩序
$catIds = $_product->getCategoryIds();
$catCollection = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('in' => $catIds))
->addAttributeToSort('name', 'ASC');
foreach($catCollection as $cat){
echo $cat->getName(), "<br>";
}
$catIds=$\u product->getCategoryIds();
$catCollection=Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect(“*”)
->addAttributeToFilter('entity_id',array('in'=>$CATID))
->addAttributeToSort('name','ASC');
foreach($catCollection作为$cat){
echo$cat->getName(),“
”;
}
目前无法对此进行测试,但这应该适用于您:
这样做,而不是你的foreach让他们的秩序
$catIds = $_product->getCategoryIds();
$catCollection = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('in' => $catIds))
->addAttributeToSort('name', 'ASC');
foreach($catCollection as $cat){
echo $cat->getName(), "<br>";
}
$catIds=$\u product->getCategoryIds();
$catCollection=Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect(“*”)
->addAttributeToFilter('entity_id',array('in'=>$CATID))
->addAttributeToSort('name','ASC');
foreach($catCollection作为$cat){
echo$cat->getName(),“
”;
}
这目前没有影响。这目前没有影响。