Skip to content

Commit

Permalink
MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist…
Browse files Browse the repository at this point in the history
… if options are selected for configurable product #8168

- fixing formatting
  • Loading branch information
cpartica committed Jul 17, 2018
1 parent 31f089f commit c2c8ef9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class ItemResolverComposite implements ItemResolverInterface
/** @var string[] */
private $itemResolvers = [];

/** @var ItemResolverInterface[] */
private $itemResolversInstances = [];

/**
* @param string[] $itemResolvers
*/
Expand All @@ -43,13 +46,16 @@ public function getFinalProduct(ItemInterface $item) : ProductInterface
}

/**
* Get the instance of the item resolver by class name
* Get the instance of the item resolver by class name.
*
* @param string $className
* @return ItemResolverInterface
*/
private function getItemResolverInstance(string $className)
{
return ObjectManager::getInstance()->get($className);
if (!isset($this->itemResolversInstances[$className])) {
$this->itemResolversInstances[$className] = ObjectManager::getInstance()->get($className);
}
return $this->itemResolversInstances[$className];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function setUp()
->getMock();
$context->expects($this->once())
->method('getLayout')
->will($this->returnValue($this->layout));
->willReturn($this->layout);

$this->imageBuilder = $this->getMockBuilder(\Magento\Catalog\Block\Product\ImageBuilder::class)
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ public function getFinalProduct(ItemInterface $item) : ProductInterface
* Show parent product thumbnail if it must be always shown according to the related setting in system config
* or if child thumbnail is not available.
*/
$parentItem = $item->getProduct();
$config = $this->scopeConfig->getValue(
$parentProduct = $item->getProduct();
$configValue = $this->scopeConfig->getValue(
self::CONFIG_THUMBNAIL_SOURCE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

$childProduct = $this->getChildProduct($item);
$childThumbnail = $childProduct->getData('thumbnail');
$childThumb = $childProduct->getData('thumbnail');
$finalProduct =
($config == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumbnail || $childThumbnail == 'no_selection')
? $parentItem
($configValue == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumb || $childThumb == 'no_selection')
? $parentProduct
: $childProduct;
return $finalProduct;
}

/**
* Get item configurable child product
* Get item configurable child product.
*
* @param ItemInterface $item
* @return Product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ public function getFinalProduct(ItemInterface $item) : ProductInterface
{
/**
* Show grouped product thumbnail if it must be always shown according to the related setting in system config
* or if child product thumbnail is not available
* or if child product thumbnail is not available.
*/
$config = $this->scopeConfig->getValue(
$configValue = $this->scopeConfig->getValue(
self::CONFIG_THUMBNAIL_SOURCE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$childProduct = $item->getProduct();
$childThumbnail = $childProduct->getData('thumbnail');
$childThumb = $childProduct->getData('thumbnail');

$finalProduct =
($config == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumbnail || $childThumbnail == 'no_selection')
($configValue == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumb || $childThumb == 'no_selection')
? $this->getParentProduct($item)
: $childProduct;
return $finalProduct;
}

/**
* Get grouped product
* Get grouped product.
*
* @param ItemInterface $item
* @return Product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

/**
* Wishlist block customer item cart column
*/
namespace Magento\Wishlist\Block\Customer\Wishlist\Item\Column;

use Magento\Catalog\Model\Product\Image\UrlBuilder;
Expand All @@ -15,6 +13,8 @@
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;

/**
* Wishlist block customer item cart column
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -54,7 +54,7 @@ public function __construct(
*
* @return \Magento\Catalog\Model\Product
*/
public function getProductForThumbnail(\Magento\Wishlist\Model\Item $item)
public function getProductForThumbnail(\Magento\Wishlist\Model\Item $item) : \Magento\Catalog\Model\Product
{
return $this->itemResolver->getFinalProduct($item);
}
Expand Down

0 comments on commit c2c8ef9

Please sign in to comment.