Magento 1 - get category ID from product ID

前端 未结 3 1647
孤街浪徒
孤街浪徒 2020-12-18 04:51

In magento how to get the category id of each product from its product ID.

   $items    = $request->getAllItems();
    $c           = count($items); 

            


        
相关标签:
3条回答
  • 2020-12-18 05:48
    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;
    }
    
    0 讨论(0)
  • 2020-12-18 05:52

    suppose if you want all category ids from current product id you can get from

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

    it may help you

    0 讨论(0)
  • 2020-12-18 05:54
    Mage::registry('current_product')->getCategoryId();
    

    this way, category id of a current product can be get.

    0 讨论(0)
提交回复
热议问题