@@ -90,8 +90,7 @@ public function getProductCollection()
90
90
$ collection = [];
91
91
if (!empty ($ productIds )) {
92
92
$ collection = $ this ->_productCollectionFactory ->create ()
93
- ->addIdFilter ($ productIds )
94
- ->setPageSize ($ this ->getProductsCount ());
93
+ ->addIdFilter (array ('in ' => $ productIds ));
95
94
$ this ->_addProductAttributesAndPrices ($ collection );
96
95
}
97
96
@@ -109,10 +108,7 @@ public function getProductIdsByCategory()
109
108
$ catIds = $ this ->getSliderCategoryIds ();
110
109
$ collection = $ this ->_productCollectionFactory ->create ();
111
110
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 ));
116
112
} else {
117
113
$ category = $ this ->_categoryFactory ->create ()->load ($ catIds );
118
114
$ collection ->addAttributeToSelect ('* ' )->addCategoryFilter ($ category );
@@ -122,7 +118,18 @@ public function getProductIdsByCategory()
122
118
$ productIds [] = $ item ->getData ('entity_id ' );
123
119
}
124
120
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 ;
126
133
}
127
134
128
135
/**
0 commit comments