Skip to content

Commit 6701e96

Browse files
committed
FIX for MSI issue #74 on qty increment
magento/inventory#774
1 parent 169b3eb commit 6701e96

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

app/code/Magento/CatalogInventory/Api/StockConfigurationInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getEnableQtyIncrements($storeId = null);
7777

7878
/**
7979
* @param int $storeId
80-
* @return int
80+
* @return float
8181
*/
8282
public function getQtyIncrements($store = null);
8383

app/code/Magento/CatalogInventory/Model/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function getEnableQtyIncrements($store = null)
273273

274274
/**
275275
* @param null|string|bool|int|\Magento\Store\Model\Store $store
276-
* @return int
276+
* @return float
277277
*/
278278
public function getQtyIncrements($store = null)
279279
{

app/code/Magento/CatalogInventory/Model/Stock/Item.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public function getUseConfigQtyIncrements()
392392
/**
393393
* Retrieve Quantity Increments
394394
*
395-
* @return int|false
395+
* @return int|float|false
396396
*/
397397
public function getQtyIncrements()
398398
{
@@ -401,7 +401,13 @@ public function getQtyIncrements()
401401
if ($this->getUseConfigQtyIncrements()) {
402402
$this->qtyIncrements = $this->stockConfiguration->getQtyIncrements($this->getStoreId());
403403
} else {
404-
$this->qtyIncrements = (int) $this->getData(static::QTY_INCREMENTS);
404+
$this->qtyIncrements = $this->getData(static::QTY_INCREMENTS);
405+
}
406+
407+
if ($this->getIsQtyDecimal()) { // Cast accordingly to decimal qty usage
408+
$this->qtyIncrements = (float) $this->qtyIncrements;
409+
} else {
410+
$this->qtyIncrements = (int) $this->qtyIncrements;
405411
}
406412
}
407413
if ($this->qtyIncrements <= 0) {

app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ public function testGetQtyIncrements($config, $expected)
394394
$this->setDataArrayValue('qty_increments', $config['qty_increments']);
395395
$this->setDataArrayValue('enable_qty_increments', $config['enable_qty_increments']);
396396
$this->setDataArrayValue('use_config_qty_increments', $config['use_config_qty_increments']);
397+
$this->setDataArrayValue('is_qty_decimal', $config['is_qty_decimal']);
397398
if ($config['use_config_qty_increments']) {
398399
$this->stockConfiguration->expects($this->once())
399400
->method('getQtyIncrements')
@@ -415,23 +416,44 @@ public function getQtyIncrementsDataProvider()
415416
[
416417
'qty_increments' => 1,
417418
'enable_qty_increments' => true,
418-
'use_config_qty_increments' => true
419+
'use_config_qty_increments' => true,
420+
'is_qty_decimal' => false,
421+
],
422+
1
423+
],
424+
[
425+
[
426+
'qty_increments' => 1.5,
427+
'enable_qty_increments' => true,
428+
'use_config_qty_increments' => true,
429+
'is_qty_decimal' => true,
430+
],
431+
1.5
432+
],
433+
[
434+
[
435+
'qty_increments' => 1.5,
436+
'enable_qty_increments' => true,
437+
'use_config_qty_increments' => true,
438+
'is_qty_decimal' => false,
419439
],
420440
1
421441
],
422442
[
423443
[
424444
'qty_increments' => -2,
425445
'enable_qty_increments' => true,
426-
'use_config_qty_increments' => true
446+
'use_config_qty_increments' => true,
447+
'is_qty_decimal' => false,
427448
],
428449
false
429450
],
430451
[
431452
[
432453
'qty_increments' => 3,
433454
'enable_qty_increments' => true,
434-
'use_config_qty_increments' => false
455+
'use_config_qty_increments' => false,
456+
'is_qty_decimal' => false,
435457
],
436458
3
437459
],

app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@
568568
<settings>
569569
<scopeLabel>[GLOBAL]</scopeLabel>
570570
<validation>
571-
<rule name="validate-digits" xsi:type="boolean">true</rule>
572571
<rule name="validate-number" xsi:type="boolean">true</rule>
573572
</validation>
574573
<label translate="true">Qty Increments</label>

0 commit comments

Comments
 (0)