Magento 2 How can we get product url with product collection?
-
14-04-2021 - |
Pregunta
I am able to load product collection by using
[$objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection')]
in my phtml file.But in that collection product url is not there how can we get Product url also with that collection.
Solución
$productCollection = $productObj;
Gives from product collection url using loop the collection,
foreach($productCollection as $_product){
echo $_product->getProductUrl();
}
Otros consejos
You can also try this code.
foreach($productCollection as $product){
$productUrl=$objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getBaseUrl().$product->getUrlKey().'.html';
echo $productUrl;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange