diff --git a/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverComposite.php b/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverComposite.php index 3c34438da55a4..365837089dce3 100644 --- a/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverComposite.php +++ b/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverComposite.php @@ -5,8 +5,10 @@ */ namespace Magento\Catalog\Model\Product\Configuration\Item; +use Magento\Catalog\Api\Data\ProductInterface; + /** - * Composite implementation for @see ItemResolverInterface + * {@inheritdoc} */ class ItemResolverComposite implements ItemResolverInterface { @@ -24,14 +26,14 @@ public function __construct(array $itemResolvers) /** * {@inheritdoc} */ - public function getFinalProduct( - \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - ) : \Magento\Catalog\Api\Data\ProductInterface { + public function getFinalProduct(ItemInterface $item) : ProductInterface + { $product = $item->getProduct(); foreach ($this->itemResolvers as $resolver) { $resolvedProduct = $resolver->getFinalProduct($item); if ($resolvedProduct !== $product) { - return $resolvedProduct; + $product = $resolvedProduct; + break; } } return $product; diff --git a/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverInterface.php b/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverInterface.php index 6d2d201ac2a3d..78859016c48b4 100644 --- a/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverInterface.php +++ b/app/code/Magento/Catalog/Model/Product/Configuration/Item/ItemResolverInterface.php @@ -5,19 +5,20 @@ */ namespace Magento\Catalog\Model\Product\Configuration\Item; +use Magento\Catalog\Api\Data\ProductInterface; + /** - * Resolves the product for a configured item + * Resolves the product from a configured item. * * @api */ interface ItemResolverInterface { /** - * Get the final product from a configured item by product type and selection + * Get the final product from a configured item by product type and selection. * * @param ItemInterface $item - * @return \Magento\Catalog\Api\Data\ProductInterface + * @return ProductInterface */ - public function getFinalProduct(\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item) - : \Magento\Catalog\Api\Data\ProductInterface; + public function getFinalProduct(ItemInterface $item) : ProductInterface; } diff --git a/app/code/Magento/Checkout/Model/Cart/ImageProvider.php b/app/code/Magento/Checkout/Model/Cart/ImageProvider.php index a75dbd6b5a505..61985e6e3b6ff 100644 --- a/app/code/Magento/Checkout/Model/Cart/ImageProvider.php +++ b/app/code/Magento/Checkout/Model/Cart/ImageProvider.php @@ -39,7 +39,7 @@ public function __construct( ) { $this->itemRepository = $itemRepository; $this->itemPool = $itemPool; - $this->customerDataItem = $customerDataItem ?? ObjectManager::getInstance()->get(DefaultItem::class); + $this->customerDataItem = $customerDataItem ?: ObjectManager::getInstance()->get(DefaultItem::class); } /** diff --git a/app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php b/app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php index 557228defc0dc..733f45ac827aa 100644 --- a/app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php @@ -57,7 +57,8 @@ public function getOptionList() /** * {@inheritdoc} - * @deprecated + * @deprecated because parent can handle the logic for images of all product types + * @see \Magento\Checkout\Block\Cart\Item\Renderer::getProductForThumbnail */ public function getProductForThumbnail() { diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Configuration/Item/ItemProductResolver.php b/app/code/Magento/ConfigurableProduct/Model/Product/Configuration/Item/ItemProductResolver.php index 135f57462761e..bfe35a1b4c4c6 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Configuration/Item/ItemProductResolver.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Configuration/Item/ItemProductResolver.php @@ -6,39 +6,40 @@ namespace Magento\ConfigurableProduct\Model\Product\Configuration\Item; use Magento\Catalog\Model\Config\Source\Product\Thumbnail; +use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface; +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Catalog\Model\Product; /** - * Resolves the product for a configured option item + * {@inheritdoc} */ -class ItemProductResolver implements \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface +class ItemProductResolver implements ItemResolverInterface { const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/configurable_product_image'; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ protected $scopeConfig; /** - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig */ - public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) + public function __construct(ScopeConfigInterface $scopeConfig) { $this->scopeConfig = $scopeConfig; } /** - * Identify the product from which thumbnail should be taken. - * - * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - * @return \Magento\Catalog\Api\Data\ProductInterface + * {@inheritdoc} */ - public function getFinalProduct( - \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - ) : \Magento\Catalog\Api\Data\ProductInterface { + 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 + * or if child thumbnail is not available. */ $parentItem = $item->getProduct(); $config = $this->scopeConfig->getValue( @@ -46,26 +47,28 @@ public function getFinalProduct( \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); - return $config == Thumbnail::OPTION_USE_PARENT_IMAGE - || (!$this->getChildProduct($item)->getData('thumbnail') - || $this->getChildProduct($item)->getData('thumbnail') == 'no_selection') - ? $parentItem - : $this->getChildProduct($item); + $childProduct = $this->getChildProduct($item); + $childThumbnail = $childProduct->getData('thumbnail'); + $finalProduct = + ($config == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumbnail || $childThumbnail == 'no_selection') + ? $parentItem + : $childProduct; + return $finalProduct; } /** * Get item configurable child product * - * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - * @return \Magento\Catalog\Model\Product + * @param ItemInterface $item + * @return Product */ - private function getChildProduct( - \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - ) : \Magento\Catalog\Model\Product { + private function getChildProduct(ItemInterface $item) : Product + { $option = $item->getOptionByCode('simple_product'); + $product = $item->getProduct(); if ($option) { - return $option->getProduct(); + $product = $option->getProduct(); } - return $item->getProduct(); + return $product; } } diff --git a/app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php b/app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php index 0340a78b45a39..a550e5cb2eed5 100644 --- a/app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php +++ b/app/code/Magento/GroupedProduct/Block/Cart/Item/Renderer/Grouped.php @@ -38,7 +38,8 @@ public function getGroupedProduct() /** * {@inheritdoc} - * @deprecated + * @deprecated because parent can handle the logic for images of all product types + * @see \Magento\Checkout\Block\Cart\Item\Renderer::getProductForThumbnail */ public function getProductForThumbnail() { diff --git a/app/code/Magento/GroupedProduct/Model/Product/Configuration/Item/ItemProductResolver.php b/app/code/Magento/GroupedProduct/Model/Product/Configuration/Item/ItemProductResolver.php index 825a62cc52275..09613a2f554bf 100644 --- a/app/code/Magento/GroupedProduct/Model/Product/Configuration/Item/ItemProductResolver.php +++ b/app/code/Magento/GroupedProduct/Model/Product/Configuration/Item/ItemProductResolver.php @@ -6,11 +6,16 @@ namespace Magento\GroupedProduct\Model\Product\Configuration\Item; use Magento\Catalog\Model\Config\Source\Product\Thumbnail; +use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface; /** - * Resolves the product for a configured option item + * {@inheritdoc} */ -class ItemProductResolver implements \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface +class ItemProductResolver implements ItemResolverInterface { /** * Path in config to the setting which defines if parent or child product should be used to generate a thumbnail. @@ -18,27 +23,23 @@ class ItemProductResolver implements \Magento\Catalog\Model\Product\Configuratio const CONFIG_THUMBNAIL_SOURCE = 'checkout/cart/grouped_product_image'; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ protected $scopeConfig; /** - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig */ - public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) + public function __construct(ScopeConfigInterface $scopeConfig) { $this->scopeConfig = $scopeConfig; } /** - * Identify the product from which thumbnail should be taken. - * - * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - * @return \Magento\Catalog\Api\Data\ProductInterface + * {@inheritdoc} */ - public function getFinalProduct( - \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - ) : \Magento\Catalog\Api\Data\ProductInterface { + 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 @@ -48,25 +49,28 @@ public function getFinalProduct( \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); $childProduct = $item->getProduct(); - return $config == Thumbnail::OPTION_USE_PARENT_IMAGE || - (!$childProduct->getData('thumbnail') || $childProduct->getData('thumbnail') == 'no_selection') + $childThumbnail = $childProduct->getData('thumbnail'); + + $finalProduct = + ($config == Thumbnail::OPTION_USE_PARENT_IMAGE) || (!$childThumbnail || $childThumbnail == 'no_selection') ? $this->getParentProduct($item) : $childProduct; + return $finalProduct; } /** * Get grouped product * - * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - * @return \Magento\Catalog\Model\Product + * @param ItemInterface $item + * @return Product */ - private function getParentProduct( - \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item - ) : \Magento\Catalog\Model\Product { + private function getParentProduct(ItemInterface $item) : Product + { $option = $item->getOptionByCode('product_type'); + $product = $item->getProduct(); if ($option) { - return $option->getProduct(); + $product = $option->getProduct(); } - return $item->getProduct(); + return $product; } } diff --git a/app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php b/app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php index bd055937b9719..b8728dd33f4c8 100644 --- a/app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php +++ b/app/code/Magento/Wishlist/Block/Customer/Wishlist/Item/Column/Image.php @@ -41,7 +41,7 @@ public function __construct( UrlBuilder $urlBuilder = null, ItemResolverInterface $itemResolver = null ) { - $this->itemResolver = $itemResolver ?? ObjectManager::getInstance()->get(ItemResolverInterface::class); + $this->itemResolver = $itemResolver ?: ObjectManager::getInstance()->get(ItemResolverInterface::class); parent::__construct( $context, $httpContext, diff --git a/app/code/Magento/Wishlist/CustomerData/Wishlist.php b/app/code/Magento/Wishlist/CustomerData/Wishlist.php index e721fbf9a9029..9cfc55bae723e 100644 --- a/app/code/Magento/Wishlist/CustomerData/Wishlist.php +++ b/app/code/Magento/Wishlist/CustomerData/Wishlist.php @@ -62,7 +62,7 @@ public function __construct( $this->imageHelperFactory = $imageHelperFactory; $this->block = $block; $this->view = $view; - $this->itemResolver = $itemResolver ?? ObjectManager::getInstance()->get( + $this->itemResolver = $itemResolver ?: ObjectManager::getInstance()->get( \Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface::class ); }