Skip to content

Commit 2a1d477

Browse files
author
Fabian Schmengler /
authored
Merge pull request #10 from integer-net/bundle
Indexing of Bundle children products
2 parents 232ba1a + 1069154 commit 2a1d477

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/app/code/community/IntegerNet/Solr/Model/Bridge/ProductRepository.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public function getProductAssociations($productIds)
5252
foreach ($groupedResourceTypeModel->getChildrenIdsForMultipleParents($productIds) as $parentId => $childrenIds) {
5353
$associations[$parentId] = $childrenIds;
5454
}
55+
56+
/** @var $bundleResourceTypeModel IntegerNet_Solr_Model_Resource_Catalog_Product_Type_Bundle */
57+
$bundleResourceTypeModel = Mage::getResourceModel('integernet_solr/catalog_product_type_bundle');
58+
// Don't use array_merge here due to performance reasons
59+
foreach ($bundleResourceTypeModel->getChildrenIdsForMultipleParents($productIds) as $parentId => $childrenIds) {
60+
$associations[$parentId] = $childrenIds;
61+
}
5562
return array_combine(array_keys($associations), array_map(
5663
function($parentId, $childrenIds) {
5764
return new \IntegerNet\Solr\Indexer\Data\ProductAssociation($parentId, $childrenIds);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* integer_net Magento Module
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Solr
7+
* @copyright Copyright (c) 2016 integer_net GmbH (http://www.integer-net.de/)
8+
* @author Andreas von Studnitz <avs@integer-net.de>
9+
*/
10+
class IntegerNet_Solr_Model_Resource_Catalog_Product_Type_Bundle extends Mage_Bundle_Model_Resource_Selection
11+
{
12+
/**
13+
* Retrieve Required children ids
14+
* Return grouped array, ex array(
15+
* group => array(ids)
16+
* )
17+
*
18+
* @param null|int[] $parentIds
19+
* @return int[][]
20+
*/
21+
public function getChildrenIdsForMultipleParents($parentIds)
22+
{
23+
$childrenIds = array();
24+
$adapter = $this->_getReadAdapter();
25+
$select = $adapter->select()
26+
->from(
27+
array('tbl_selection' => $this->getMainTable()),
28+
array('product_id', 'parent_product_id', 'option_id')
29+
)
30+
->join(
31+
array('e' => $this->getTable('catalog/product')),
32+
'e.entity_id = tbl_selection.product_id AND e.required_options=0',
33+
array()
34+
)
35+
->join(
36+
array('tbl_option' => $this->getTable('bundle/option')),
37+
'tbl_option.option_id = tbl_selection.option_id',
38+
array('required')
39+
);
40+
if (!is_null($parentIds)) {
41+
$select->where('tbl_selection.parent_product_id IN (?)', $parentIds);
42+
}
43+
44+
foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
45+
$childrenIds[$row['parent_product_id']][$row['product_id']] = $row['product_id'];
46+
}
47+
48+
return $childrenIds;
49+
}
50+
}

0 commit comments

Comments
 (0)