Skip to content

Commit 8860952

Browse files
committed
AC-13448: Deliver tier-price operations performance improvement patch into 2.4.8
Fix for WebAPI, Integration & Unit tests failures
1 parent b982d6a commit 8860952

File tree

4 files changed

+51
-88
lines changed

4 files changed

+51
-88
lines changed

app/code/Magento/Catalog/Model/Product/Price/Validation/TierPriceValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private function retrieveGroupValue(string $code)
493493
'customer_group_code = ?',
494494
$code
495495
);
496-
$this->customerGroupCheck[$code] = (bool)$connection->fetchOne($select);
496+
$this->customerGroupCheck[$code] = $connection->fetchOne($select);
497497
}
498498

499499
return $this->customerGroupCheck[$code];

app/code/Magento/Catalog/Test/Unit/Model/Product/Price/Validation/TierPriceValidatorTest.php

Lines changed: 48 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -14,13 +14,9 @@
1414
use Magento\Catalog\Model\Product\Price\Validation\TierPriceValidator;
1515
use Magento\Catalog\Model\Product\Type;
1616
use Magento\Catalog\Model\ProductIdLocatorInterface;
17-
use Magento\Customer\Api\Data\GroupInterface;
18-
use Magento\Customer\Api\Data\GroupSearchResultsInterface;
19-
use Magento\Customer\Api\GroupRepositoryInterface;
20-
use Magento\Framework\Api\AbstractSimpleObject;
21-
use Magento\Framework\Api\FilterBuilder;
22-
use Magento\Framework\Api\Search\SearchCriteriaInterface;
23-
use Magento\Framework\Api\SearchCriteriaBuilder;
17+
use Magento\Framework\App\ResourceConnection;
18+
use Magento\Framework\DB\Adapter\AdapterInterface;
19+
use Magento\Framework\DB\Select;
2420
use Magento\Framework\Exception\NoSuchEntityException;
2521
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2622
use Magento\Store\Api\Data\WebsiteInterface;
@@ -45,21 +41,6 @@ class TierPriceValidatorTest extends TestCase
4541
*/
4642
private $productIdLocator;
4743

48-
/**
49-
* @var SearchCriteriaBuilder|MockObject
50-
*/
51-
private $searchCriteriaBuilder;
52-
53-
/**
54-
* @var FilterBuilder|MockObject
55-
*/
56-
private $filterBuilder;
57-
58-
/**
59-
* @var GroupRepositoryInterface|MockObject
60-
*/
61-
private $customerGroupRepository;
62-
6344
/**
6445
* @var WebsiteRepositoryInterface|MockObject
6546
*/
@@ -85,6 +66,16 @@ class TierPriceValidatorTest extends TestCase
8566
*/
8667
private $productRepository;
8768

69+
/**
70+
* @var ResourceConnection|MockObject
71+
*/
72+
private $resourceConnectionMock;
73+
74+
/**
75+
* @var AdapterInterface|MockObject
76+
*/
77+
private $adapterInterface;
78+
8879
/**
8980
* {@inheritdoc}
9081
*/
@@ -93,15 +84,6 @@ protected function setUp(): void
9384
$this->productIdLocator = $this->getMockBuilder(ProductIdLocatorInterface::class)
9485
->disableOriginalConstructor()
9586
->getMockForAbstractClass();
96-
$this->searchCriteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class)
97-
->disableOriginalConstructor()
98-
->getMock();
99-
$this->filterBuilder = $this->getMockBuilder(FilterBuilder::class)
100-
->disableOriginalConstructor()
101-
->getMock();
102-
$this->customerGroupRepository = $this->getMockBuilder(GroupRepositoryInterface::class)
103-
->disableOriginalConstructor()
104-
->getMockForAbstractClass();
10587
$this->websiteRepository = $this->getMockBuilder(WebsiteRepositoryInterface::class)
10688
->disableOriginalConstructor()
10789
->getMockForAbstractClass();
@@ -118,51 +100,54 @@ protected function setUp(): void
118100
$this->productRepository = $this->getMockBuilder(ProductRepositoryInterface::class)
119101
->disableOriginalConstructor()
120102
->getMockForAbstractClass();
103+
$this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
104+
->disableOriginalConstructor()
105+
->getMock();
106+
107+
$this->adapterInterface = $this->getMockBuilder(AdapterInterface::class)
108+
->disableOriginalConstructor()
109+
->getMockForAbstractClass();
121110

