Issue
How can I get a category collection in the product details page? I've tried using the below code, but it's not getting the collection.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')
->registry('current_category');
$categoryProducts = $category->getCategoryProducts($categoryId);
Solution
on the product detail page you can just call getCategoryCollection function on product's Object to get Category Collection as following :
$_product = $block->getProduct();
$categoryCollection = $_product->getCategoryCollection();
Answered By - Emizen Tech Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.