Skip to content

Commit b1df309

Browse files
[EngCom] Public Pull Requests - 2.2-develop
- merged latest code from mainline branch
2 parents d78f8d2 + cb0954a commit b1df309

File tree

14 files changed

+416
-271
lines changed

14 files changed

+416
-271
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,17 +1062,13 @@ protected function _afterLoad()
10621062
/**
10631063
* Clear cache related with product id
10641064
*
1065+
* @deprecated
1066+
* @see \Magento\Framework\Model\AbstractModel::cleanModelCache
10651067
* @return $this
10661068
*/
10671069
public function cleanCache()
10681070
{
1069-
if ($this->getId()) {
1070-
$this->_cacheManager->clean(
1071-
self::CACHE_TAG . '_' . $this->getId()
1072-
);
1073-
}
1074-
1075-
return $this;
1071+
return $this->cleanModelCache();
10761072
}
10771073

10781074
/**
@@ -2101,6 +2097,8 @@ public function reset()
21012097
/**
21022098
* Get cache tags associated with object id
21032099
*
2100+
* @deprecated
2101+
* @see \Magento\Catalog\Model\Product::getIdentities
21042102
* @return string[]
21052103
*/
21062104
public function getCacheIdTags()

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,29 +1452,6 @@ public function testGetOptionByIdForProductWithoutOptions()
14521452
$this->assertNull($this->model->getOptionById(100));
14531453
}
14541454