122111
$objectManagerHelper = new ObjectManager($this);
123112
$this->tierPriceValidator = $objectManagerHelper->getObject(
124113
TierPriceValidator::class,
125114
[
126115
'productIdLocator' => $this->productIdLocator,
127-
'searchCriteriaBuilder' => $this->searchCriteriaBuilder,
128-
'filterBuilder' => $this->filterBuilder,
129-
'customerGroupRepository' => $this->customerGroupRepository,
130116
'websiteRepository' => $this->websiteRepository,
131117
'validationResult' => $this->validationResult,
132118
'invalidSkuProcessor' => $this->invalidSkuProcessor,
133-
'productRepository' => $this->productRepository
119+
'productRepository' => $this->productRepository,
120+
'resourceConnection' => $this->resourceConnectionMock
134121
]
135122
);
136123
}
137124

138125
/**
139126
* Prepare CustomerGroupRepository mock.
140127
*
141-
* @param array $returned
142128
* @return void
143129
*/
144-
private function prepareCustomerGroupRepositoryMock(array $returned)
130+
private function prepareCustomerGroupRepositoryMock()
145131
{
146-
$searchCriteria = $this
147-
->getMockBuilder(SearchCriteriaInterface::class)
148-
->disableOriginalConstructor()
149-
->getMockForAbstractClass();
150-
$filter = $this->getMockBuilder(AbstractSimpleObject::class)
151-
->disableOriginalConstructor()
152-
->getMockForAbstractClass();
153-
$this->filterBuilder->expects($this->atLeastOnce())->method('setField')->willReturnSelf();
154-
$this->filterBuilder->expects($this->atLeastOnce())->method('setValue')->willReturnSelf();
155-
$this->filterBuilder->expects($this->atLeastOnce())->method('create')->willReturn($filter);
156-
$this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('addFilters')->willReturnSelf();
157-
$this->searchCriteriaBuilder->expects($this->atLeastOnce())->method('create')->willReturn($searchCriteria);
158-
$customerGroupSearchResults = $this
159-
->getMockBuilder(GroupSearchResultsInterface::class)
160-
->disableOriginalConstructor()
161-
->getMockForAbstractClass();
162-
$customerGroupSearchResults->expects($this->once())->method('getItems')
163-
->willReturn($returned['customerGroupSearchResults_getItems']);
164-
$this->customerGroupRepository->expects($this->atLeastOnce())->method('getList')
165-
->willReturn($customerGroupSearchResults);
132+
$select = $this->createMock(Select::class);
133+
$select->expects($this->once())
134+
->method('from')
135+
->with('customer_group', 'customer_group_id')
136+
->willReturnSelf();
137+
$select->expects($this->once())
138+
->method('where')
139+
->with('customer_group_code = ?', 'test_group')
140+
->willReturnSelf();
141+
$this->adapterInterface->expects($this->once())
142+
->method('select')
143+
->willReturn($select);
144+
145+
$this->resourceConnectionMock->expects($this->once())
146+
->method('getConnection')
147+
->willReturn($this->adapterInterface);
148+
$this->resourceConnectionMock->expects($this->once())
149+
->method('getTableName')
150+
->willReturnArgument(0);
166151
}
167152

168153
/**
@@ -251,11 +236,6 @@ public function testValidateSkus()
251236
*/
252237
public function testRetrieveValidationResult(array $returned)
253238
{
254-
if (!empty($returned['customerGroupSearchResults_getItems'])) {
255-
$groupSearchResult = $returned['customerGroupSearchResults_getItems'][0];
256-
$returned['customerGroupSearchResults_getItems'][0] = $groupSearchResult($this);
257-
}
258-
259239
$sku = 'ASDF234234';
260240
$prices = [$this->tierPrice];
261241
$existingPrices = [$this->tierPrice];
@@ -264,26 +244,14 @@ public function testRetrieveValidationResult(array $returned)
264244
->disableOriginalConstructor()
265245
->getMockForAbstractClass();
266246
$this->websiteRepository->expects($this->atLeastOnce())->method('getById')->willReturn($website);
267-
$this->prepareCustomerGroupRepositoryMock($returned);
247+
$this->prepareCustomerGroupRepositoryMock();
268248

269249
$this->assertEquals(
270250
$this->validationResult,
271251
$this->tierPriceValidator->retrieveValidationResult($prices, $existingPrices)
272252
);
273253
}
274254

