10
10
11
11
namespace IntegerNet \Solr \Model \Bridge ;
12
12
13
-
14
13
use IntegerNet \Solr \Implementor \PagedProductIterator as PagedProductIteratorInterface ;
15
14
use IntegerNet \Solr \Implementor \Product as ProductInterface ;
16
15
use IntegerNet \Solr \Implementor \ProductFactory as ProductFactoryInterface ;
20
19
use IntegerNet \Solr \Model \Indexer \ProductCollectionFactory ;
21
20
use Magento \Catalog \Model \ResourceModel \Product \Collection ;
22
21
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
22
+ use Magento \Framework \Event \ManagerInterface as EventManager ;
23
23
24
24
class PagedProductIterator implements PagedProductIteratorInterface, \OuterIterator
25
25
{
@@ -67,18 +67,29 @@ class PagedProductIterator implements PagedProductIteratorInterface, \OuterItera
67
67
68
68
const PARAM_PRODUCT_ID_CHUNKS = 'productIdChunks ' ;
69
69
const PARAM_STORE_ID = 'storeId ' ;
70
+ /**
71
+ * @var EventManager
72
+ */
73
+ private $ eventManager ;
74
+
70
75
/**
71
76
* @param ProductCollectionFactory $collectionFactory
72
77
* @param ProductFactoryInterface $productFactory
73
78
* @param ProductIdChunks $productIdChunks parent and children product ids to be loaded
74
79
* @param int $storeId
75
80
*/
76
- public function __construct (ProductCollectionFactory $ collectionFactory , ProductFactoryInterface $ productFactory , ProductIdChunks $ productIdChunks , $ storeId = null )
77
- {
81
+ public function __construct (
82
+ ProductCollectionFactory $ collectionFactory ,
83
+ ProductFactoryInterface $ productFactory ,
84
+ ProductIdChunks $ productIdChunks ,
85
+ EventManager $ eventManager ,
86
+ $ storeId = null
87
+ ) {
78
88
$ this ->productFactory = $ productFactory ;
79
89
$ this ->storeId = $ storeId ;
80
90
$ this ->collectionFactory = $ collectionFactory ;
81
91
$ this ->productIdChunks = $ productIdChunks ;
92
+ $ this ->eventManager = $ eventManager ;
82
93
}
83
94
84
95
/**
@@ -91,7 +102,14 @@ private function getProductCollection()
91
102
$ collection ->setCurPage ($ this ->currentChunkId );
92
103
$ collection ->setPageSize ($ this ->pageSize );
93
104
105
+ $ this ->eventManager ->dispatch ('integernet_solr_product_collection_load_before ' , [
106
+ 'collection ' => $ collection ,
107
+ ]);
94
108
$ collection ->load ();
109
+ $ this ->eventManager ->dispatch ('integernet_solr_product_collection_load_after ' , [
110
+ 'collection ' => $ collection ,
111
+ ]);
112
+
95
113
return $ collection ;
96
114
}
97
115
@@ -194,25 +212,19 @@ public function currentChunk()
194
212
}
195
213
196
214
/**
197
- * Returns an iterator for a subset of products. The ids must be part of the current chunk, otherwise an
198
- * OutOfBoundsException will be thrown
215
+ * Returns an iterator for a subset of products. If the ID is not part of the current chunk, it will be ignored.
199
216
*
200
217
* @param int[] $ids
201
218
* @return ProductIteratorInterface
202
- * @throws \OutOfBoundsException
203
219
*/
204
220
public function subset ($ ids )
205
221
{
206
222
$ products = ArrayCollection::fromArray ($ ids )
207
- ->map (function ($ id ) {
208
- $ product = $ this ->collection ->getItemById ($ id );
209
- if ($ product === null ) {
210
- throw new \OutOfBoundsException ("Item with id $ id is not loaded in current chunk " );
211
- }
212
- return $ product ;
223
+ ->map (function ($ id ) {
224
+ return $ this ->collection ->getItemById ($ id );
213
225
});
214
226
215
- return new ProductIterator ($ this ->productFactory , $ products ->getArrayCopy (), $ this ->storeId );
227
+ return new ProductIterator ($ this ->productFactory , array_filter ( $ products ->getArrayCopy () ), $ this ->storeId );
216
228
}
217
229
218
230
/**
0 commit comments