Skip to content

Commit 143a2cf

Browse files
[Fix bug] Show slider with configurable products.
1 parent 150c2a9 commit 143a2cf

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Block/CategoryId.php

+22-14
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,41 @@ public function getProductIdsByCategory()
118118
{
119119
$productIds = [];
120120
$catIds = $this->getSliderCategoryIds();
121-
$collection = $this->_productCollectionFactory->create();
122121

123122
if (is_array($catIds)) {
124-
$collection->addAttributeToSelect('*')->addCategoriesFilter(array('in' => $catIds));
125-
} else {
123+
$productId = [];
124+
125+
foreach($catIds as $cat)
126+
{
127+
$collection = $this->_productCollectionFactory->create();
128+
$category = $this->_categoryFactory->create()->load($cat);
129+
$collection->addAttributeToSelect('*')->addCategoryFilter($category);
130+
131+
foreach ($collection as $item) {
132+
$productId[] = $item->getData('entity_id');
133+
}
134+
135+
$productIds = array_merge($productIds, $productId);
136+
}
137+
}else {
138+
$collection = $this->_productCollectionFactory->create();
126139
$category = $this->_categoryFactory->create()->load($catIds);
127140
$collection->addAttributeToSelect('*')->addCategoryFilter($category);
128-
}
129141

130-
foreach ($collection as $item) {
131-
$productIds[] = $item->getData('entity_id');
142+
foreach ($collection as $item) {
143+
$productIds[] = $item->getData('entity_id');
144+
}
132145
}
133146

134147
$keys = array_keys($productIds);
135148
shuffle($keys);
136149
$productIdsRandom = [];
137150

138151
foreach ($keys as $key => $value) {
139-
$productCollection = $collection->addIdFilter($productIds[$value]);
140-
$mpProductIds = $this->getProductParentIds($productCollection);
152+
$productIdsRandom[] = $productIds[$value];
141153

142-
if (!in_array($mpProductIds, $productIdsRandom) && !empty($mpProductIds)) {
143-
$productIdsRandom[] = $mpProductIds[$value];
144-
145-
if ($key >= ($this->getProductsCount() - 1)) {
146-
break;
147-
}
154+
if ($key >= ($this->getProductsCount() - 1)) {
155+
break;
148156
}
149157
}
150158

0 commit comments

Comments
 (0)