Skip to content

Commit 082d981

Browse files
authored
Merge pull request #9424 from magento-gl/spartans_pr_12122024
[Spartans] Bugfix Delivery
2 parents 5d745d7 + 53d9ad3 commit 082d981

File tree

4 files changed

+83
-147
lines changed

4 files changed

+83
-147
lines changed

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

+27-60
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

77
namespace Magento\Catalog\Model\Product\Price\Validation;
@@ -10,10 +10,8 @@
1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Catalog\Model\Product\Type;
1212
use Magento\Catalog\Model\ProductIdLocatorInterface;
13-
use Magento\Customer\Api\GroupRepositoryInterface;
1413
use Magento\Directory\Model\Currency;
15-
use Magento\Framework\Api\FilterBuilder;
16-
use Magento\Framework\Api\SearchCriteriaBuilder;
14+
use Magento\Framework\App\ResourceConnection;
1715
use Magento\Framework\Exception\LocalizedException;
1816
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1917
use Magento\Store\Api\WebsiteRepositoryInterface;
@@ -35,21 +33,6 @@ class TierPriceValidator implements ResetAfterRequestInterface
3533
*/
3634
private $productIdLocator;
3735

38-
/**
39-
* @var SearchCriteriaBuilder
40-
*/
41-
private $searchCriteriaBuilder;
42-
43-
/**
44-
* @var FilterBuilder
45-
*/
46-
private $filterBuilder;
47-
48-
/**
49-
* @var GroupRepositoryInterface
50-
*/
51-
private $customerGroupRepository;
52-
5336
/**
5437
* @var WebsiteRepositoryInterface
5538
*/
@@ -60,13 +43,6 @@ class TierPriceValidator implements ResetAfterRequestInterface
6043
*/
6144
private $validationResult;
6245

63-
/**
64-
* Groups by code cache.
65-
*
66-
* @var array
67-
*/
68-
private $customerGroupsByCode = [];
69-
7046
/**
7147
* @var InvalidSkuProcessor
7248
*/
@@ -97,6 +73,16 @@ class TierPriceValidator implements ResetAfterRequestInterface
9773
*/
9874
private $productsCacheBySku = [];
9975

76+
/**
77+
* @var ResourceConnection
78+
*/
79+
private $resourceConnection;
80+
81+
/**
82+
* @var array Customer group check cache
83+
*/
84+
private $customerGroupCheck = [];
85+
10086
/**
10187
* @var ScopeConfigInterface
10288
*/
@@ -106,38 +92,32 @@ class TierPriceValidator implements ResetAfterRequestInterface
10692
* TierPriceValidator constructor.
10793
*
10894
* @param ProductIdLocatorInterface $productIdLocator
109-
* @param SearchCriteriaBuilder $searchCriteriaBuilder
110-
* @param FilterBuilder $filterBuilder
111-
* @param GroupRepositoryInterface $customerGroupRepository
11295
* @param WebsiteRepositoryInterface $websiteRepository
11396
* @param Result $validationResult
11497
* @param InvalidSkuProcessor $invalidSkuProcessor
11598
* @param ProductRepositoryInterface $productRepository
11699
* @param array $allowedProductTypes [optional]
100+
* @param ResourceConnection|null $resourceConnection
117101
* @param ScopeConfigInterface|null $scopeConfig
118102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
119103
*/
120104
public function __construct(
121105
ProductIdLocatorInterface $productIdLocator,
122-
SearchCriteriaBuilder $searchCriteriaBuilder,
123-
FilterBuilder $filterBuilder,
124-
GroupRepositoryInterface $customerGroupRepository,
125106
WebsiteRepositoryInterface $websiteRepository,
126107
Result $validationResult,
127108
InvalidSkuProcessor $invalidSkuProcessor,
128109
ProductRepositoryInterface $productRepository,
129110
array $allowedProductTypes = [],
111+
?ResourceConnection $resourceConnection = null,
130112
?ScopeConfigInterface $scopeConfig = null
131113
) {
132114
$this->productIdLocator = $productIdLocator;
133-
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
134-
$this->filterBuilder = $filterBuilder;
135-
$this->customerGroupRepository = $customerGroupRepository;
136115
$this->websiteRepository = $websiteRepository;
137116
$this->validationResult = $validationResult;
138117
$this->invalidSkuProcessor = $invalidSkuProcessor;
139118
$this->productRepository = $productRepository;
140119
$this->allowedProductTypes = $allowedProductTypes;
120+
$this->resourceConnection = $resourceConnection ?: ObjectManager::getInstance()->get(ResourceConnection::class);
141121
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
142122
}
143123

@@ -504,32 +484,19 @@ private function checkGroup(TierPriceInterface $price, $key, Result $validationR
504484
*/
505485
private function retrieveGroupValue(string $code)
506486
{
507-
if (!isset($this->customerGroupsByCode[$code])) {
508-
$searchCriteria = $this->searchCriteriaBuilder->addFilters(
509-
[
510-
$this->filterBuilder->setField('customer_group_code')->setValue($code)->create()
511-
]
487+
if (!isset($this->customerGroupCheck[$code])) {
488+
$connection = $this->resourceConnection->getConnection();
489+
$select = $connection->select()->from(
490+
$this->resourceConnection->getTableName('customer_group'),
491+
'customer_group_id'
492+
)->where(
493+
'customer_group_code = ?',
494+
$code
512495
);
513-
$items = $this->customerGroupRepository->getList($searchCriteria->create())->getItems();
514-
$item = array_shift($items);
515-
516-
if (!$item) {
517-
$this->customerGroupsByCode[$code] = false;
518-
return false;
519-
}
520-
521-
$itemCode = $item->getCode();
522-
$itemId = $item->getId();
523-
524-
if (strtolower($itemCode) !== $code) {
525-
$this->customerGroupsByCode[$code] = false;
526-
return false;
527-
}
528-
529-
$this->customerGroupsByCode[strtolower($itemCode)] = $itemId;
496+
$this->customerGroupCheck[$code] = $connection->fetchOne($select);
530497
}
531498

532-
return $this->customerGroupsByCode[$code];
499+
return $this->customerGroupCheck[$code];
533500
}
534501

535502
/**
@@ -576,6 +543,6 @@ private function compareWebsiteValueNewPrice(TierPriceInterface $price, TierPric
576543
*/
577544
public function _resetState(): void
578545
{
579-
$this->customerGroupsByCode = [];
546+
$this->customerGroupCheck = [];
580547
}
581548
}

0 commit comments

Comments
 (0)