7
7
namespace Magento \Catalog \Model \Product \Price \Validation ;
8
8
9
9
use Magento \Catalog \Api \Data \TierPriceInterface ;
10
- use Magento \Catalog \Model \ Product \ Price \ TierPricePersistence ;
10
+ use Magento \Catalog \Api \ ProductRepositoryInterface ;
11
11
use Magento \Catalog \Model \Product \Type ;
12
12
use Magento \Catalog \Model \ProductIdLocatorInterface ;
13
13
use Magento \Customer \Api \GroupRepositoryInterface ;
@@ -54,11 +54,6 @@ class TierPriceValidator implements ResetAfterRequestInterface
54
54
*/
55
55
private $ validationResult ;
56
56
57
- /**
58
- * @var TierPricePersistence
59
- */
60
- private $ tierPricePersistence ;
61
-
62
57
/**
63
58
* Groups by code cache.
64
59
*
@@ -86,6 +81,16 @@ class TierPriceValidator implements ResetAfterRequestInterface
86
81
*/
87
82
private $ allowedProductTypes = [];
88
83
84
+ /**
85
+ * @var ProductRepositoryInterface
86
+ */
87
+ private $ productRepository ;
88
+
89
+ /**
90
+ * @var array
91
+ */
92
+ private $ productsCacheBySku = [];
93
+
89
94
/**
90
95
* TierPriceValidator constructor.
91
96
*
@@ -94,9 +99,9 @@ class TierPriceValidator implements ResetAfterRequestInterface
94
99
* @param FilterBuilder $filterBuilder
95
100
* @param GroupRepositoryInterface $customerGroupRepository
96
101
* @param WebsiteRepositoryInterface $websiteRepository
97
- * @param TierPricePersistence $tierPricePersistence
98
102
* @param Result $validationResult
99
103
* @param InvalidSkuProcessor $invalidSkuProcessor
104
+ * @param ProductRepositoryInterface $productRepository
100
105
* @param array $allowedProductTypes [optional]
101
106
*/
102
107
public function __construct (
@@ -105,19 +110,19 @@ public function __construct(
105
110
FilterBuilder $ filterBuilder ,
106
111
GroupRepositoryInterface $ customerGroupRepository ,
107
112
WebsiteRepositoryInterface $ websiteRepository ,
108
- TierPricePersistence $ tierPricePersistence ,
109
113
Result $ validationResult ,
110
114
InvalidSkuProcessor $ invalidSkuProcessor ,
115
+ ProductRepositoryInterface $ productRepository ,
111
116
array $ allowedProductTypes = []
112
117
) {
113
118
$ this ->productIdLocator = $ productIdLocator ;
114
119
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
115
120
$ this ->filterBuilder = $ filterBuilder ;
116
121
$ this ->customerGroupRepository = $ customerGroupRepository ;
117
122
$ this ->websiteRepository = $ websiteRepository ;
118
- $ this ->tierPricePersistence = $ tierPricePersistence ;
119
123
$ this ->validationResult = $ validationResult ;
120
124
$ this ->invalidSkuProcessor = $ invalidSkuProcessor ;
125
+ $ this ->productRepository = $ productRepository ;
121
126
$ this ->allowedProductTypes = $ allowedProductTypes ;
122
127
}
123
128
@@ -310,7 +315,16 @@ private function checkPriceType(
310
315
*/
311
316
private function checkQuantity (TierPriceInterface $ price , $ key , Result $ validationResult )
312
317
{
313
- if ($ price ->getQuantity () < 1 ) {
318
+ $ sku = $ price ->getSku ();
319
+ if (isset ($ this ->productsCacheBySku [$ sku ])) {
320
+ $ product = $ this ->productsCacheBySku [$ sku ];
321
+ } else {
322
+ $ product = $ this ->productRepository ->get ($ price ->getSku ());
323
+ $ this ->productsCacheBySku [$ sku ] = $ product ;
324
+ }
325
+
326
+ $ canUseQtyDecimals = $ product ->getTypeInstance ()->canUseQtyDecimals ();
327
+ if ($ price ->getQuantity () <= 0 || $ price ->getQuantity () < 1 && !$ canUseQtyDecimals ) {
314
328
$ validationResult ->addFailedItem (
315
329
$ key ,
316
330
__ (
0 commit comments