Skip to content

Commit 8951449

Browse files
Allow injection of Magento\Catalog\Model\View\Asset\ImageFactory
1 parent d4f730e commit 8951449

File tree

1 file changed

+11
-16
lines changed
  • app/code/Magento/Catalog/Model/Product

1 file changed

+11
-16
lines changed

app/code/Magento/Catalog/Model/Product/Image.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class Image extends \Magento\Framework\Model\AbstractModel
173173
/**
174174
* @var \Magento\Catalog\Model\View\Asset\ImageFactory
175175
*/
176-
private $viewAssetImageFactory;
176+
protected $_viewAssetImageFactory;
177177

178178
/**
179179
* @var \Magento\Catalog\Model\View\Asset\PlaceholderFactory
@@ -198,6 +198,7 @@ class Image extends \Magento\Framework\Model\AbstractModel
198198
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
199199
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
200200
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
201+
* @param \Magento\Catalog\Model\View\Asset\ImageFactory $viewAssetImageFactory
201202
* @param array $data
202203
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
203204
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
@@ -215,6 +216,7 @@ public function __construct(
215216
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
216217
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
217218
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
219+
\Magento\Catalog\Model\View\Asset\ImageFactory $viewAssetImageFactory = null,
218220
array $data = []
219221
) {
220222
$this->_storeManager = $storeManager;
@@ -226,6 +228,13 @@ public function __construct(
226228
$this->_assetRepo = $assetRepo;
227229
$this->_viewFileSystem = $viewFileSystem;
228230
$this->_scopeConfig = $scopeConfig;
231+
if ($viewAssetImageFactory == null) {
232+
$this->_viewAssetImageFactory = ObjectManager::getInstance()->get(
233+
\Magento\Catalog\Model\View\Asset\ImageFactory::class
234+
);
235+
} else {
236+
$this->_viewAssetImageFactory = $viewAssetImageFactory;
237+
}
229238
}
230239

231240
/**
@@ -469,7 +478,7 @@ public function setBaseFile($file)
469478
{
470479
$this->_isBaseFilePlaceholder = false;
471480

472-
$this->imageAsset = $this->getViewAssetImageFactory()->create(
481+
$this->imageAsset = $this->_viewAssetImageFactory->create(
473482
[
474483
'miscParams' => $this->getMiscParams(),
475484
'filePath' => $file,
@@ -894,20 +903,6 @@ public function getResizedImageInfo()
894903
return getimagesize($image);
895904
}
896905

897-
/**
898-
* @return \Magento\Catalog\Model\View\Asset\ImageFactory
899-
*/
900-
private function getViewAssetImageFactory()
901-
{
902-
if ($this->viewAssetImageFactory == null) {
903-
$this->viewAssetImageFactory = ObjectManager::getInstance()->get(
904-
\Magento\Catalog\Model\View\Asset\ImageFactory::class
905-
);
906-
}
907-
908-
return $this->viewAssetImageFactory;
909-
}
910-
911906
/**
912907
* @return \Magento\Catalog\Model\View\Asset\PlaceholderFactory
913908
*/

0 commit comments

Comments
 (0)