77namespace Magento \Catalog \Model \Product \Price \Validation ;
88
99use Magento \Catalog \Api \Data \TierPriceInterface ;
10- use Magento \Catalog \Model \ Product \ Price \ TierPricePersistence ;
10+ use Magento \Catalog \Api \ ProductRepositoryInterface ;
1111use Magento \Catalog \Model \Product \Type ;
1212use Magento \Catalog \Model \ProductIdLocatorInterface ;
1313use Magento \Customer \Api \GroupRepositoryInterface ;
@@ -54,11 +54,6 @@ class TierPriceValidator implements ResetAfterRequestInterface
5454 */
5555 private $ validationResult ;
5656
57- /**
58- * @var TierPricePersistence
59- */
60- private $ tierPricePersistence ;
61-
6257 /**
6358 * Groups by code cache.
6459 *
@@ -86,6 +81,16 @@ class TierPriceValidator implements ResetAfterRequestInterface
8681 */
8782 private $ allowedProductTypes = [];
8883
84+ /**
85+ * @var ProductRepositoryInterface
86+ */
87+ private $ productRepository ;
88+
89+ /**
90+ * @var array
91+ */
92+ private $ productsCacheBySku = [];
93+
8994 /**
9095 * TierPriceValidator constructor.
9196 *
@@ -94,9 +99,9 @@ class TierPriceValidator implements ResetAfterRequestInterface
9499 * @param FilterBuilder $filterBuilder
95100 * @param GroupRepositoryInterface $customerGroupRepository
96101 * @param WebsiteRepositoryInterface $websiteRepository
97- * @param TierPricePersistence $tierPricePersistence
98102 * @param Result $validationResult
99103 * @param InvalidSkuProcessor $invalidSkuProcessor
104+ * @param ProductRepositoryInterface $productRepository
100105 * @param array $allowedProductTypes [optional]
101106 */
102107 public function __construct (
@@ -105,19 +110,19 @@ public function __construct(
105110 FilterBuilder $ filterBuilder ,
106111 GroupRepositoryInterface $ customerGroupRepository ,
107112 WebsiteRepositoryInterface $ websiteRepository ,
108- TierPricePersistence $ tierPricePersistence ,
109113 Result $ validationResult ,
110114 InvalidSkuProcessor $ invalidSkuProcessor ,
115+ ProductRepositoryInterface $ productRepository ,
111116 array $ allowedProductTypes = []
112117 ) {
113118 $ this ->productIdLocator = $ productIdLocator ;
114119 $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
115120 $ this ->filterBuilder = $ filterBuilder ;
116121 $ this ->customerGroupRepository = $ customerGroupRepository ;
117122 $ this ->websiteRepository = $ websiteRepository ;
118- $ this ->tierPricePersistence = $ tierPricePersistence ;
119123 $ this ->validationResult = $ validationResult ;
120124 $ this ->invalidSkuProcessor = $ invalidSkuProcessor ;
125+ $ this ->productRepository = $ productRepository ;
121126 $ this ->allowedProductTypes = $ allowedProductTypes ;
122127 }
123128
@@ -310,7 +315,16 @@ private function checkPriceType(
310315 */
311316 private function checkQuantity (TierPriceInterface $ price , $ key , Result $ validationResult )
312317 {
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 ) {
314328 $ validationResult ->addFailedItem (
315329 $ key ,
316330 __ (
0 commit comments