Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. $categoryID = $product->getCategoryCollection()->getFirstItem()->getId();
  2.  
  3. $categoryName = $product->getCategoryCollection()->getFirstItem()->getName();
  4.  
  5. $product->getCategoryCollection()
  6. ->addAttributeToSelect('name')
  7. ->getFirstItem()
  8. ->getName();
  9.  
  10. $categoryID = $product->getCategoryCollection()->getFirstItem()->getId();
  11. $category = Mage::getModel('catalog/category')->load($categoryID);
  12. $categoryName = $category->getName();
  13.  
  14. $categoryName = $product->getCategoryCollection()->addAttributeToSelect('name')->getFirstItem()->getName();
  15.  
  16. /**
  17. * @param $product_id
  18. * @return array
  19. */
  20. public function mc_getCategoryIds($product_id)
  21. {
  22. // +++ get product the category id
  23. $registry = $this->mc_C['product'];
  24. $getObj = $this->mc_get_obj($registry);
  25. /**
  26. * @var MagentoCatalogModelProduct $getObj
  27. * MagentoCatalogModelProduct
  28. */
  29. $product = $getObj->load($product_id);
  30.  
  31. /**
  32. * @var MagentoCatalogModelProduct $product
  33. * MagentoCatalogModelProduct
  34. */
  35.  
  36. return $product->getCategoryIds();
  37. }
  38.  
  39. /**
  40. * @param $product_id
  41. * @return mixed
  42. */
  43. public function mc_getCategoryName($product_id)
  44. {
  45. $cats = $this->mc_getCategoryIds($product_id);
  46. if(count($cats) ){
  47. $firstCategoryId = $cats[(count($cats)-1)];
  48. $registry = $this->mc_C['category'];
  49. $getObj = $this->mc_get_obj($registry);
  50.  
  51. /**
  52. * @var MagentoCatalogModelCategoryFactory $getObj
  53. */
  54. $_category = $getObj->create();
  55. /**
  56. * @var MagentoCatalogModelCategoryFactory $_category
  57. */
  58. $data = $_category->load($firstCategoryId);
  59. /**
  60. * @var MagentoCatalogModelCategoryFactory $data
  61. */
  62. return $data->getName();
  63. }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement