diff --git a/src/app/code/community/IntegerNet/Solr/Model/Bridge/ProductRepository.php b/src/app/code/community/IntegerNet/Solr/Model/Bridge/ProductRepository.php index 1d9e163..76f617a 100644 --- a/src/app/code/community/IntegerNet/Solr/Model/Bridge/ProductRepository.php +++ b/src/app/code/community/IntegerNet/Solr/Model/Bridge/ProductRepository.php @@ -52,6 +52,13 @@ public function getProductAssociations($productIds) foreach ($groupedResourceTypeModel->getChildrenIdsForMultipleParents($productIds) as $parentId => $childrenIds) { $associations[$parentId] = $childrenIds; } + + /** @var $bundleResourceTypeModel IntegerNet_Solr_Model_Resource_Catalog_Product_Type_Bundle */ + $bundleResourceTypeModel = Mage::getResourceModel('integernet_solr/catalog_product_type_bundle'); + // Don't use array_merge here due to performance reasons + foreach ($bundleResourceTypeModel->getChildrenIdsForMultipleParents($productIds) as $parentId => $childrenIds) { + $associations[$parentId] = $childrenIds; + } return array_combine(array_keys($associations), array_map( function($parentId, $childrenIds) { return new \IntegerNet\Solr\Indexer\Data\ProductAssociation($parentId, $childrenIds); diff --git a/src/app/code/community/IntegerNet/Solr/Model/Resource/Catalog/Product/Type/Bundle.php b/src/app/code/community/IntegerNet/Solr/Model/Resource/Catalog/Product/Type/Bundle.php new file mode 100644 index 0000000..e621972 --- /dev/null +++ b/src/app/code/community/IntegerNet/Solr/Model/Resource/Catalog/Product/Type/Bundle.php @@ -0,0 +1,50 @@ + + */ +class IntegerNet_Solr_Model_Resource_Catalog_Product_Type_Bundle extends Mage_Bundle_Model_Resource_Selection +{ + /** + * Retrieve Required children ids + * Return grouped array, ex array( + * group => array(ids) + * ) + * + * @param null|int[] $parentIds + * @return int[][] + */ + public function getChildrenIdsForMultipleParents($parentIds) + { + $childrenIds = array(); + $adapter = $this->_getReadAdapter(); + $select = $adapter->select() + ->from( + array('tbl_selection' => $this->getMainTable()), + array('product_id', 'parent_product_id', 'option_id') + ) + ->join( + array('e' => $this->getTable('catalog/product')), + 'e.entity_id = tbl_selection.product_id AND e.required_options=0', + array() + ) + ->join( + array('tbl_option' => $this->getTable('bundle/option')), + 'tbl_option.option_id = tbl_selection.option_id', + array('required') + ); + if (!is_null($parentIds)) { + $select->where('tbl_selection.parent_product_id IN (?)', $parentIds); + } + + foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { + $childrenIds[$row['parent_product_id']][$row['product_id']] = $row['product_id']; + } + + return $childrenIds; + } +} \ No newline at end of file