In this chapter, we will explore the possibilities of the Magento collections. A Magento collection is a set of entities where you can add filters to customize your result.
In this chapter, we will explore everything that is possible with Magento collections.
Go to the indexController
of the helloworld
module and create a collectionAction
method in it. In this action, we will perform some tests to compare the results.
The next examples show what are the possibilities while working with Magento collections:
Add the following code in the
collectionAction
method and navigate to the page. This code will return 10 products.public function collectionAction () { $productCollection = Mage::getModel('catalog/product') ->getCollection() ->setPageSize(10,1); foreach ($productCollection as $product) { Zend_Debug::dump($product->debug()); } }