Skip to content

Commit

Permalink
FIX for MSI issue #74 on qty increment
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Apr 22, 2018
1 parent 169b3eb commit 6701e96
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getEnableQtyIncrements($storeId = null);

/**
* @param int $storeId
* @return int
* @return float
*/
public function getQtyIncrements($store = null);

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogInventory/Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function getEnableQtyIncrements($store = null)

/**
* @param null|string|bool|int|\Magento\Store\Model\Store $store
* @return int
* @return float
*/
public function getQtyIncrements($store = null)
{
Expand Down
10 changes: 8 additions & 2 deletions app/code/Magento/CatalogInventory/Model/Stock/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public function getUseConfigQtyIncrements()
/**
* Retrieve Quantity Increments
*
* @return int|false
* @return int|float|false
*/
public function getQtyIncrements()
{
Expand All @@ -401,7 +401,13 @@ public function getQtyIncrements()
if ($this->getUseConfigQtyIncrements()) {
$this->qtyIncrements = $this->stockConfiguration->getQtyIncrements($this->getStoreId());
} else {
$this->qtyIncrements = (int) $this->getData(static::QTY_INCREMENTS);
$this->qtyIncrements = $this->getData(static::QTY_INCREMENTS);
}

if ($this->getIsQtyDecimal()) { // Cast accordingly to decimal qty usage
$this->qtyIncrements = (float) $this->qtyIncrements;
} else {
$this->qtyIncrements = (int) $this->qtyIncrements;
}
}
if ($this->qtyIncrements <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ public function testGetQtyIncrements($config, $expected)
$this->setDataArrayValue('qty_increments', $config['qty_increments']);
$this->setDataArrayValue('enable_qty_increments', $config['enable_qty_increments']);
$this->setDataArrayValue('use_config_qty_increments', $config['use_config_qty_increments']);
$this->setDataArrayValue('is_qty_decimal', $config['is_qty_decimal']);
if ($config['use_config_qty_increments']) {
$this->stockConfiguration->expects($this->once())
->method('getQtyIncrements')
Expand All @@ -415,23 +416,44 @@ public function getQtyIncrementsDataProvider()
[
'qty_increments' => 1,
'enable_qty_increments' => true,
'use_config_qty_increments' => true
'use_config_qty_increments' => true,
'is_qty_decimal' => false,
],
1
],
[
[
'qty_increments' => 1.5,
'enable_qty_increments' => true,
'use_config_qty_increments' => true,
'is_qty_decimal' => true,
],
1.5
],
[
[
'qty_increments' => 1.5,
'enable_qty_increments' => true,
'use_config_qty_increments' => true,
'is_qty_decimal' => false,
],
1
],
[
[
'qty_increments' => -2,
'enable_qty_increments' => true,
'use_config_qty_increments' => true
'use_config_qty_increments' => true,
'is_qty_decimal' => false,
],
false
],
[
[
'qty_increments' => 3,
'enable_qty_increments' => true,
'use_config_qty_increments' => false
'use_config_qty_increments' => false,
'is_qty_decimal' => false,
],
3
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@
<settings>
<scopeLabel>[GLOBAL]</scopeLabel>
<validation>
<rule name="validate-digits" xsi:type="boolean">true</rule>
<rule name="validate-number" xsi:type="boolean">true</rule>
</validation>
<label translate="true">Qty Increments</label>
Expand Down

0 comments on commit 6701e96

Please sign in to comment.