Skip to content

Commit c935f5e

Browse files
committed
MC-38593: Complex products children ids are not cached in Type class leading to multiple unnecessary db requests
1 parent 4e0f75d commit c935f5e

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

app/code/Magento/Bundle/Test/Unit/Model/Plugin/ProductTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
namespace Magento\Bundle\Test\Unit\Model\Plugin;
99

1010
use Magento\Bundle\Model\Product\Type;
11+
use Magento\Bundle\Model\Plugin\Product as Plugin;
1112
use Magento\Catalog\Model\Product;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1314
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516

1617
class ProductTest extends TestCase
1718
{
18-
/** @var \Magento\Bundle\Model\Plugin\Product */
19+
/** @var Plugin */
1920
private $plugin;
2021

2122
/** @var MockObject|Type */
@@ -30,15 +31,15 @@ protected function setUp(): void
3031

3132
$this->product = $this->getMockBuilder(Product::class)
3233
->disableOriginalConstructor()
33-
->setMethods(['getEntityId'])
34+
->setMethods(['getEntityId', 'getTypeId'])
3435
->getMock();
3536
$this->type = $this->getMockBuilder(Type::class)
3637
->disableOriginalConstructor()
3738
->setMethods(['getParentIdsByChild'])
3839
->getMock();
3940

4041
$this->plugin = $objectManager->getObject(
41-
\Magento\Bundle\Model\Plugin\Product::class,
42+
Plugin::class,
4243
[
4344
'type' => $this->type,
4445
]
@@ -64,6 +65,9 @@ public function testAfterGetIdentities()
6465
$this->product->expects($this->once())
6566
->method('getEntityId')
6667
->willReturn($id);
68+
$this->product->expects($this->once())
69+
->method('getTypeId')
70+
->willReturn(Type::TYPE_CODE);
6771
$this->type->expects($this->once())
6872
->method('getParentIdsByChild')
6973
->with($id)

app/code/Magento/ConfigurableProduct/Model/Plugin/ProductIdentitiesExtender.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public function afterGetIdentities(Product $subject, array $identities): array
4949
if ($subject->getTypeId() !== ConfigurableType::TYPE_CODE) {
5050
return $identities;
5151
}
52-
$parentProductIdentities = [];
52+
$parentProductsIdentities = [];
5353
foreach ($this->configurableType->getParentIdsByChild($subject->getId()) as $parentId) {
5454
$parentProduct = $this->productRepository->getById($parentId);
55-
$parentProductIdentities[] = $parentProduct->getIdentities();
55+
$parentProductsIdentities[] = $parentProduct->getIdentities();
5656
}
57-
$identities = array_merge($identities, $parentProductIdentities);
57+
$identities = array_merge($identities, ...$parentProductsIdentities);
5858

5959
return array_unique($identities);
6060
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Plugin/ProductIdentitiesExtenderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public function testAfterGetIdentities()
5858
$productMock->expects($this->once())
5959
->method('getId')
6060
->willReturn($productId);
61+
$productMock->expects($this->once())
62+
->method('getTypeId')
63+
->willReturn(Configurable::TYPE_CODE);
6164
$this->configurableTypeMock->expects($this->once())
6265
->method('getParentIdsByChild')
6366
->with($productId)

0 commit comments

Comments
 (0)