26
26
use Magento \Store \Model \Store ;
27
27
use Magento \Catalog \Model \ResourceModel \Category ;
28
28
use Zend_Db_Expr ;
29
+ use Magento \Catalog \Model \ResourceModel \Product \Gallery ;
29
30
30
31
/**
31
32
* Product collection
@@ -310,6 +311,9 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
310
311
* @param PriceTableResolver|null $priceTableResolver
311
312
* @param DimensionFactory|null $dimensionFactory
312
313
* @param Category|null $categoryResourceModel
314
+ * @param DbStorage|null $urlFinder
315
+ * @param GalleryReadHandler|null $productGalleryReadHandler
316
+ * @param Gallery|null $mediaGalleryResource
313
317
*
314
318
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
315
319
*/
@@ -339,7 +343,10 @@ public function __construct(
339
343
TableMaintainer $ tableMaintainer = null ,
340
344
PriceTableResolver $ priceTableResolver = null ,
341
345
DimensionFactory $ dimensionFactory = null ,
342
- Category $ categoryResourceModel = null
346
+ Category $ categoryResourceModel = null ,
347
+ DbStorage $ urlFinder = null ,
348
+ GalleryReadHandler $ productGalleryReadHandler = null ,
349
+ Gallery $ mediaGalleryResource = null
343
350
) {
344
351
$ this ->moduleManager = $ moduleManager ;
345
352
$ this ->_catalogProductFlatState = $ catalogProductFlatState ;
@@ -369,25 +376,19 @@ public function __construct(
369
376
$ storeManager ,
370
377
$ connection
371
378
);
372
- $ this ->tableMaintainer = $ tableMaintainer ?: ObjectManager::getInstance ()->get (TableMaintainer::class);
373
- $ this ->priceTableResolver = $ priceTableResolver ?: ObjectManager::getInstance ()->get (PriceTableResolver::class);
379
+ $ this ->tableMaintainer = $ tableMaintainer ?: ObjectManager::getInstance ()
380
+ ->get (TableMaintainer::class);
381
+ $ this ->priceTableResolver = $ priceTableResolver ?: ObjectManager::getInstance ()
382
+ ->get (PriceTableResolver::class);
374
383
$ this ->dimensionFactory = $ dimensionFactory
375
384
?: ObjectManager::getInstance ()->get (DimensionFactory::class);
376
385
$ this ->categoryResourceModel = $ categoryResourceModel ?: ObjectManager::getInstance ()
377
386
->get (Category::class);
378
- }
379
-
380
- /**
381
- * Retrieve urlFinder
382
- *
383
- * @return GalleryReadHandler
384
- */
385
- private function getUrlFinder ()
386
- {
387
- if ($ this ->urlFinder === null ) {
388
- $ this ->urlFinder = ObjectManager::getInstance ()->get (DbStorage::class);
389
- }
390
- return $ this ->urlFinder ;
387
+ $ this ->urlFinder = $ urlFinder ?: ObjectManager::getInstance ()->get (DbStorage::class);
388
+ $ this ->productGalleryReadHandler = $ productGalleryReadHandler ?: ObjectManager::getInstance ()
389
+ ->get (GalleryReadHandler::class);
390
+ $ this ->mediaGalleryResource = $ mediaGalleryResource ?: ObjectManager::getInstance ()
391
+ ->get (Gallery::class);
391
392
}
392
393
393
394
/**
@@ -1461,7 +1462,7 @@ protected function _addUrlRewrite()
1461
1462
$ filter ['metadata ' ]['category_id ' ] = $ this ->_urlRewriteCategory ;
1462
1463
}
1463
1464
1464
- $ rewrites = $ this ->getUrlFinder () ->findAllByData ($ filter );
1465
+ $ rewrites = $ this ->urlFinder ->findAllByData ($ filter );
1465
1466
foreach ($ rewrites as $ rewrite ) {
1466
1467
if ($ item = $ this ->getItemById ($ rewrite ->getEntityId ())) {
1467
1468
$ item ->setData ('request_path ' , $ rewrite ->getRequestPath ());
@@ -2347,7 +2348,7 @@ public function addMediaGalleryData()
2347
2348
$ items = $ this ->getItems ();
2348
2349
$ linkField = $ this ->getProductEntityMetadata ()->getLinkField ();
2349
2350
2350
- $ select = $ this ->getMediaGalleryResource ()
2351
+ $ select = $ this ->mediaGalleryResource
2351
2352
->createBatchBaseSelect (
2352
2353
$ this ->getStoreId (),
2353
2354
$ this ->getAttribute ('media_gallery ' )->getAttributeId ()
@@ -2369,7 +2370,7 @@ function ($item) use ($linkField) {
2369
2370
}
2370
2371
2371
2372
foreach ($ items as $ item ) {
2372
- $ this ->getGalleryReadHandler ()
2373
+ $ this ->productGalleryReadHandler
2373
2374
->addMediaDataToProduct (
2374
2375
$ item ,
2375
2376
$ mediaGalleries [$ item ->getOrigData ($ linkField )] ?? []
@@ -2391,35 +2392,6 @@ public function getProductEntityMetadata()
2391
2392
return $ this ->metadataPool ->getMetadata (ProductInterface::class);
2392
2393
}
2393
2394
2394
- /**
2395
- * Retrieve GalleryReadHandler
2396
- *
2397
- * @return GalleryReadHandler
2398
- * @deprecated 101.0.1
2399
- */
2400
- private function getGalleryReadHandler ()
2401
- {
2402
- if ($ this ->productGalleryReadHandler === null ) {
2403
- $ this ->productGalleryReadHandler = ObjectManager::getInstance ()->get (GalleryReadHandler::class);
2404
- }
2405
- return $ this ->productGalleryReadHandler ;
2406
- }
2407
-
2408
- /**
2409
- * Retrieve Media gallery resource.
2410
- *
2411
- * @deprecated 101.0.1
2412
- *
2413
- * @return \Magento\Catalog\Model\ResourceModel\Product\Gallery
2414
- */
2415
- private function getMediaGalleryResource ()
2416
- {
2417
- if (null === $ this ->mediaGalleryResource ) {
2418
- $ this ->mediaGalleryResource = ObjectManager::getInstance ()->get (Gallery::class);
2419
- }
2420
- return $ this ->mediaGalleryResource ;
2421
- }
2422
-
2423
2395
/**
2424
2396
* Clear collection
2425
2397
*
0 commit comments