/** * Get categories assigned to product * * @return \Magento\Catalog\Model\Resource\Category\Collection */ protected function getCategories() { if (!$this->categories) { $this->categories = $this->product->getCategoryCollection(); $this->categories->addAttributeToSelect('url_key'); $this->categories->addAttributeToSelect('url_path'); } return $this->categories; }
/** * @return void */ protected function prepareCollection() { $storeId = $this->storeManager->getStore()->getId(); $this->categoryCollection->addAttributeToSelect('name')->addAttributeToSelect('is_active')->setProductStoreId($storeId)->setLoadProductCount(true)->setStoreId($storeId); }