I want to get products URL's using product collection,I have tried many links from searching browser,please help me with appropriate file path this is my module catalog import export code to get URL's in export.

protected function loadCollection(): array
    $data = [];

    $collection = $this->_getEntityCollection();
    foreach (array_keys($this->_storeIdToCode) as $storeId) {
        foreach ($collection as $itemId => $item) {
            $data[$itemId][$storeId] = $item;

    return $data;
  • $product->getProductUrl() if you have product object – Shoaib Munir Jun 25 '19 at 12:08
  • @shoaib from where i get product object can u specify the file path..? – Shan Haider Jun 25 '19 at 12:10
  • where do you want product url? on which file you are working on? – Shoaib Munir Jun 25 '19 at 12:27
  • i am working on catalog import export module under product file to get products Url's when i export the products url's should come in export sheet – Shan Haider Jun 25 '19 at 12:31
  • in that file, is there any foreach loop on product collection? if yes, then please share your code in question – Shoaib Munir Jun 25 '19 at 12:32

Run this file on your magento root Directory

use Magento\Framework\App\Bootstrap;
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
ini_set('memory_limit', '1024M');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
/** Apply filters here */
$collection = $productCollection->addAttributeToSelect('*')
foreach ($collection as $product){
     echo $product->getProductUrl().'<br>';
|improve this answer|||||

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.