I am able to load product collection by using


in my phtml file.But in that collection product url is not there how can we get Product url also with that collection.


$productCollection = $productObj;

Gives from product collection url using loop the collection,

foreach($productCollection as $_product){ 
   echo $_product->getProductUrl();
  • Hi @Rakesh Actually I am loading collection in product detail page using this [$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection') ->addAttributeToFilter('type_id','bundle') ->addAttributeToFilter('product_identifier',$productIdentifier);] If I print [$productCollection->getData()] it is not giving products urls. Dec 20 '16 at 11:38
  • Here my need is I want to give other product links in this current product detail page. Dec 20 '16 at 11:40
  • have you try with, $_product->getProductUrl()? Dec 20 '16 at 11:42
  • yes I tried using [$productCollection->getProductUrl()] but it is not giving any thing. Dec 20 '16 at 11:44
  • plz share your full code Dec 20 '16 at 11:47

If you're using an objectmanager then try this code.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
foreach($productCollection as $product){
echo $productUrl.'<br/>';

you can also make a product url using the url key.

foreach($productCollection as $product){
    echo $productUrl; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.