Ela*_*gan 6 magento entity-attribute-value magento-1.4
在magento中如何从其产品ID获取每个产品的类别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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里$items[$i]->getProduct()->getId()返回产品ID.我想要它的类别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;
}
Run Code Online (Sandbox Code Playgroud)