Skip to content

Commit 8846cf5

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-2610' into Tier4-PR-Delivery-12-1-23
2 parents efc6bae + 084dfea commit 8846cf5

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Catalog\Model\Product\Price\Validation;
88

99
use Magento\Catalog\Api\Data\TierPriceInterface;
10-
use Magento\Catalog\Model\Product\Price\TierPricePersistence;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Catalog\Model\Product\Type;
1212
use Magento\Catalog\Model\ProductIdLocatorInterface;
1313
use 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
__(

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Catalog\Test\Unit\Model\Product\Price\Validation;
99

1010
use Magento\Catalog\Api\Data\TierPriceInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
1112
use Magento\Catalog\Model\Product\Price\Validation\InvalidSkuProcessor;
1213
use Magento\Catalog\Model\Product\Price\Validation\Result;
1314
use Magento\Catalog\Model\Product\Price\Validation\TierPriceValidator;
@@ -79,6 +80,11 @@ class TierPriceValidatorTest extends TestCase
7980
*/
8081
private $tierPrice;
8182

83+
/**
84+
* @var ProductRepositoryInterface|MockObject
85+
*/
86+
private $productRepository;
87+
8288
/**
8389
* {@inheritdoc}
8490
*/
@@ -109,6 +115,9 @@ protected function setUp(): void
109115
$this->tierPrice = $this->getMockBuilder(TierPriceInterface::class)
110116
->disableOriginalConstructor()
111117
->getMockForAbstractClass();
118+
$this->productRepository = $this->getMockBuilder(ProductRepositoryInterface::class)
119+
->disableOriginalConstructor()
120+
->getMockForAbstractClass();
112121

113122
$objectManagerHelper = new ObjectManager($this);
114123
$this->tierPriceValidator = $objectManagerHelper->getObject(
@@ -120,7 +129,8 @@ protected function setUp(): void
120129
'customerGroupRepository' => $this->customerGroupRepository,
121130
'websiteRepository' => $this->websiteRepository,
122131
'validationResult' => $this->validationResult,
123-
'invalidSkuProcessor' => $this->invalidSkuProcessor
132+
'invalidSkuProcessor' => $this->invalidSkuProcessor,
133+
'productRepository' => $this->productRepository
124134
]
125135
);
126136
}
@@ -187,6 +197,27 @@ private function prepareRetrieveValidationResultMethod($sku, array $returned)
187197
];
188198
$this->productIdLocator->expects($this->atLeastOnce())->method('retrieveProductIdsBySkus')
189199
->willReturn($idsBySku);
200+
201+
$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
202+
->disableOriginalConstructor()
203+
->getMock();
204+
$type = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type\AbstractType::class)
205+
->onlyMethods(['canUseQtyDecimals'])
206+
->disableOriginalConstructor()
207+
->getMockForAbstractClass();
208+
209+
$this->productRepository->expects($this->once())
210+
->method('get')
211+
->with($sku)
212+
->willReturn($product);
213+
214+
$product->expects($this->once())
215+
->method('getTypeInstance')
216+
->willReturn($type);
217+
218+
$type->expects($this->once())
219+
->method('canUseQtyDecimals')
220+
->willReturn(true);
190221
}
191222

192223
/**

0 commit comments

Comments
 (0)