In this post I am going to explain how to get all categories of specific product in magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_categoryCollectionFactory; protected $_productRepository; public function __construct( \Magento\Catalog\Block\Product\Context $context, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, \Magento\Catalog\Model\ProductRepository $productRepository, array $data = [] ) { $this->_categoryCollectionFactory = $categoryCollectionFactory; $this->_productRepository = $productRepository;…


Recent Comments