Skip to content

Suboptimal method Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProducts #1218

Open
@midlan

Description

@midlan

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:

  1. depracate the method
  2. refactor all usages of it to use Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProductCollection with only needed attributes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions