Skip to content

Commit de67de9

Browse files
committed
Merge branch 'develop'
2 parents ebb81fc + 221a8b9 commit de67de9

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

main/src/Model/Bridge/PagedProductIterator.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace IntegerNet\Solr\Model\Bridge;
1212

13-
1413
use IntegerNet\Solr\Implementor\PagedProductIterator as PagedProductIteratorInterface;
1514
use IntegerNet\Solr\Implementor\Product as ProductInterface;
1615
use IntegerNet\Solr\Implementor\ProductFactory as ProductFactoryInterface;
@@ -20,6 +19,7 @@
2019
use IntegerNet\Solr\Model\Indexer\ProductCollectionFactory;
2120
use Magento\Catalog\Model\ResourceModel\Product\Collection;
2221
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
22+
use Magento\Framework\Event\ManagerInterface as EventManager;
2323

2424
class PagedProductIterator implements PagedProductIteratorInterface, \OuterIterator
2525
{
@@ -67,18 +67,29 @@ class PagedProductIterator implements PagedProductIteratorInterface, \OuterItera
6767

6868
const PARAM_PRODUCT_ID_CHUNKS = 'productIdChunks';
6969
const PARAM_STORE_ID = 'storeId';
70+
/**
71+
* @var EventManager
72+
*/
73+
private $eventManager;
74+
7075
/**
7176
* @param ProductCollectionFactory $collectionFactory
7277
* @param ProductFactoryInterface $productFactory
7378
* @param ProductIdChunks $productIdChunks parent and children product ids to be loaded
7479
* @param int $storeId
7580
*/
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+
) {
7888
$this->productFactory = $productFactory;
7989
$this->storeId = $storeId;
8090
$this->collectionFactory = $collectionFactory;
8191
$this->productIdChunks = $productIdChunks;
92+
$this->eventManager = $eventManager;
8293
}
8394

8495
/**
@@ -91,7 +102,14 @@ private function getProductCollection()
91102
$collection->setCurPage($this->currentChunkId);
92103
$collection->setPageSize($this->pageSize);
93104

105+
$this->eventManager->dispatch('integernet_solr_product_collection_load_before', [
106+
'collection' => $collection,
107+
]);
94108
$collection->load();
109+
$this->eventManager->dispatch('integernet_solr_product_collection_load_after', [
110+
'collection' => $collection,
111+
]);
112+
95113
return $collection;
96114
}
97115

@@ -194,25 +212,19 @@ public function currentChunk()
194212
}
195213

196214
/**
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.
199216
*
200217
* @param int[] $ids
201218
* @return ProductIteratorInterface
202-
* @throws \OutOfBoundsException
203219
*/
204220
public function subset($ids)
205221
{
206222
$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);
213225
});
214226

215-
return new ProductIterator($this->productFactory, $products->getArrayCopy(), $this->storeId);
227+
return new ProductIterator($this->productFactory, array_filter($products->getArrayCopy()), $this->storeId);
216228
}
217229

218230
/**

main/src/Model/Indexer/ProductCollectionFactory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ class ProductCollectionFactory
5050
* @param AttributeRepositoryInterface $attributeRepository
5151
* @param StockStatusFactory $stockStatusFactory
5252
*/
53-
public function __construct(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory, CatalogConfig $catalogConfig, AttributeRepositoryInterface $attributeRepository, StockStatusFactory $stockStatusFactory)
54-
{
53+
public function __construct(
54+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory,
55+
CatalogConfig $catalogConfig,
56+
AttributeRepositoryInterface $attributeRepository,
57+
StockStatusFactory $stockStatusFactory
58+
) {
5559
$this->collectionFactory = $collectionFactory;
5660
$this->catalogConfig = $catalogConfig;
5761
$this->attributeRepository = $attributeRepository;

0 commit comments

Comments
 (0)