/** * Get downloadable product links * * @param \Magento\Catalog\Model\Product $product * @return \Magento\Downloadable\Model\Link[] */ public function getLinks($product) { if ($product->getDownloadableLinks() === null) { /** @var \Magento\Downloadable\Model\Resource\Link\Collection $linkCollection */ $linkCollection = $this->_linksFactory->create()->addProductToFilter($product->getId())->addTitleToResult($product->getStoreId())->addPriceToResult($product->getStore()->getWebsiteId()); $this->extensionAttributesJoinProcessor->process($linkCollection); $linksCollectionById = []; foreach ($linkCollection as $link) { /* @var \Magento\Downloadable\Model\Link $link */ $link->setProduct($product); $linksCollectionById[$link->getId()] = $link; } $product->setDownloadableLinks($linksCollectionById); } return $product->getDownloadableLinks(); }
/** * Get downloadable product links * * @param \Magento\Catalog\Model\Product $product * @return array */ public function getLinks($product) { if (is_null($product->getDownloadableLinks())) { $_linkCollection = $this->_linksFactory->create()->addProductToFilter($product->getId())->addTitleToResult($product->getStoreId())->addPriceToResult($product->getStore()->getWebsiteId()); $linksCollectionById = array(); foreach ($_linkCollection as $link) { /* @var \Magento\Downloadable\Model\Link $link */ $link->setProduct($product); $linksCollectionById[$link->getId()] = $link; } $product->setDownloadableLinks($linksCollectionById); } return $product->getDownloadableLinks(); }