Skip to content

Commit

Permalink
#8168: Configurable product on wishlist shows parent image instead va…
Browse files Browse the repository at this point in the history
…riation image
  • Loading branch information
RomaKis committed Dec 14, 2017
1 parent 506d500 commit 93a5c39
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/code/Magento/Catalog/Block/Product/ImageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ protected function getRatio(\Magento\Catalog\Helper\Image $helper)
*/
public function create()
{
/** @var \Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface $simpleOption */
$simpleOption = $this->product->getCustomOption('simple_product');

if ($simpleOption !== null) {
$optionProduct = $simpleOption->getProduct();
$this->setProduct($optionProduct);
}

/** @var \Magento\Catalog\Helper\Image $helper */
$helper = $this->helperFactory->create()
->init($this->product, $this->imageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,64 @@ public function createDataProvider()
],
];
}

/**
* @param array $data
* @param array $expected
* @dataProvider createDataProvider
*/
public function testCreateWithSimpleProduct($data, $expected)
{
$imageId = 'test_image_id';

$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
$simpleOptionMock = $this->createMock(\Magento\Wishlist\Model\Item\Option::class);
$simpleProductMock = $this->createMock(\Magento\Catalog\Model\Product::class);

$productMock->expects($this->once())->method('getCustomOption')
->with('simple_product')->willReturn($simpleOptionMock);

$simpleOptionMock->expects($this->once())->method('getProduct')->willReturn($simpleProductMock);

$helperMock = $this->createMock(\Magento\Catalog\Helper\Image::class);
$helperMock->expects($this->once())
->method('init')
->with($simpleProductMock, $imageId)
->willReturnSelf();
$helperMock->expects($this->once())
->method('getFrame')
->willReturn($data['frame']);
$helperMock->expects($this->once())
->method('getUrl')
->willReturn($data['url']);
$helperMock->expects($this->exactly(2))
->method('getWidth')
->willReturn($data['width']);
$helperMock->expects($this->exactly(2))
->method('getHeight')
->willReturn($data['height']);
$helperMock->expects($this->once())
->method('getLabel')
->willReturn($data['label']);
$helperMock->expects($this->once())
->method('getResizedImageInfo')
->willReturn($data['imagesize']);

$this->helperFactory->expects($this->once())
->method('create')
->willReturn($helperMock);

$imageMock = $this->createMock(\Magento\Catalog\Block\Product\Image::class);

$this->imageFactory->expects($this->once())
->method('create')
->with($expected)
->willReturn($imageMock);

$this->model->setProduct($productMock);
$this->model->setImageId($imageId);
$this->model->setAttributes($data['custom_attributes']);

$this->assertInstanceOf(\Magento\Catalog\Block\Product\Image::class, $this->model->create());
}
}

0 comments on commit 93a5c39

Please sign in to comment.