Skip to content

Commit c0baca9

Browse files
authored
Merge pull request #87 from mageplaza/2.3-develop
v2.0.9
2 parents 78bb905 + a7ef265 commit c0baca9

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

Block/CategoryId.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public function getProductCollection()
9090
$collection = [];
9191
if (!empty($productIds)) {
9292
$collection = $this->_productCollectionFactory->create()
93-
->addIdFilter($productIds)
94-
->setPageSize($this->getProductsCount());
93+
->addIdFilter(array('in' => $productIds));
9594
$this->_addProductAttributesAndPrices($collection);
9695
}
9796

@@ -109,10 +108,7 @@ public function getProductIdsByCategory()
109108
$catIds = $this->getSliderCategoryIds();
110109
$collection = $this->_productCollectionFactory->create();
111110
if (is_array($catIds)) {
112-
foreach ($catIds as $catId) {
113-
$category = $this->_categoryFactory->create()->load($catId);
114-
$collection->addAttributeToSelect('*')->addCategoryFilter($category);
115-
}
111+
$collection->addAttributeToSelect('*')->addCategoriesFilter(array('in' => $catIds));
116112
} else {
117113
$category = $this->_categoryFactory->create()->load($catIds);
118114
$collection->addAttributeToSelect('*')->addCategoryFilter($category);
@@ -122,7 +118,18 @@ public function getProductIdsByCategory()
122118
$productIds[] = $item->getData('entity_id');
123119
}
124120

125-
return $productIds;
121+
$keys = array_keys($productIds);
122+
shuffle($keys);
123+
$productIdsRandom = [];
124+
125+
foreach ($keys as $key => $value) {
126+
$productIdsRandom[$value] = $productIds[$value];
127+
if ($key >= ($this->getProductsCount() - 1)) {
128+
break;
129+
}
130+
}
131+
132+
return $productIdsRandom;
126133
}
127134

128135
/**

composer.json

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
{
2-
"name": "mageplaza/magento-2-product-slider",
3-
"description": "Magento 2 Product Slider",
4-
"require": {
5-
"mageplaza/module-core": "^1.4.5"
6-
},
7-
"type": "magento2-module",
8-
"version": "2.0.8",
9-
"license": "proprietary",
10-
"authors": [
11-
{
12-
"name": "Mageplaza",
13-
"email": "[email protected]",
14-
"homepage": "https://www.mageplaza.com",
15-
"role": "Technical Support"
16-
}
17-
],
18-
"autoload": {
19-
"files": [
20-
"registration.php"
21-
],
22-
"psr-4": {
23-
"Mageplaza\\Productslider\\": ""
24-
}
25-
}
26-
}
1+
{
2+
"name": "mageplaza/magento-2-product-slider",
3+
"description": "Magento 2 Product Slider",
4+
"require": {
5+
"mageplaza/module-core": "^1.4.5"
6+
},
7+
"type": "magento2-module",
8+
"version": "2.0.9",
9+
"license": "proprietary",
10+
"authors": [
11+
{
12+
"name": "Mageplaza",
13+
"email": "[email protected]",
14+
"homepage": "https://www.mageplaza.com",
15+
"role": "Technical Support"
16+
}
17+
],
18+
"autoload": {
19+
"files": [
20+
"registration.php"
21+
],
22+
"psr-4": {
23+
"Mageplaza\\Productslider\\": ""
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)