Skip to content

Commit fb64086

Browse files
MAGETWO-86661: #8168: Configurable product on wishlist shows parent image instead variation image #1031
- Merge Pull Request magento-engcom/magento2ce#1031 from RomaKis/magento2ce:8168 - Merged commits: 1. 93a5c39
2 parents 5afa7d3 + 93a5c39 commit fb64086

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

app/code/Magento/Catalog/Block/Product/ImageBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ protected function getRatio(\Magento\Catalog\Helper\Image $helper)
121121
*/
122122
public function create()
123123
{
124+
/** @var \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface $simpleOption */
125+
$simpleOption = $this->product->getCustomOption('simple_product');
126+
127+
if ($simpleOption !== null) {
128+
$optionProduct = $simpleOption->getProduct();
129+
$this->setProduct($optionProduct);
130+
}
131+
124132
/** @var \Magento\Catalog\Helper\Image $helper */
125133
$helper = $this->helperFactory->create()
126134
->init($this->product, $this->imageId);

app/code/Magento/Catalog/Test/Unit/Block/Product/ImageBuilderTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,64 @@ private function getTestDataWithAttributes(): array
290290
],
291291
];
292292
}
293+
294+
/**
295+
* @param array $data
296+
* @param array $expected
297+
* @dataProvider createDataProvider
298+
*/
299+
public function testCreateWithSimpleProduct($data, $expected)
300+
{
301+
$imageId = 'test_image_id';
302+
303+
$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
304+
$simpleOptionMock = $this->createMock(\Magento\Wishlist\Model\Item\Option::class);
305+
$simpleProductMock = $this->createMock(\Magento\Catalog\Model\Product::class);
306+
307+
$productMock->expects($this->once())->method('getCustomOption')
308+
->with('simple_product')->willReturn($simpleOptionMock);
309+
310+
$simpleOptionMock->expects($this->once())->method('getProduct')->willReturn($simpleProductMock);
311+
312+
$helperMock = $this->createMock(\Magento\Catalog\Helper\Image::class);
313+
$helperMock->expects($this->once())
314+
->method('init')
315+
->with($simpleProductMock, $imageId)
316+
->willReturnSelf();
317+
$helperMock->expects($this->once())
318+
->method('getFrame')
319+
->willReturn($data['frame']);
320+
$helperMock->expects($this->once())
321+
->method('getUrl')
322+
->willReturn($data['url']);
323+
$helperMock->expects($this->exactly(2))
324+
->method('getWidth')
325+
->willReturn($data['width']);
326+
$helperMock->expects($this->exactly(2))
327+
->method('getHeight')
328+
->willReturn($data['height']);
329+
$helperMock->expects($this->once())
330+
->method('getLabel')
331+
->willReturn($data['label']);
332+
$helperMock->expects($this->once())
333+
->method('getResizedImageInfo')
334+
->willReturn($data['imagesize']);
335+
336+
$this->helperFactory->expects($this->once())
337+
->method('create')
338+
->willReturn($helperMock);
339+
340+
$imageMock = $this->createMock(\Magento\Catalog\Block\Product\Image::class);
341+
342+
$this->imageFactory->expects($this->once())
343+
->method('create')
344+
->with($expected)
345+
->willReturn($imageMock);
346+
347+
$this->model->setProduct($productMock);
348+
$this->model->setImageId($imageId);
349+
$this->model->setAttributes($data['custom_attributes']);
350+
351+
$this->assertInstanceOf(\Magento\Catalog\Block\Product\Image::class, $this->model->create());
352+
}
293353
}

0 commit comments

Comments
 (0)