1455-
/**
1456-
* @dataProvider cleanCacheDataProvider
1457-
*/
1458-
public function testCleanCache($id, $method)
1459-
{
1460-
$this->model->setId($id);
1461-
$this->cacheInterfaceMock
1462-
->expects($this->$method())
1463-
->method('clean');
1464-
$this->model->cleanCache();
1465-
}
1466-
1467-
/**
1468-
* @return array
1469-
*/
1470-
public function cleanCacheDataProvider()
1471-
{
1472-
return [
1473-
[null, 'never'],
1474-
['1', 'once'],
1475-
];
1476-
}
1477-
14781455
public function testGetCacheTags()
14791456
{
14801457
//If entity is identified getCacheTags has to return the same values
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ConfigurableProduct\Model\Plugin;
9+
10+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Model\Product;
13+
14+
/**
15+
* Extender of product identities for child of configurable products
16+
*/
17+
class ProductIdentitiesExtender
18+
{
19+
/**
20+
* @var Configurable
21+
*/
22+
private $configurableType;
23+
24+
/**
25+
* @var ProductRepositoryInterface
26+
*/
27+
private $productRepository;
28+
29+
/**
30+
* @param Configurable $configurableType
31+
* @param ProductRepositoryInterface $productRepository
32+
*/
33+
public function __construct(Configurable $configurableType, ProductRepositoryInterface $productRepository)
34+
{
35+
$this->configurableType = $configurableType;
36+
$this->productRepository = $productRepository;
37+
}
38+
39+
/**
40+
* Add parent identities to product identities
41+
*
42+
* @param Product $subject
43+
* @param array $identities
44+
* @return array
45+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
46+
*/
47+
public function afterGetIdentities(Product $subject, array $identities): array
48+
{
49+
$identities = (array) $identities;
50+
51+
foreach ($this->configurableType->getParentIdsByChild($subject->getId()) as $parentId) {
52+
$parentProduct = $this->productRepository->getById($parentId);
53+
$identities = array_merge($identities, (array) $parentProduct->getIdentities());
54+
}
55+
56+
return array_unique($identities);
57+
}
58+
}

app/code/Magento/ConfigurableProduct/Model/Product/Cache/Tag/Configurable.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ public function getChildrenIds($parentId, $required = true)
189189
*/
190190
public function getParentIdsByChild($childId)
191191
{
192-
$parentIds = [];
193192
$select = $this->getConnection()
194193
->select()
195194
->from(['l' => $this->getMainTable()], [])
@@ -198,10 +197,7 @@ public function getParentIdsByChild($childId)
198197
'e.' . $this->optionProvider->getProductEntityLinkField() . ' = l.parent_id',
199198
['e.entity_id']
200199
)->where('l.product_id IN(?)', $childId);
201-
202-
foreach ($this->getConnection()->fetchAll($select) as $row) {
203-
$parentIds[] = $row['entity_id'];
204-
}
200+
$parentIds = $this->getConnection()->fetchCol($select);
205201

206202
return $parentIds;
207203
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ConfigurableProduct\Test\Unit\Model\Plugin;
9+
10+
use Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender;
11+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
12+
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Catalog\Model\Product;
14+
15+
/**
16+
* Class ProductIdentitiesExtenderTest
17+
*/
18+
class ProductIdentitiesExtenderTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject|Configurable
22+
*/
23+
private $configurableTypeMock;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject|ProductRepositoryInterface
27+
*/
28+
private $productRepositoryMock;
29+
30+
/**
31+
* @var ProductIdentitiesExtender
32+
*/
33+
private $plugin;
34+
35+
protected function setUp()
36+
{
37+
$this->configurableTypeMock = $this->getMockBuilder(Configurable::class)
38+
->disableOriginalConstructor()
39+
->getMock();
40+
$this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)
41+
->getMock();
42+
43+
$this->plugin = new ProductIdentitiesExtender($this->configurableTypeMock, $this->productRepositoryMock);
44+
}
45+
46+
public function testAfterGetIdentities()
47+
{
48+
$productId = 1;
49+
$productIdentity = 'cache_tag_1';
50+
$productMock = $this->getMockBuilder(Product::class)
51+
->disableOriginalConstructor()
52+
->getMock();
53+
$parentProductId = 2;
54+
$parentProductIdentity = 'cache_tag_2';
55+
$parentProductMock = $this->getMockBuilder(Product::class)
56+
->disableOriginalConstructor()
57+
->getMock();
58+
59+
$productMock->expects($this->once())
60+
->method('getId')
61+
->willReturn($productId);
62+
$this->configurableTypeMock->expects($this->once())
63+
->method('getParentIdsByChild')
64+
->with($productId)
65+
->willReturn([$parentProductId]);
66+
$this->productRepositoryMock->expects($this->once())
67+
->method('getById')
68+
->with($parentProductId)
69+
->willReturn($parentProductMock);
70+
$parentProductMock->expects($this->once())
71+
->method('getIdentities')
72+
->willReturn([$parentProductIdentity]);
73+
74+
$productIdentities = $this->plugin->afterGetIdentities($productMock, [$productIdentity]);
75+
$this->assertEquals([$productIdentity, $parentProductIdentity], $productIdentities);
76+
}
77+
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Cache/Tag/ConfigurableTest.php

Lines changed: 0 additions & 66 deletions
This file was deleted.

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@
168168
</argument>
169169
</arguments>
170170
</type>
171-
<type name="Magento\Framework\App\Cache\Tag\Strategy\Factory">
172-
<arguments>
173-
<argument name="customStrategies" xsi:type="array">
174-
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="object">\Magento\ConfigurableProduct\Model\Product\Cache\Tag\Configurable</item>
175-
</argument>
176-
</arguments>
177-
</type>
178171
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator">
179172
<arguments>
180173
<argument name="estimators" xsi:type="array">
@@ -209,4 +202,7 @@
209202
<type name="Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver">
210203
<plugin name="configurable" type="Magento\ConfigurableProduct\Plugin\Catalog\Model\Product\Pricing\Renderer\SalableResolver" />
211204
</type>
205+
<type name="Magento\Catalog\Model\Product">
206+
<plugin name="product_identities_extender" type="Magento\ConfigurableProduct\Model\Plugin\ProductIdentitiesExtender" />
207+
</type>
212208
</config>

0 commit comments

Comments
 (0)