Skip to content

Commit 93a5c39

Browse files
committed
#8168: Configurable product on wishlist shows parent image instead variation image
1 parent 506d500 commit 93a5c39

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
@@ -190,4 +190,64 @@ public function createDataProvider()
190190
],
191191
];
192192
}
193+
194+
/**
195+
* @param array $data
196+
* @param array $expected
197+
* @dataProvider createDataProvider
198+
*/
199+
public function testCreateWithSimpleProduct($data, $expected)
200+
{
201+
$imageId = 'test_image_id';
202+
203+
$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
204+
$simpleOptionMock = $this->createMock(\Magento\Wishlist\Model\Item\Option::class);
205+
$simpleProductMock = $this->createMock(\Magento\Catalog\Model\Product::class);
206+
207+
$productMock->expects($this->once())->method('getCustomOption')
208+
->with('simple_product')->willReturn($simpleOptionMock);
209+
210+
$simpleOptionMock->expects($this->once())->method('getProduct')->willReturn($simpleProductMock);
211+
212+
$helperMock = $this->createMock(\Magento\Catalog\Helper\Image::class);
213+
$helperMock->expects($this->once())
214+
->method('init')
215+
->with($simpleProductMock, $imageId)
216+
->willReturnSelf();
217+
$helperMock->expects($this->once())
218+
->method('getFrame')
219+
->willReturn($data['frame']);
220+
$helperMock->expects($this->once())
221+
->method('getUrl')
222+
->willReturn($data['url']);
223+
$helperMock->expects($this->exactly(2))
224+
->method('getWidth')
225+
->willReturn($data['width']);
226+
$helperMock->expects($this->exactly(2))
227+
->method('getHeight')
228+
->willReturn($data['height']);
229+
$helperMock->expects($this->once())
230+
->method('getLabel')
231+
->willReturn($data['label']);
232+
$helperMock->expects($this->once())
233+
->method('getResizedImageInfo')
234+
->willReturn($data['imagesize']);
235+
236+
$this->helperFactory->expects($this->once())
237+
->method('create')
238+
->willReturn($helperMock);
239+
240+
$imageMock = $this->createMock(\Magento\Catalog\Block\Product\Image::class);
241+
242+
$this->imageFactory->expects($this->once())
243+
->method('create')
244+
->with($expected)
245+
->willReturn($imageMock);
246+
247+
$this->model->setProduct($productMock);
248+
$this->model->setImageId($imageId);
249+
$this->model->setAttributes($data['custom_attributes']);
250+
251+
$this->assertInstanceOf(\Magento\Catalog\Block\Product\Image::class, $this->model->create());
252+
}
193253
}

0 commit comments

Comments
 (0)