275-
protected function getMockForCustomerGroup($customerGroupName)
276-
{
277-
$customerGroup = $this->getMockBuilder(GroupInterface::class)
278-
->onlyMethods(['getCode', 'getId'])
279-
->disableOriginalConstructor()
280-
->getMockForAbstractClass();
281-
$customerGroup->expects($this->atLeastOnce())->method('getCode')->willReturn($customerGroupName);
282-
$customerGroupId = 23;
283-
$customerGroup->expects($this->atLeastOnce())->method('getId')->willReturn($customerGroupId);
284-
return $customerGroup;
285-
}
286-
287255
/**
288256
* Data provider for retrieveValidationResult() test.
289257
*
@@ -292,21 +260,17 @@ protected function getMockForCustomerGroup($customerGroupName)
292260
public static function retrieveValidationResultDataProvider()
293261
{
294262
$customerGroupName = 'test_Group';
295-
$customerGroup = static fn (self $testCase) => $testCase->getMockForCustomerGroup($customerGroupName);
296-
297263
return [
298264
[
299265
[
300266
'tierPrice_getCustomerGroup' => $customerGroupName,
301-
'tierPrice_getPriceType' => TierPriceInterface::PRICE_TYPE_DISCOUNT,
302-
'customerGroupSearchResults_getItems' => [$customerGroup]
267+
'tierPrice_getPriceType' => TierPriceInterface::PRICE_TYPE_DISCOUNT
303268
]
304269
],
305270
[
306271
[
307272
'tierPrice_getCustomerGroup' => $customerGroupName,
308-
'tierPrice_getPriceType' => TierPriceInterface::PRICE_TYPE_FIXED,
309-
'customerGroupSearchResults_getItems' => []
273+
'tierPrice_getPriceType' => TierPriceInterface::PRICE_TYPE_FIXED
310274
]
311275
]
312276
];
@@ -325,13 +289,12 @@ public function testRetrieveValidationResultWithException()
325289
$existingPrices = [$this->tierPrice];
326290
$returned = [
327291
'tierPrice_getPriceType' => TierPriceInterface::PRICE_TYPE_DISCOUNT,
328-
'customerGroupSearchResults_getItems' => [],
329292
'tierPrice_getCustomerGroup' => $customerGroupName,
330293
];
331294
$this->prepareRetrieveValidationResultMethod($sku, $returned);
332295
$exception = new NoSuchEntityException();
333296
$this->websiteRepository->expects($this->atLeastOnce())->method('getById')->willThrowException($exception);
334-
$this->prepareCustomerGroupRepositoryMock($returned);
297+
$this->prepareCustomerGroupRepositoryMock();
335298

336299
$this->assertEquals(
337300
$this->validationResult,

app/code/Magento/Customer/etc/db_schema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@
430430
<constraint xsi:type="primary" referenceId="PRIMARY">
431431
<column name="customer_group_id"/>
432432
</constraint>
433-
<index referenceId="CUSTOMER_GROUP_CODE" indexType="btree">
433+
<index referenceId="CUSTOMER_GROUP_CUSTOMER_GROUP_CODE" indexType="btree">
434434
<column name="customer_group_code"/>
435435
</index>
436436
</table>

app/code/Magento/Customer/etc/db_schema_whitelist.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
"tax_class_id": true
268268
},
269269
"index": {
270-
"CUSTOMER_GROUP_CODE": true
270+
"CUSTOMER_GROUP_CUSTOMER_GROUP_CODE": true
271271
},
272272
"constraint": {
273273
"PRIMARY": true

0 commit comments

Comments
 (0)