Skip to content

Commit b4b7538

Browse files
authored
Merge pull request #3124 from magento-tsg-csl3/2.2-develop-pr1
[TSG-CSL3] Backporting 2.2 (pr1)
2 parents 679bdb5 + 4e3a4a9 commit b4b7538

File tree

10 files changed

+290
-52
lines changed

10 files changed

+290
-52
lines changed

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator.php

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
use Magento\CatalogInventory\Model\Stock;
1717
use Magento\Framework\Event\Observer;
1818
use Magento\Framework\Exception\LocalizedException;
19+
use Magento\Quote\Model\Quote\Item;
1920

2021
/**
2122
* @api
2223
* @since 100.0.2
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2325
*/
2426
class QuantityValidator
2527
{
@@ -66,7 +68,7 @@ public function __construct(
6668
* Add error information to Quote Item
6769
*
6870
* @param \Magento\Framework\DataObject $result
69-
* @param \Magento\Quote\Model\Quote\Item $quoteItem
71+
* @param Item $quoteItem
7072
* @param bool $removeError
7173
* @return void
7274
*/
@@ -99,7 +101,7 @@ private function addErrorInfoToQuote($result, $quoteItem)
99101
*/
100102
public function validate(Observer $observer)
101103
{
102-
/* @var $quoteItem \Magento\Quote\Model\Quote\Item */
104+
/* @var $quoteItem Item */
103105
$quoteItem = $observer->getEvent()->getItem();
104106
if (!$quoteItem ||
105107
!$quoteItem->getProductId() ||
@@ -174,31 +176,7 @@ public function validate(Observer $observer)
174176
$qty = $product->getTypeInstance()->prepareQuoteItemQty($qty, $product);
175177
$quoteItem->setData('qty', $qty);
176178
if ($stockStatus) {
177-
$result = $this->stockState->checkQtyIncrements(
178-
$product->getId(),
179-
$qty,
180-
$product->getStore()->getWebsiteId()
181-
);
182-
if ($result->getHasError()) {
183-
$quoteItem->addErrorInfo(
184-
'cataloginventory',
185-
Data::ERROR_QTY_INCREMENTS,
186-
$result->getMessage()
187-
);
188-
189-
$quoteItem->getQuote()->addErrorInfo(
190-
$result->getQuoteMessageIndex(),
191-
'cataloginventory',
192-
Data::ERROR_QTY_INCREMENTS,
193-
$result->getQuoteMessage()
194-
);
195-
} else {
196-
// Delete error from item and its quote, if it was set due to qty problems
197-
$this->_removeErrorsFromQuoteAndItem(
198-
$quoteItem,
199-
Data::ERROR_QTY_INCREMENTS
200-
);
201-
}
179+
$this->checkOptionsQtyIncrements($quoteItem, $options);
202180
}
203181
// variable to keep track if we have previously encountered an error in one of the options
204182
$removeError = true;
@@ -227,10 +205,44 @@ public function validate(Observer $observer)
227205
}
228206
}
229207

208+
/**
209+
* Verifies product options quantity increments.
210+
*
211+
* @param Item $quoteItem
212+
* @param array $options
213+
* @return void
214+
*/
215+
private function checkOptionsQtyIncrements(Item $quoteItem, array $options)
216+
{
217+
$removeErrors = true;
218+
foreach ($options as $option) {
219+
$result = $this->stockState->checkQtyIncrements(
220+
$option->getProduct()->getId(),
221+
$quoteItem->getData('qty'),
222+
$option->getProduct()->getStore()->getWebsiteId()
223+
);
224+
if ($result->getHasError()) {
225+
$quoteItem->getQuote()->addErrorInfo(
226+
$result->getQuoteMessageIndex(),
227+
'cataloginventory',
228+
Data::ERROR_QTY_INCREMENTS,
229+
$result->getQuoteMessage()
230+
);
231+
232+
$removeErrors = false;
233+
}
234+
}
235+
236+
if ($removeErrors) {
237+
// Delete error from item and its quote, if it was set due to qty problems
238+
$this->_removeErrorsFromQuoteAndItem($quoteItem, Data::ERROR_QTY_INCREMENTS);
239+
}
240+
}
241+
230242
/**
231243
* Removes error statuses from quote and item, set by this observer
232244
*
233-
* @param \Magento\Quote\Model\Quote\Item $item
245+
* @param Item $item
234246
* @param int $code
235247
* @return void
236248
*/

app/code/Magento/CatalogInventory/Model/Quote/Item/QuantityValidator/Initializer/Option.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\CatalogInventory\Api\StockStateInterface;
1010
use Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\QuoteItemQtyList;
1111

12+
/**
13+
* Class for initialize quote item options.
14+
*/
1215
class Option
1316
{
1417
/**
@@ -67,10 +70,6 @@ public function getStockItem(
6770
* define that stock item is child for composite product
6871
*/
6972
$stockItem->setIsChildItem(true);
70-
/**
71-
* don't check qty increments value for option product
72-
*/
73-
$stockItem->setSuppressCheckQtyIncrements(true);
7473

7574
return $stockItem;
7675
}

app/code/Magento/CatalogInventory/Test/Unit/Model/Quote/Item/QuantityValidator/Initializer/OptionTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\CatalogInventory\Test\Unit\Model\Quote\Item\QuantityValidator\Initializer;
77

8+
/**
9+
* Class OptionTest
10+
*/
811
class OptionTest extends \PHPUnit\Framework\TestCase
912
{
1013
/**
@@ -67,6 +70,9 @@ class OptionTest extends \PHPUnit\Framework\TestCase
6770
*/
6871
protected $websiteId = 111;
6972

73+
/**
74+
* @inheritdoc
75+
*/
7076
protected function setUp()
7177
{
7278
$optionMethods = [
@@ -140,6 +146,9 @@ protected function setUp()
140146
);
141147
}
142148

149+
/**
150+
* @return void
151+
*/
143152
public function testInitializeWhenResultIsDecimalGetBackordersMessageHasOptionQtyUpdate()
144153
{
145154
$optionValue = 5;
@@ -151,7 +160,6 @@ public function testInitializeWhenResultIsDecimalGetBackordersMessageHasOptionQt
151160
$this->optionMock->expects($this->any())->method('getProduct')->will($this->returnValue($this->productMock));
152161

153162
$this->stockItemMock->expects($this->once())->method('setIsChildItem')->with(true);
154-
$this->stockItemMock->expects($this->once())->method('setSuppressCheckQtyIncrements')->with(true);
155163
$this->stockItemMock->expects($this->once())->method('getItemId')->will($this->returnValue(true));
156164

157165
$this->stockRegistry
@@ -212,6 +220,9 @@ public function testInitializeWhenResultIsDecimalGetBackordersMessageHasOptionQt
212220
$this->validator->initialize($this->optionMock, $this->quoteItemMock, $qty);
213221
}
214222

223+
/**
224+
* @return void
225+
*/
215226
public function testInitializeWhenResultNotDecimalGetBackordersMessageHasOptionQtyUpdate()
216227
{
217228
$optionValue = 5;
@@ -222,7 +233,6 @@ public function testInitializeWhenResultNotDecimalGetBackordersMessageHasOptionQ
222233
$this->optionMock->expects($this->any())->method('getProduct')->will($this->returnValue($this->productMock));
223234

224235
$this->stockItemMock->expects($this->once())->method('setIsChildItem')->with(true);
225-
$this->stockItemMock->expects($this->once())->method('setSuppressCheckQtyIncrements')->with(true);
226236
$this->stockItemMock->expects($this->once())->method('getItemId')->will($this->returnValue(true));
227237

228238
$this->stockRegistry
@@ -267,6 +277,8 @@ public function testInitializeWhenResultNotDecimalGetBackordersMessageHasOptionQ
267277
}
268278

269279
/**
280+
* @return void
281+
*
270282
* @expectedException \Magento\Framework\Exception\LocalizedException
271283
* @expectedExceptionMessage The stock item for Product in option is not valid.
272284
*/

app/code/Magento/CatalogInventory/Test/Unit/Model/Quote/Item/QuantityValidator/Initializer/QuantityValidatorTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class QuantityValidatorTest extends \PHPUnit\Framework\TestCase
119119
*/
120120
private $stockStatusMock;
121121

122+
/**
123+
* @inheritdoc
124+
*/
122125
protected function setUp()
123126
{
124127
$objectManagerHelper = new ObjectManager($this);
@@ -278,11 +281,13 @@ public function testValidateWithOptions()
278281
{
279282
$optionMock = $this->getMockBuilder(OptionItem::class)
280283
->disableOriginalConstructor()
281-
->setMethods(['setHasError', 'getStockStateResult'])
284+
->setMethods(['setHasError', 'getStockStateResult', 'getProduct'])
282285
->getMock();
283286
$optionMock->expects($this->once())
284287
->method('getStockStateResult')
285288
->willReturn($this->resultMock);
289+
$optionMock->method('getProduct')
290+
->willReturn($this->productMock);
286291
$this->stockRegistryMock->expects($this->at(0))
287292
->method('getStockItem')
288293
->willReturn($this->stockItemMock);
@@ -319,7 +324,7 @@ public function testValidateWithOptionsAndError()
319324
{
320325
$optionMock = $this->getMockBuilder(OptionItem::class)
321326
->disableOriginalConstructor()
322-
->setMethods(['setHasError', 'getStockStateResult'])
327+
->setMethods(['setHasError', 'getStockStateResult', 'getProduct'])
323328
->getMock();
324329
$this->stockRegistryMock->expects($this->at(0))
325330
->method('getStockItem')
@@ -330,6 +335,8 @@ public function testValidateWithOptionsAndError()
330335
$optionMock->expects($this->once())
331336
->method('getStockStateResult')
332337
->willReturn($this->resultMock);
338+
$optionMock->method('getProduct')
339+
->willReturn($this->productMock);
333340
$options = [$optionMock];
334341
$this->createInitialStub(1);
335342
$this->setUpStubForQuantity(1, true);
@@ -360,7 +367,7 @@ public function testValidateAndRemoveErrorsFromQuote()
360367
{
361368
$optionMock = $this->getMockBuilder(OptionItem::class)
362369
->disableOriginalConstructor()
363-
->setMethods(['setHasError', 'getStockStateResult'])
370+
->setMethods(['setHasError', 'getStockStateResult', 'getProduct'])
364371
->getMock();
365372
$quoteItem = $this->getMockBuilder(Item::class)
366373
->disableOriginalConstructor()
@@ -369,6 +376,8 @@ public function testValidateAndRemoveErrorsFromQuote()
369376
$optionMock->expects($this->once())
370377
->method('getStockStateResult')
371378
->willReturn($this->resultMock);
379+
$optionMock->method('getProduct')
380+
->willReturn($this->productMock);
372381
$this->stockRegistryMock->expects($this->at(0))
373382
->method('getStockItem')
374383
->willReturn($this->stockItemMock);
@@ -544,6 +553,9 @@ private function createInitialStub($qty)
544553
->willReturn($this->resultMock);
545554
}
546555

556+
/**
557+
* @return void
558+
*/
547559
private function setUpStubForRemoveError()
548560
{
549561
$quoteItems = [$this->quoteItemMock];

app/code/Magento/Reports/Block/Adminhtml/Grid.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ protected function _prepareCollection()
127127
* Validate from and to date
128128
*/
129129
try {
130-
$from = $this->_localeDate->scopeDate(null, $this->getFilter('report_from'), false);
131-
$to = $this->_localeDate->scopeDate(null, $this->getFilter('report_to'), false);
130+
$from = $this->_localeDate->date($this->getFilter('report_from'), null, false, false);
131+
$to = $this->_localeDate->date($this->getFilter('report_to'), null, false, false);
132132

133133
$collection->setInterval($from, $to);
134134
} catch (\Exception $e) {

app/code/Magento/Swagger/view/frontend/web/swagger-ui/js/swagger-ui-bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/Swagger/view/frontend/web/swagger-ui/js/swagger-ui-standalone-preset.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)