Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $categoryID = $product->getCategoryCollection()->getFirstItem()->getId();
- $categoryName = $product->getCategoryCollection()->getFirstItem()->getName();
- $product->getCategoryCollection()
- ->addAttributeToSelect('name')
- ->getFirstItem()
- ->getName();
- $categoryID = $product->getCategoryCollection()->getFirstItem()->getId();
- $category = Mage::getModel('catalog/category')->load($categoryID);
- $categoryName = $category->getName();
- $categoryName = $product->getCategoryCollection()->addAttributeToSelect('name')->getFirstItem()->getName();
- /**
- * @param $product_id
- * @return array
- */
- public function mc_getCategoryIds($product_id)
- {
- // +++ get product the category id
- $registry = $this->mc_C['product'];
- $getObj = $this->mc_get_obj($registry);
- /**
- * @var MagentoCatalogModelProduct $getObj
- * MagentoCatalogModelProduct
- */
- $product = $getObj->load($product_id);
- /**
- * @var MagentoCatalogModelProduct $product
- * MagentoCatalogModelProduct
- */
- return $product->getCategoryIds();
- }
- /**
- * @param $product_id
- * @return mixed
- */
- public function mc_getCategoryName($product_id)
- {
- $cats = $this->mc_getCategoryIds($product_id);
- if(count($cats) ){
- $firstCategoryId = $cats[(count($cats)-1)];
- $registry = $this->mc_C['category'];
- $getObj = $this->mc_get_obj($registry);
- /**
- * @var MagentoCatalogModelCategoryFactory $getObj
- */
- $_category = $getObj->create();
- /**
- * @var MagentoCatalogModelCategoryFactory $_category
- */
- $data = $_category->load($firstCategoryId);
- /**
- * @var MagentoCatalogModelCategoryFactory $data
- */
- return $data->getName();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement