Magento 1-从产品ID获取类别ID

Magento 1-从产品ID获取类别ID,magento,entity-attribute-value,magento-1.4,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

在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;
              }
        }
    }
$items=$request->getAllItems();
$c=计数(项目);
对于($i=0;$i<$c;$i++){
if($items[$i]->getProduct()图片目录产品的实例){
如果($items[$i]->getProduct()->getId()){
$this->_dhlAllowed=false;
}
}
}
这里
$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;
}

通过这种方式,可以获取当前产品的类别id。

假设您希望从当前产品id中获取所有类别id,则可以从

Mage::registry('current_product')->getCategoryIds();

它可以帮助您

$items[$i]->getProduct()->getCategoryId();这将返回一台服务器中的类别ID,但不返回另一台服务器中的类别ID。有什么想法吗?你有没有尝试在服务器上重新索引平面类别表?这类奇怪的东西通常与过期(或损坏)的索引关联。
count($categoryIds)
应该是
>=1
Mage::registry('current_product')->getCategoryIds();