Skip to content

Commit

Permalink
Fix mass product update with group min cart qty
Browse files Browse the repository at this point in the history
Resolves warning when using the product edit mass-action after configuring
global group cart min qty

Fixes magento#17592
  • Loading branch information
pmclain committed Nov 15, 2018
1 parent 8cc960c commit cf383a9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Edit\Action\Attribute\Tab;

use Magento\Customer\Api\Data\GroupInterface;

/**
* Products mass update inventory tab
*
Expand All @@ -29,6 +31,11 @@ class Inventory extends \Magento\Backend\Block\Widget implements \Magento\Backen
*/
protected $disabledFields = [];

/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\CatalogInventory\Model\Source\Backorders $backorders
Expand All @@ -39,10 +46,13 @@ public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\CatalogInventory\Model\Source\Backorders $backorders,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
array $data = []
array $data = [],
\Magento\Framework\Serialize\SerializerInterface $serializer = null
) {
$this->_backorders = $backorders;
$this->stockConfiguration = $stockConfiguration;
$this->serializer = $serializer ?? \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\SerializerInterface::class);
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -88,6 +98,21 @@ public function getDefaultConfigValue($field)
return $this->stockConfiguration->getDefaultConfigValue($field);
}

/**
* Returns min_sale_qty configuration for the ALL Customer Group
* @return int
*/
public function getDefaultMinSaleQty()
{
$default = $this->stockConfiguration->getDefaultConfigValue('min_sale_qty');
if (!is_numeric($default)) {
$default = $this->serializer->unserialize($default);
$default = isset($default[GroupInterface::CUST_GROUP_ALL]) ? $default[GroupInterface::CUST_GROUP_ALL] : 1;
}

return (int) $default;
}

/**
* Tab settings
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Edit\Action\Attribute\Tab;

use Magento\Customer\Api\Data\GroupInterface;

/**
* Class InventoryTest
*/
Expand Down Expand Up @@ -68,7 +70,8 @@ protected function setUp()
[
'context' => $this->contextMock,
'backorders' => $this->backordersMock,
'stockConfiguration' => $this->stockConfigurationMock
'stockConfiguration' => $this->stockConfigurationMock,
'serializer' => new \Magento\Framework\Serialize\Serializer\Json(),
]
);
}
Expand Down Expand Up @@ -126,6 +129,32 @@ public function testGetDefaultConfigValue()
$this->assertEquals('return-value', $this->inventory->getDefaultConfigValue('field-name'));
}

/**
* @dataProvider getDefaultMinSaleQtyDataProvider
* @param string $expected
* @param string $default
*/
public function testGetDefaultMinSaleQty($expected, $default)
{
$this->stockConfigurationMock->method('getDefaultConfigValue')->willReturn($default);
$this->assertEquals($expected, $this->inventory->getDefaultMinSaleQty());
}

public function getDefaultMinSaleQtyDataProvider()
{
return [
'single-default-value' => [
22, '22'
],
'no-default-for-all-group' => [
1, json_encode(['12' => '111'])
],
'default-for-all-group' => [
5, json_encode(['12' => '111', GroupInterface::CUST_GROUP_ALL => '5'])
]
];
}

/**
* Run test getTabLabel method
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<div class="field">
<input type="text" class="input-text validate-number" id="inventory_min_sale_qty"
name="<?= /* @escapeNotVerified */ $block->getFieldSuffix() ?>[min_sale_qty]"
value="<?= /* @escapeNotVerified */ $block->getDefaultConfigValue('min_sale_qty') * 1 ?>"
value="<?= /* @escapeNotVerified */ $block->getDefaultMinSaleQty() * 1 ?>"
disabled="disabled"/>
</div>
<div class="field choice">
Expand Down

0 comments on commit cf383a9

Please sign in to comment.