1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2024 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
7
7
namespace Magento \Catalog \Model \Product \Price \Validation ;
10
10
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
11
use Magento \Catalog \Model \Product \Type ;
12
12
use Magento \Catalog \Model \ProductIdLocatorInterface ;
13
- use Magento \Customer \Api \GroupRepositoryInterface ;
14
13
use Magento \Directory \Model \Currency ;
15
- use Magento \Framework \Api \FilterBuilder ;
16
- use Magento \Framework \Api \SearchCriteriaBuilder ;
14
+ use Magento \Framework \App \ResourceConnection ;
17
15
use Magento \Framework \Exception \LocalizedException ;
18
16
use Magento \Framework \ObjectManager \ResetAfterRequestInterface ;
19
17
use Magento \Store \Api \WebsiteRepositoryInterface ;
@@ -35,21 +33,6 @@ class TierPriceValidator implements ResetAfterRequestInterface
35
33
*/
36
34
private $ productIdLocator ;
37
35
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
-
53
36
/**
54
37
* @var WebsiteRepositoryInterface
55
38
*/
@@ -60,13 +43,6 @@ class TierPriceValidator implements ResetAfterRequestInterface
60
43
*/
61
44
private $ validationResult ;
62
45
63
- /**
64
- * Groups by code cache.
65
- *
66
- * @var array
67
- */
68
- private $ customerGroupsByCode = [];
69
-
70
46
/**
71
47
* @var InvalidSkuProcessor
72
48
*/
@@ -97,6 +73,16 @@ class TierPriceValidator implements ResetAfterRequestInterface
97
73
*/
98
74
private $ productsCacheBySku = [];
99
75
76
+ /**
77
+ * @var ResourceConnection
78
+ */
79
+ private $ resourceConnection ;
80
+
81
+ /**
82
+ * @var array Customer group check cache
83
+ */
84
+ private $ customerGroupCheck = [];
85
+
100
86
/**
101
87
* @var ScopeConfigInterface
102
88
*/
@@ -106,38 +92,32 @@ class TierPriceValidator implements ResetAfterRequestInterface
106
92
* TierPriceValidator constructor.
107
93
*
108
94
* @param ProductIdLocatorInterface $productIdLocator
109
- * @param SearchCriteriaBuilder $searchCriteriaBuilder
110
- * @param FilterBuilder $filterBuilder
111
- * @param GroupRepositoryInterface $customerGroupRepository
112
95
* @param WebsiteRepositoryInterface $websiteRepository
113
96
* @param Result $validationResult
114
97
* @param InvalidSkuProcessor $invalidSkuProcessor
115
98
* @param ProductRepositoryInterface $productRepository
116
99
* @param array $allowedProductTypes [optional]
100
+ * @param ResourceConnection|null $resourceConnection
117
101
* @param ScopeConfigInterface|null $scopeConfig
118
102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
119
103
*/
120
104
public function __construct (
121
105
ProductIdLocatorInterface $ productIdLocator ,
122
- SearchCriteriaBuilder $ searchCriteriaBuilder ,
123
- FilterBuilder $ filterBuilder ,
124
- GroupRepositoryInterface $ customerGroupRepository ,
125
106
WebsiteRepositoryInterface $ websiteRepository ,
126
107
Result $ validationResult ,
127
108
InvalidSkuProcessor $ invalidSkuProcessor ,
128
109
ProductRepositoryInterface $ productRepository ,
129
110
array $ allowedProductTypes = [],
111
+ ?ResourceConnection $ resourceConnection = null ,
130
112
?ScopeConfigInterface $ scopeConfig = null
131
113
) {
132
114
$ this ->productIdLocator = $ productIdLocator ;
133
- $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
134
- $ this ->filterBuilder = $ filterBuilder ;
135
- $ this ->customerGroupRepository = $ customerGroupRepository ;
136
115
$ this ->websiteRepository = $ websiteRepository ;
137
116
$ this ->validationResult = $ validationResult ;
138
117
$ this ->invalidSkuProcessor = $ invalidSkuProcessor ;
139
118
$ this ->productRepository = $ productRepository ;
140
119
$ this ->allowedProductTypes = $ allowedProductTypes ;
120
+ $ this ->resourceConnection = $ resourceConnection ?: ObjectManager::getInstance ()->get (ResourceConnection::class);
141
121
$ this ->scopeConfig = $ scopeConfig ?: ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
142
122
}
143
123
@@ -504,32 +484,19 @@ private function checkGroup(TierPriceInterface $price, $key, Result $validationR
504
484
*/
505
485
private function retrieveGroupValue (string $ code )
506
486
{
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
512
495
);
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 );
530
497
}
531
498
532
- return $ this ->customerGroupsByCode [$ code ];
499
+ return $ this ->customerGroupCheck [$ code ];
533
500
}
534
501
535
502
/**
@@ -576,6 +543,6 @@ private function compareWebsiteValueNewPrice(TierPriceInterface $price, TierPric
576
543
*/
577
544
public function _resetState (): void
578
545
{
579
- $ this ->customerGroupsByCode = [];
546
+ $ this ->customerGroupCheck = [];
580
547
}
581
548
}
0 commit comments