1

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) {
        $collection->setStoreId($storeId);
        foreach ($collection as $itemId => $item) {
            $data[$itemId][$storeId] = $item;
        }
        $collection->clear();
    }

    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
1

Run this file on your magento root Directory

<?php 
ob_start();
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
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('*')
            ->load();
$collection->addUrlRewrite();
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.