@@ -118,33 +118,41 @@ public function getProductIdsByCategory()
118
118
{
119
119
$ productIds = [];
120
120
$ catIds = $ this ->getSliderCategoryIds ();
121
- $ collection = $ this ->_productCollectionFactory ->create ();
122
121
123
122
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 ();
126
139
$ category = $ this ->_categoryFactory ->create ()->load ($ catIds );
127
140
$ collection ->addAttributeToSelect ('* ' )->addCategoryFilter ($ category );
128
- }
129
141
130
- foreach ($ collection as $ item ) {
131
- $ productIds [] = $ item ->getData ('entity_id ' );
142
+ foreach ($ collection as $ item ) {
143
+ $ productIds [] = $ item ->getData ('entity_id ' );
144
+ }
132
145
}
133
146
134
147
$ keys = array_keys ($ productIds );
135
148
shuffle ($ keys );
136
149
$ productIdsRandom = [];
137
150
138
151
foreach ($ keys as $ key => $ value ) {
139
- $ productCollection = $ collection ->addIdFilter ($ productIds [$ value ]);
140
- $ mpProductIds = $ this ->getProductParentIds ($ productCollection );
152
+ $ productIdsRandom [] = $ productIds [$ value ];
141
153
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 ;
148
156
}
149
157
}
150
158
0 commit comments