Skip to content

Commit e7c9ab8

Browse files
committed
MAGETWO-65251: [Backport] - [Performance] Image resize mechanism does not generate images of all necessary sizes - for 2.1.6
1 parent b710d0e commit e7c9ab8

File tree

2 files changed

+37
-56
lines changed

2 files changed

+37
-56
lines changed

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

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class Image extends \Magento\Framework\Model\AbstractModel
199199
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
200200
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
201201
* @param array $data
202+
* @param \Magento\Catalog\Model\View\Asset\ImageFactory $assetImageFactory
203+
* @param \Magento\Catalog\Model\View\Asset\PlaceholderFactory $assetPlaceholderFactory
202204
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
203205
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
204206
*/
@@ -215,7 +217,9 @@ public function __construct(
215217
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
216218
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
217219
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
218-
array $data = []
220+
array $data = [],
221+
\Magento\Catalog\Model\View\Asset\ImageFactory $assetImageFactory = null,
222+
\Magento\Catalog\Model\View\Asset\PlaceholderFactory $assetPlaceholderFactory = null
219223
) {
220224
$this->_storeManager = $storeManager;
221225
$this->_catalogProductMediaConfig = $catalogProductMediaConfig;
@@ -226,6 +230,18 @@ public function __construct(
226230
$this->_assetRepo = $assetRepo;
227231
$this->_viewFileSystem = $viewFileSystem;
228232
$this->_scopeConfig = $scopeConfig;
233+
$this->viewAssetImageFactory = $assetImageFactory;
234+
if ($this->viewAssetImageFactory == null) {
235+
$this->viewAssetImageFactory = ObjectManager::getInstance()->get(
236+
\Magento\Catalog\Model\View\Asset\ImageFactory::class
237+
);
238+
}
239+
$this->viewAssetPlaceholderFactory = $assetPlaceholderFactory;
240+
if ($this->viewAssetPlaceholderFactory == null) {
241+
$this->viewAssetPlaceholderFactory = ObjectManager::getInstance()->get(
242+
\Magento\Catalog\Model\View\Asset\PlaceholderFactory::class
243+
);
244+
}
229245
}
230246

231247
/**
@@ -469,7 +485,7 @@ public function setBaseFile($file)
469485
{
470486
$this->_isBaseFilePlaceholder = false;
471487

472-
$this->imageAsset = $this->getViewAssetImageFactory()->create(
488+
$this->imageAsset = $this->viewAssetImageFactory->create(
473489
[
474490
'miscParams' => $this->getMiscParams(),
475491
'filePath' => $file,
@@ -479,7 +495,7 @@ public function setBaseFile($file)
479495
|| !$this->_checkMemory($this->imageAsset->getSourceFile())
480496
) {
481497
$this->_isBaseFilePlaceholder = true;
482-
$this->imageAsset = $this->getViewAssetPlaceholderFactory()->create(
498+
$this->imageAsset = $this->viewAssetPlaceholderFactory->create(
483499
[
484500
'type' => $this->getDestinationSubdir(),
485501
]
@@ -895,38 +911,6 @@ public function getResizedImageInfo()
895911
return getimagesize($image);
896912
}
897913

898-
/**
899-
* Get assets ImageFactory object
900-
*
901-
* @return \Magento\Catalog\Model\View\Asset\ImageFactory
902-
*/
903-
private function getViewAssetImageFactory()
904-
{
905-
if ($this->viewAssetImageFactory == null) {
906-
$this->viewAssetImageFactory = ObjectManager::getInstance()->get(
907-
\Magento\Catalog\Model\View\Asset\ImageFactory::class
908-
);
909-
}
910-
911-
return $this->viewAssetImageFactory;
912-
}
913-
914-
/**
915-
* Get assets PlaceholderFactory object
916-
*
917-
* @return \Magento\Catalog\Model\View\Asset\PlaceholderFactory
918-
*/
919-
private function getViewAssetPlaceholderFactory()
920-
{
921-
if ($this->viewAssetPlaceholderFactory == null) {
922-
$this->viewAssetPlaceholderFactory = ObjectManager::getInstance()->get(
923-
\Magento\Catalog\Model\View\Asset\PlaceholderFactory::class
924-
);
925-
}
926-
927-
return $this->viewAssetPlaceholderFactory;
928-
}
929-
930914
/**
931915
* Retrieve misc params based on all image attributes
932916
*

app/code/Magento/Catalog/Test/Unit/Model/Product/ImageTest.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ protected function setUp()
132132
$context = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
133133
->disableOriginalConstructor()
134134
->getMock();
135+
136+
$this->viewAssetImageFactory = $this->getMockBuilder(ImageFactory::class)
137+
->disableOriginalConstructor()
138+
->setMethods(['create'])
139+
->getMock();
140+
141+
$this->viewAssetPlaceholderFactory = $this->getMockBuilder(PlaceholderFactory::class)
142+
->disableOriginalConstructor()
143+
->setMethods(['create'])
144+
->getMock();
145+
135146
$this->image = new \Magento\Catalog\Model\Product\Image(
136147
$context,
137148
$this->registry,
@@ -142,8 +153,14 @@ protected function setUp()
142153
$this->factory,
143154
$this->repository,
144155
$this->fileSystem,
145-
$this->scopeConfigInterface
156+
$this->scopeConfigInterface,
157+
null,
158+
null,
159+
[],
160+
$this->viewAssetImageFactory,
161+
$this->viewAssetPlaceholderFactory
146162
);
163+
147164
//Settings for backward compatible property
148165
$objectManagerHelper = new ObjectManagerHelper($this);
149166
$this->imageAsset = $this->getMockBuilder(\Magento\Framework\View\Asset\LocalInterface::class)
@@ -153,26 +170,6 @@ protected function setUp()
153170
'imageAsset',
154171
$this->imageAsset
155172
);
156-
157-
$this->viewAssetImageFactory = $this->getMockBuilder(ImageFactory::class)
158-
->disableOriginalConstructor()
159-
->setMethods(['create'])
160-
->getMock();
161-
$objectManagerHelper->setBackwardCompatibleProperty(
162-
$this->image,
163-
'viewAssetImageFactory',
164-
$this->viewAssetImageFactory
165-
);
166-
167-
$this->viewAssetPlaceholderFactory = $this->getMockBuilder(PlaceholderFactory::class)
168-
->disableOriginalConstructor()
169-
->setMethods(['create'])
170-
->getMock();
171-
$objectManagerHelper->setBackwardCompatibleProperty(
172-
$this->image,
173-
'viewAssetPlaceholderFactory',
174-
$this->viewAssetPlaceholderFactory
175-
);
176173
}
177174

178175
public function testSetGetQuality()

0 commit comments

Comments
 (0)