Skip to content

Commit c127b4c

Browse files
committed
Add optional dependencies for product model and catalog image helper
1 parent da4de8b commit c127b4c

File tree

1 file changed

+22
-8
lines changed
  • app/code/Magento/Sitemap/Model/ResourceModel/Catalog

1 file changed

+22
-8
lines changed

app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php

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

1111
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
1212
use Magento\Store\Model\Store;
13-
use Magento\Framework\App\ObjectManager;
1413

1514
/**
1615
* Sitemap resource product collection model
@@ -82,6 +81,16 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
8281
*/
8382
protected $_mediaConfig;
8483

84+
/**
85+
* @var \Magento\Catalog\Model\Product
86+
*/
87+
protected $productModel;
88+
89+
/**
90+
* @var \Magento\Catalog\Helper\Image
91+
*/
92+
protected $catalogImageHelper;
93+
8594
/**
8695
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
8796
* @param \Magento\Sitemap\Helper\Data $sitemapData
@@ -93,6 +102,8 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
93102
* @param \Magento\Catalog\Model\Product\Gallery\ReadHandler $mediaGalleryReadHandler
94103
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
95104
* @param string $connectionName
105+
* @param \Magento\Catalog\Model\Product $productModel
106+
* @param \Magento\Catalog\Helper\Image $catalogImageHelper
96107
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
97108
*/
98109
public function __construct(
@@ -105,7 +116,9 @@ public function __construct(
105116
\Magento\Catalog\Model\ResourceModel\Product\Gallery $mediaGalleryResourceModel,
106117
\Magento\Catalog\Model\Product\Gallery\ReadHandler $mediaGalleryReadHandler,
107118
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
108-
$connectionName = null
119+
$connectionName = null,
120+
\Magento\Catalog\Model\Product $productModel = null,
121+
\Magento\Catalog\Helper\Image $catalogImageHelper = null
109122
) {
110123
$this->_productResource = $productResource;
111124
$this->_storeManager = $storeManager;
@@ -115,6 +128,8 @@ public function __construct(
115128
$this->mediaGalleryReadHandler = $mediaGalleryReadHandler;
116129
$this->_mediaConfig = $mediaConfig;
117130
$this->_sitemapData = $sitemapData;
131+
$this->productModel = $productModel ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
132+
$this->catalogImageHelper = $catalogImageHelper ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Catalog\Helper\Image::class);
118133
parent::__construct($context, $connectionName);
119134
}
120135

@@ -419,12 +434,11 @@ protected function _getMediaConfig()
419434
*/
420435
private function getProductImageUrl($image)
421436
{
422-
$productObject = ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
423-
$imgUrl = ObjectManager::getInstance()
424-
->get(\Magento\Catalog\Helper\Image::class)
425-
->init($productObject, 'product_page_image_large')
426-
->setImageFile($image)
427-
->getUrl();
437+
$productObject = $this->productModel;
438+
$imgUrl = $this->catalogImageHelper
439+
->init($productObject, 'product_page_image_large')
440+
->setImageFile($image)
441+
->getUrl();
428442

429443
return $imgUrl;
430444
}

0 commit comments

Comments
 (0)