Skip to content

Commit

Permalink
Merge pull request #2219 from magento-tango/2.2-PR-part-3
Browse files Browse the repository at this point in the history
Fixed issues:
  - MAGETWO-77754 [2.2.x] - Related Products Rule for Up-sell Products with Customer Segments Specified Doesn't Work
  - MAGETWO-87570 [2.2.x] "Hide from Product Page" option does not work for child of configurable product
  • Loading branch information
igrybkov authored Mar 16, 2018
2 parents 178fa2b + 9198f74 commit cb0954a
Show file tree
Hide file tree
Showing 14 changed files with 416 additions and 271 deletions.
12 changes: 5 additions & 7 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,17 +1062,13 @@ protected function _afterLoad()
/**
* Clear cache related with product id
*
* @deprecated
* @see \Magento\Framework\Model\AbstractModel::cleanModelCache
* @return $this
*/
public function cleanCache()
{
if ($this->getId()) {
$this->_cacheManager->clean(
self::CACHE_TAG . '_' . $this->getId()
);
}

return $this;
return $this->cleanModelCache();
}

/**
Expand Down Expand Up @@ -2101,6 +2097,8 @@ public function reset()
/**
* Get cache tags associated with object id
*
* @deprecated
* @see \Magento\Catalog\Model\Product::getIdentities
* @return string[]
*/
public function getCacheIdTags()
Expand Down
23 changes: 0 additions & 23 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1452,29 +1452,6 @@ public function testGetOptionByIdForProductWithoutOptions()
$this->assertNull($this->model->getOptionById(100));
}

/**
* @dataProvider cleanCacheDataProvider
*/
public function testCleanCache($id, $method)
{
$this->model->setId($id);
$this->cacheInterfaceMock
->expects($this->$method())
->method('clean');
$this->model->cleanCache();
}

/**
* @return array
*/
public function cleanCacheDataProvider()
{
return [
[null, 'never'],
['1', 'once'],
];
}

public function testGetCacheTags()
{
//If entity is identified getCacheTags has to return the same values
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Model\Plugin;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;

/**
* Extender of product identities for child of configurable products
*/
class ProductIdentitiesExtender
{
/**
* @var Configurable
*/
private $configurableType;

/**
* @var ProductRepositoryInterface
*/
private $productRepository;

/**
* @param Configurable $configurableType
* @param ProductRepositoryInterface $productRepository
*/
public function __construct(Configurable $configurableType, ProductRepositoryInterface $productRepository)
{
$this->configurableType = $configurableType;
$this->productRepository = $productRepository;
}

/**
* Add parent identities to product identities
*
* @param Product $subject
* @param array $identities
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetIdentities(Product $subject, array $identities): array
{
$identities = (array) $identities;

foreach ($this->configurableType->getParentIdsByChild($subject->getId()) as $parentId) {
$parentProduct = $this->productRepository->getById($parentId);
$identities = array_merge($identities, (array) $parentProduct->getIdentities());
}

return array_unique($identities);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public function getChildrenIds($parentId, $required = true)
*/
public function getParentIdsByChild($childId)
{
$parentIds = [];
$select = $this->getConnection()
->select()
->from(['l' => $this->getMainTable()], [])
Expand All @@ -198,10 +197,7 @@ public function getParentIdsByChild($childId)
'e.' . $this->optionProvider->getProductEntityLinkField() . ' = l.parent_id',
['e.entity_id']
)->where('l.product_id IN(?)', $childId);

foreach ($this->getConnection()->fetchAll($select) as $row) {
$parentIds[] = $row['entity_id'];
}
$parentIds = $this->getConnection()->fetchCol($select);

return $parentIds;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ConfigurableProduct\Test\Unit\Model\Plugin;

use Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;

/**
* Class ProductIdentitiesExtenderTest
*/
class ProductIdentitiesExtenderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|Configurable
*/
private $configurableTypeMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ProductRepositoryInterface
*/
private $productRepositoryMock;

/**
* @var ProductIdentitiesExtender
*/
private $plugin;

protected function setUp()
{
$this->configurableTypeMock = $this->getMockBuilder(Configurable::class)
->disableOriginalConstructor()
->getMock();
$this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)
->getMock();

$this->plugin = new ProductIdentitiesExtender($this->configurableTypeMock, $this->productRepositoryMock);
}

public function testAfterGetIdentities()
{
$productId = 1;
$productIdentity = 'cache_tag_1';
$productMock = $this->getMockBuilder(Product::class)
->disableOriginalConstructor()
->getMock();
$parentProductId = 2;
$parentProductIdentity = 'cache_tag_2';
$parentProductMock = $this->getMockBuilder(Product::class)
->disableOriginalConstructor()
->getMock();

$productMock->expects($this->once())
->method('getId')
->willReturn($productId);
$this->configurableTypeMock->expects($this->once())
->method('getParentIdsByChild')
->with($productId)
->willReturn([$parentProductId]);
$this->productRepositoryMock->expects($this->once())
->method('getById')
->with($parentProductId)
->willReturn($parentProductMock);
$parentProductMock->expects($this->once())
->method('getIdentities')
->willReturn([$parentProductIdentity]);

$productIdentities = $this->plugin->afterGetIdentities($productMock, [$productIdentity]);
$this->assertEquals([$productIdentity, $parentProductIdentity], $productIdentities);
}
}

This file was deleted.

10 changes: 3 additions & 7 deletions app/code/Magento/ConfigurableProduct/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\App\Cache\Tag\Strategy\Factory">
<arguments>
<argument name="customStrategies" xsi:type="array">
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="object">\Magento\ConfigurableProduct\Model\Product\Cache\Tag\Configurable</item>
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator">
<arguments>
<argument name="estimators" xsi:type="array">
Expand Down Expand Up @@ -209,4 +202,7 @@
<type name="Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver">
<plugin name="configurable" type="Magento\ConfigurableProduct\Plugin\Catalog\Model\Product\Pricing\Renderer\SalableResolver" />
</type>
<type name="Magento\Catalog\Model\Product">
<plugin name="product_identities_extender" type="Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender" />
</type>
</config>
Loading

0 comments on commit cb0954a

Please sign in to comment.