In magento how to get the category id of each product from its product ID.
$items = $request->getAllItems();
$c = count($items);
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;
}
suppose if you want all category ids from current product id you can get from
Mage::registry('current_product')->getCategoryIds();
it may help you
Mage::registry('current_product')->getCategoryId();
this way, category id of a current product can be get.