Skip to content

Commit 838182a

Browse files
committed
MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist if options are selected for configurable product #8168
- fixing formatting
1 parent e1ffa88 commit 838182a

File tree

9 files changed

+73
-61
lines changed

9 files changed

+73
-61
lines changed

app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverComposite.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
*/
66
namespace Magento\Catalog\Model\Product\Configuration\Item;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
810
/**
9-
* Composite implementation for @see ItemResolverInterface
11+
* {@inheritdoc}
1012
*/
1113
class ItemResolverComposite implements ItemResolverInterface
1214
{
@@ -24,14 +26,14 @@ public function __construct(array $itemResolvers)
2426
/**
2527
* {@inheritdoc}
2628
*/
27-
public function getFinalProduct(
28-
\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
29-
) : \Magento\Catalog\Api\Data\ProductInterface {
29+
public function getFinalProduct(ItemInterface $item) : ProductInterface
30+
{
3031
$product = $item->getProduct();
3132
foreach ($this->itemResolvers as $resolver) {
3233
$resolvedProduct = $resolver->getFinalProduct($item);
3334
if ($resolvedProduct !== $product) {
34-
return $resolvedProduct;
35+
$product = $resolvedProduct;
36+
break;
3537
}
3638
}
3739
return $product;

app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverInterface.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
*/
66
namespace Magento\Catalog\Model\Product\Configuration\Item;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
810
/**
9-
* Resolves the product for a configured item
11+
* Resolves the product from a configured item.
1012
*
1113
* @api
1214
*/
1315
interface ItemResolverInterface
1416
{
1517
/**
16-
* Get the final product from a configured item by product type and selection
18+
* Get the final product from a configured item by product type and selection.
1719
*
1820
* @param ItemInterface $item
19-
* @return \Magento\Catalog\Api\Data\ProductInterface
21+
* @return ProductInterface
2022
*/
21-
public function getFinalProduct(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item)
22-
: \Magento\Catalog\Api\Data\ProductInterface;
23+
public function getFinalProduct(ItemInterface $item) : ProductInterface;
2324
}

app/code/Magento/Checkout/Model/Cart/ImageProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939
) {
4040
$this->itemRepository = $itemRepository;
4141
$this->itemPool = $itemPool;
42-
$this->customerDataItem = $customerDataItem ?? ObjectManager::getInstance()->get(DefaultItem::class);
42+
$this->customerDataItem = $customerDataItem ?: ObjectManager::getInstance()->get(DefaultItem::class);
4343
}
4444

4545
/**

app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function getOptionList()
5757

5858
/**
5959
* {@inheritdoc}
60-
* @deprecated
60+
* @deprecated because parent can handle the logic for images of all product types
61+
* @see \Magento\Checkout\Block\Cart\Item\Renderer::getProductForThumbnail
6162
*/
6263
public function getProductForThumbnail()
6364
{

app/code/Magento/ConfigurableProduct/Model/Product/Configuration/Item/ItemProductResolver.php

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,69 @@
66
namespace Magento\ConfigurableProduct\Model\Product\Configuration\Item;
77

88
use Magento\Catalog\Model\Config\Source\Product\Thumbnail;
9+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Catalog\Model\Product;
914

1015
/**
11-
* Resolves the product for a configured option item
16+
* {@inheritdoc}
1217
*/
13-
class ItemProductResolver implements \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface
18+
class ItemProductResolver implements ItemResolverInterface
1419
{
1520
const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/configurable_product_image';
1621

1722
/**
18-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
23+
* @var ScopeConfigInterface
1924
*/
2025
protected $scopeConfig;
2126

2227
/**
23-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
28+
* @param ScopeConfigInterface $scopeConfig
2429
*/
25-
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
30+
public function __construct(ScopeConfigInterface $scopeConfig)
2631
{
2732
$this->scopeConfig = $scopeConfig;
2833
}
2934

3035
/**
31-
* Identify the product from which thumbnail should be taken.
32-
*
33-
* @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
34-
* @return \Magento\Catalog\Api\Data\ProductInterface
36+
* {@inheritdoc}
3537
*/
36-
public function getFinalProduct(
37-
\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
38-
) : \Magento\Catalog\Api\Data\ProductInterface {
38+
public function getFinalProduct(ItemInterface $item) : ProductInterface
39+
{
3940
/**
4041
* Show parent product thumbnail if it must be always shown according to the related setting in system config
41-
* or if child thumbnail is not available
42+
* or if child thumbnail is not available.
4243
*/
4344
$parentItem = $item->getProduct();
4445
$config = $this->scopeConfig->getValue(
4546
\Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable::CONFIG_THUMBNAIL_SOURCE,
4647
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
4748
);
4849

49-
return $config == Thumbnail::OPTION_USE_PARENT_IMAGE
50-
|| (!$this->getChildProduct($item)->getData('thumbnail')
51-
|| $this->getChildProduct($item)->getData('thumbnail') == 'no_selection')
52-
? $parentItem
53-
: $this->getChildProduct($item);
50+
$childProduct = $this->getChildProduct($item);
51+
$childThumbnail = $childProduct->getData('thumbnail');
52+
$finalProduct =
53+
($config == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumbnail || $childThumbnail == 'no_selection')
54+
? $parentItem
55+
: $childProduct;
56+
return $finalProduct;
5457
}
5558

5659
/**
5760
* Get item configurable child product
5861
*
59-
* @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
60-
* @return \Magento\Catalog\Model\Product
62+
* @param ItemInterface $item
63+
* @return Product
6164
*/
62-
private function getChildProduct(
63-
\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
64-
) : \Magento\Catalog\Model\Product {
65+
private function getChildProduct(ItemInterface $item) : Product
66+
{
6567
$option = $item->getOptionByCode('simple_product');
68+
$product = $item->getProduct();
6669
if ($option) {
67-
return $option->getProduct();
70+
$product = $option->getProduct();
6871
}
69-
return $item->getProduct();
72+
return $product;
7073
}
7174
}

app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public function getGroupedProduct()
3838

3939
/**
4040
* {@inheritdoc}
41-
* @deprecated
41+
* @deprecated because parent can handle the logic for images of all product types
42+
* @see \Magento\Checkout\Block\Cart\Item\Renderer::getProductForThumbnail
4243
*/
4344
public function getProductForThumbnail()
4445
{

app/code/Magento/GroupedProduct/Model/Product/Configuration/Item/ItemProductResolver.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,40 @@
66
namespace Magento\GroupedProduct\Model\Product\Configuration\Item;
77

88
use Magento\Catalog\Model\Config\Source\Product\Thumbnail;
9+
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;
914

1015
/**
11-
* Resolves the product for a configured option item
16+
* {@inheritdoc}
1217
*/
13-
class ItemProductResolver implements \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface
18+
class ItemProductResolver implements ItemResolverInterface
1419
{
1520
/**
1621
* Path in config to the setting which defines if parent or child product should be used to generate a thumbnail.
1722
*/
1823
const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/grouped_product_image';
1924

2025
/**
21-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
26+
* @var ScopeConfigInterface
2227
*/
2328
protected $scopeConfig;
2429

2530
/**
26-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
31+
* @param ScopeConfigInterface $scopeConfig
2732
*/
28-
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
33+
public function __construct(ScopeConfigInterface $scopeConfig)
2934
{
3035
$this->scopeConfig = $scopeConfig;
3136
}
3237

3338
/**
34-
* Identify the product from which thumbnail should be taken.
35-
*
36-
* @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
37-
* @return \Magento\Catalog\Api\Data\ProductInterface
39+
* {@inheritdoc}
3840
*/
39-
public function getFinalProduct(
40-
\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
41-
) : \Magento\Catalog\Api\Data\ProductInterface {
41+
public function getFinalProduct(ItemInterface $item) : ProductInterface
42+
{
4243
/**
4344
* Show grouped product thumbnail if it must be always shown according to the related setting in system config
4445
* or if child product thumbnail is not available
@@ -48,25 +49,28 @@ public function getFinalProduct(
4849
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
4950
);
5051
$childProduct = $item->getProduct();
51-
return $config == Thumbnail::OPTION_USE_PARENT_IMAGE ||
52-
(!$childProduct->getData('thumbnail') || $childProduct->getData('thumbnail') == 'no_selection')
52+
$childThumbnail = $childProduct->getData('thumbnail');
53+
54+
$finalProduct =
55+
($config == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumbnail || $childThumbnail == 'no_selection')
5356
? $this->getParentProduct($item)
5457
: $childProduct;
58+
return $finalProduct;
5559
}
5660

5761
/**
5862
* Get grouped product
5963
*
60-
* @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
61-
* @return \Magento\Catalog\Model\Product
64+
* @param ItemInterface $item
65+
* @return Product
6266
*/
63-
private function getParentProduct(
64-
\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item
65-
) : \Magento\Catalog\Model\Product {
67+
private function getParentProduct(ItemInterface $item) : Product
68+
{
6669
$option = $item->getOptionByCode('product_type');
70+
$product = $item->getProduct();
6771
if ($option) {
68-
return $option->getProduct();
72+
$product = $option->getProduct();
6973
}
70-
return $item->getProduct();
74+
return $product;
7175
}
7276
}

app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
UrlBuilder $urlBuilder = null,
4242
ItemResolverInterface $itemResolver = null
4343
) {
44-
$this->itemResolver = $itemResolver ?? ObjectManager::getInstance()->get(ItemResolverInterface::class);
44+
$this->itemResolver = $itemResolver ?: ObjectManager::getInstance()->get(ItemResolverInterface::class);
4545
parent::__construct(
4646
$context,
4747
$httpContext,

app/code/Magento/Wishlist/CustomerData/Wishlist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct(
6262
$this->imageHelperFactory = $imageHelperFactory;
6363
$this->block = $block;
6464
$this->view = $view;
65-
$this->itemResolver = $itemResolver ?? ObjectManager::getInstance()->get(
65+
$this->itemResolver = $itemResolver ?: ObjectManager::getInstance()->get(
6666
\Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface::class
6767
);
6868
}

0 commit comments

Comments
 (0)