Skip to content

Commit

Permalink
Merge pull request #2816 from magento-honey-badgers/MAGETWO-8709
Browse files Browse the repository at this point in the history
[honey] MAGETWO-8709: [GITHUB] Child product image should be shown in Wishist if options are selected for configurable product #8168
  • Loading branch information
cpartica authored Jul 20, 2018
2 parents 244a2e9 + 30f6c2b commit 2b76b97
Show file tree
Hide file tree
Showing 33 changed files with 569 additions and 535 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Product\Configuration\Item;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\App\ObjectManager;

/**
* {@inheritdoc}
*/
class ItemResolverComposite implements ItemResolverInterface
{
/** @var string[] */
private $itemResolvers = [];

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

/**
* @param string[] $itemResolvers
*/
public function __construct(array $itemResolvers)
{
$this->itemResolvers = $itemResolvers;
}

/**
* {@inheritdoc}
*/
public function getFinalProduct(ItemInterface $item) : ProductInterface
{
$finalProduct = $item->getProduct();
foreach ($this->itemResolvers as $resolver) {
$resolvedProduct = $this->getItemResolverInstance($resolver)->getFinalProduct($item);
if ($resolvedProduct !== $finalProduct) {
$finalProduct = $resolvedProduct;
break;
}
}
return $finalProduct;
}

/**
* Get the instance of the item resolver by class name.
*
* @param string $className
* @return ItemResolverInterface
*/
private function getItemResolverInstance(string $className) : ItemResolverInterface
{
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
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Product\Configuration\Item;

use Magento\Catalog\Api\Data\ProductInterface;

/**
* Resolves the product from a configured item.
*
* @api
*/
interface ItemResolverInterface
{
/**
* Get the final product from a configured item by product type and selection.
*
* @param ItemInterface $item
* @return ProductInterface
*/
public function getFinalProduct(ItemInterface $item) : ProductInterface;
}
9 changes: 9 additions & 0 deletions app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@
<data key="filename">magento-logo</data>
<data key="file_extension">png</data>
</entity>
<entity name="TestImageNew" type="image">
<data key="title" unique="suffix">magento-again</data>
<data key="price">1.00</data>
<data key="file_type">Upload File</data>
<data key="shareable">Yes</data>
<data key="file">magento-again.jpg</data>
<data key="filename">magento-again</data>
<data key="file_extension">jpg</data>
</entity>
<entity name="ProductWithUnicode" type="product">
<data key="sku" unique="suffix">&#38657;&#20135;&#21697;</data>
<data key="type_id">simple</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
<element name="firstRow" type="button" selector="tr.data-row:nth-of-type(1)"/>
<element name="productGridCheckboxOnRow" type="checkbox" selector="//*[@id='container']//tr[{{row}}]/td[1]//input" parameterized="true"/>
<element name="productGridNameProduct" type="input" selector="//tbody//tr//td//div[contains(., '{{var1}}')]" parameterized="true" timeout="30"/>
<element name="selectRowBasedOnName" type="input" selector="//td/div[text()='{{var1}}']" parameterized="true"/>
</section>
</sections>
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
<preference for="Magento\Catalog\Api\Data\ProductRender\FormattedPriceInfoInterface" type="Magento\Catalog\Model\ProductRender\FormattedPriceInfo" />
<preference for="Magento\Framework\Indexer\BatchProviderInterface" type="Magento\Framework\Indexer\BatchProvider" />
<preference for="Magento\Catalog\Model\Indexer\Product\Price\UpdateIndexInterface" type="Magento\Catalog\Model\Indexer\Product\Price\InvalidateIndex" />
<preference for="\Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface" type="\Magento\Catalog\Model\Product\Gallery\ImagesConfigFactory" />
<preference for="Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface" type="Magento\Catalog\Model\Product\Gallery\ImagesConfigFactory" />
<preference for="Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface" type="Magento\Catalog\Model\Product\Configuration\Item\ItemResolverComposite" />
<type name="Magento\Customer\Model\ResourceModel\Visitor">
<plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
</type>
Expand Down
13 changes: 11 additions & 2 deletions app/code/Magento/Checkout/Block/Cart/Item/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
use Magento\Quote\Model\Quote\Item\AbstractItem;
use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;

/**
* Shopping cart item render block
Expand All @@ -21,6 +23,7 @@
* @method \Magento\Checkout\Block\Cart\Item\Renderer setProductName(string)
* @method \Magento\Checkout\Block\Cart\Item\Renderer setDeleteUrl(string)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Renderer extends \Magento\Framework\View\Element\Template implements
\Magento\Framework\DataObject\IdentityInterface
Expand Down Expand Up @@ -91,6 +94,9 @@ class Renderer extends \Magento\Framework\View\Element\Template implements
*/
private $messageInterpretationStrategy;

/** @var ItemResolverInterface */
private $itemResolver;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Catalog\Helper\Product\Configuration $productConfig
Expand All @@ -102,6 +108,7 @@ class Renderer extends \Magento\Framework\View\Element\Template implements
* @param \Magento\Framework\Module\Manager $moduleManager
* @param InterpretationStrategyInterface $messageInterpretationStrategy
* @param array $data
* @param ItemResolverInterface|null $itemResolver
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @codeCoverageIgnore
*/
Expand All @@ -115,7 +122,8 @@ public function __construct(
PriceCurrencyInterface $priceCurrency,
\Magento\Framework\Module\Manager $moduleManager,
InterpretationStrategyInterface $messageInterpretationStrategy,
array $data = []
array $data = [],
ItemResolverInterface $itemResolver = null
) {
$this->priceCurrency = $priceCurrency;
$this->imageBuilder = $imageBuilder;
Expand All @@ -127,6 +135,7 @@ public function __construct(
$this->_isScopePrivate = true;
$this->moduleManager = $moduleManager;
$this->messageInterpretationStrategy = $messageInterpretationStrategy;
$this->itemResolver = $itemResolver ?: ObjectManager::getInstance()->get(ItemResolverInterface::class);
}

/**
Expand Down Expand Up @@ -172,7 +181,7 @@ public function getProduct()
*/
public function getProductForThumbnail()
{
return $this->getProduct();
return $this->itemResolver->getFinalProduct($this->getItem());
}

/**
Expand Down
15 changes: 11 additions & 4 deletions app/code/Magento/Checkout/CustomerData/DefaultItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\Checkout\CustomerData;

use Magento\Framework\App\ObjectManager;
use Magento\Catalog\Model\Product\Configuration\Item\ItemResolverInterface;

/**
* Default item
Expand Down Expand Up @@ -39,19 +40,23 @@ class DefaultItem extends AbstractItem
protected $checkoutHelper;

/**
* Escaper
*
* @var \Magento\Framework\Escaper
*/
private $escaper;

/**
* @var ItemResolverInterface
*/
private $itemResolver;

/**
* @param \Magento\Catalog\Helper\Image $imageHelper
* @param \Magento\Msrp\Helper\Data $msrpHelper
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Catalog\Helper\Product\ConfigurationPool $configurationPool
* @param \Magento\Checkout\Helper\Data $checkoutHelper
* @param \Magento\Framework\Escaper|null $escaper
* @param ItemResolverInterface|null $itemResolver
* @codeCoverageIgnore
*/
public function __construct(
Expand All @@ -60,14 +65,16 @@ public function __construct(
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Catalog\Helper\Product\ConfigurationPool $configurationPool,
\Magento\Checkout\Helper\Data $checkoutHelper,
\Magento\Framework\Escaper $escaper = null
\Magento\Framework\Escaper $escaper = null,
ItemResolverInterface $itemResolver = null
) {
$this->configurationPool = $configurationPool;
$this->imageHelper = $imageHelper;
$this->msrpHelper = $msrpHelper;
$this->urlBuilder = $urlBuilder;
$this->checkoutHelper = $checkoutHelper;
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(\Magento\Framework\Escaper::class);
$this->itemResolver = $itemResolver ?: ObjectManager::getInstance()->get(ItemResolverInterface::class);
}

/**
Expand Down Expand Up @@ -119,7 +126,7 @@ protected function getOptionList()
*/
protected function getProductForThumbnail()
{
return $this->getProduct();
return $this->itemResolver->getFinalProduct($this->item);
}

/**
Expand Down
17 changes: 13 additions & 4 deletions app/code/Magento/Checkout/Model/Cart/ImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/
namespace Magento\Checkout\Model\Cart;

use Magento\Checkout\CustomerData\DefaultItem;
use Magento\Framework\App\ObjectManager;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @api
*/
class ImageProvider
Expand All @@ -18,20 +20,27 @@ class ImageProvider

/**
* @var \Magento\Checkout\CustomerData\ItemPoolInterface
* @deprecated No need for the pool as images are resolved in the default item implementation
* @see \Magento\Checkout\CustomerData\DefaultItem::getProductForThumbnail
*/
protected $itemPool;

/** @var \Magento\Checkout\CustomerData\DefaultItem */
protected $customerDataItem;

/**
* @param \Magento\Quote\Api\CartItemRepositoryInterface $itemRepository
* @param \Magento\Checkout\CustomerData\ItemPoolInterface $itemPool
* @codeCoverageIgnore
* @param DefaultItem|null $customerDataItem
*/
public function __construct(
\Magento\Quote\Api\CartItemRepositoryInterface $itemRepository,
\Magento\Checkout\CustomerData\ItemPoolInterface $itemPool
\Magento\Checkout\CustomerData\ItemPoolInterface $itemPool,
\Magento\Checkout\CustomerData\DefaultItem $customerDataItem = null
) {
$this->itemRepository = $itemRepository;
$this->itemPool = $itemPool;
$this->customerDataItem = $customerDataItem ?: ObjectManager::getInstance()->get(DefaultItem::class);
}

/**
Expand All @@ -45,7 +54,7 @@ public function getImages($cartId)
$items = $this->itemRepository->getList($cartId);
/** @var \Magento\Quote\Model\Quote\Item $cartItem */
foreach ($items as $cartItem) {
$allData = $this->itemPool->getItemData($cartItem);
$allData = $this->customerDataItem->getItemData($cartItem);
$itemData[$cartItem->getItemId()] = $allData['product_image'];
}
return $itemData;
Expand Down
Loading

0 comments on commit 2b76b97

Please sign in to comment.