Created
October 3, 2018 04:22
-
-
Save Nerjuz/0e24dbe0b98bb4e69eaf0061d14fda0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory */ | |
protected $_collectionFactory; | |
public function __construct( | |
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory | |
) { | |
$this->_collectionFactory = $collectionFactory; | |
} | |
public function yourMethod() | |
{ | |
// Use factory to create a new product collection | |
$productCollection = $this->_collectionFactory->create(); | |
/** Apply filters here */ | |
$productCollection->addAttributeToSelect('*'); | |
// Don't have to do this | |
// $productCollection->load(); | |
foreach ($productCollection as $product){ | |
echo 'Name = '.$product->getName().'<br>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment