Hello @Mag.Net ,
1. To create an observer, you must place your class file under your <module-root>/Observer directory.
2 .Your observer class should implement Magento\Framework\Event\ObserverInterface and define its execute function.
Hi @Mag.Net
Here is solution, for Magento 1 and Magento 2. Please check.
Magento 1:
$products = Mage::getModel('catalog/product')->getCollection(); foreach($products as $prod) { $product = Mage::getModel('catalog/product')->load($prod->getId()); }
Magento 2:
You can directly get product collection by using Object Manager observer file. Although it's not recommended to use Object Manager directly in Magento 2.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection'); $collection = $productCollection->addAttributeToSelect('*')->load(); foreach ($collection as $product){ echo 'Name = '.$product->getName().'<br>'; }
Let me know if you are looking for something similar.
Thanks
--
If my answer is useful, please Accept as Solution & give Kudos