I've inherited a Magento project which an old developer was in charge of. Having very limited Magento experience, I'd like to understand how product collections and the catalog/product
model is working.
Specifically I'm wondering why the collection and product objects are so huge?
I have code like this:
<?php $_productCollection = $this->getLoadedProductCollection(); ?>
<?php foreach ($_productCollection as $_product): ?>
<?php $_product = Mage::getModel( 'catalog/product' )->load( $_product->getId() ); ?>
<?php print $this->getLayout()->createBlock('mymodule_name/category_products_item')->setProduct($_product)->toHtml() ?>
<?php endforeach ?>
When I do print_r($_productCollection)
or print_r($_product)
I get massive amounts of data, when all I really want is a few product attributes (ID, name, price, image URL, etc.).
I'm used to a custom relational database platform where, if I needed to use products, I'd just do something ultra-simple like SELECT id,name,price FROM products;
! I'm not at all sure how I'd achieve this in Magento. Do I create a custom model or something?
So can anyone please tell me:
1) Why are the above objects so huge?
2) If I only need a few product attributes (as above) then is there a way to limit the objects to only those attributes to reduce their size?
3) Is there a performance or memory hit from using objects this way?
Many thanks!