本文介绍了Magento 1 - 从产品 ID 中获取类别 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 magento 中如何从每个产品的产品 ID 中获取每个产品的类别 ID.
In magento how to get the category id of each product from its product ID.
$items = $request->getAllItems();
$c = count($items);
for ($i = 0; $i < $c; $i++) {
if ($items[$i]->getProduct() instanceof Mage_Catalog_Model_Product) {
if ($items[$i]->getProduct()->getId()) {
$this->_dhlAllowed = false;
}
}
}
此处 $items[$i]->getProduct()->getId()
返回产品 ID.我想要它的类别 ID.
Here $items[$i]->getProduct()->getId()
returns product ID. I want its category ID.
推荐答案
public function getProductCategory() {
/* @var $product Mage_Catalog_Model_Product */
$product = Mage::registry('current_product');
if ($product->getId()) {
$categoryIds = $product->getCategoryIds();
if (is_array($categoryIds) and count($categoryIds) >= 1) {
return Mage::getModel('catalog/category')->load($categoryIds[0]);
};
}
return false;
}
这篇关于Magento 1 - 从产品 ID 中获取类别 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!