Open
Description
Summary (*)
The method Suboptimal method Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProducts
is not optimal at all.
- it selects all attributes (with
*
- asterisk) of associated products - loops the collection of the associated products and returns array, what actually loads the collection and breaks lazy-loading
Examples (*)
public function getAssociatedProducts($product = null)
{
if (!$this->getProduct($product)->hasData($this->_keyAssociatedProducts)) {
$associatedProducts = array();
if (!Mage::app()->getStore()->isAdmin()) {
$this->setSaleableStatus($product);
}
$collection = $this->getAssociatedProductCollection($product)
->addAttributeToSelect('*') //problem #1
->addFilterByRequiredOptions()
->setPositionOrder()
->addStoreFilter($this->getStoreFilter($product))
->addAttributeToFilter('status', array('in' => $this->getStatusFilters($product)));
foreach ($collection as $item) { //problem #2
$associatedProducts[] = $item;
}
$this->getProduct($product)->setData($this->_keyAssociatedProducts, $associatedProducts);
}
return $this->getProduct($product)->getData($this->_keyAssociatedProducts);
}
Proposed solution
I would:
- depracate the method
- refactor all usages of it to use
Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProductCollection
with only needed attributes.