Open midlan opened 4 years ago
The method Suboptimal method Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProducts is not optimal at all.
Suboptimal method Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProducts
*
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); }
I would:
Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProductCollection
M2 Optimisation of this method:
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php#L203-L227
Summary (*)
The method
Suboptimal method Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProducts
is not optimal at all.*
- asterisk) of associated productsExamples (*)
Proposed solution
I would:
Mage_Catalog_Model_Product_Type_Grouped::getAssociatedProductCollection
with only needed attributes.