Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit cf383a9

Browse files
committed
Fix mass product update with group min cart qty
Resolves warning when using the product edit mass-action after configuring global group cart min qty Fixes #17592
1 parent 8cc960c commit cf383a9

File tree

3 files changed

+57
-3
lines changed
  • app/code/Magento/Catalog

3 files changed

+57
-3
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Inventory.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Block\Adminhtml\Product\Edit\Action\Attribute\Tab;
77

8+
use Magento\Customer\Api\Data\GroupInterface;
9+
810
/**
911
* Products mass update inventory tab
1012
*
@@ -29,6 +31,11 @@ class Inventory extends \Magento\Backend\Block\Widget implements \Magento\Backen
2931
*/
3032
protected $disabledFields = [];
3133

34+
/**
35+
* @var \Magento\Framework\Serialize\SerializerInterface
36+
*/
37+
private $serializer;
38+
3239
/**
3340
* @param \Magento\Backend\Block\Template\Context $context
3441
* @param \Magento\CatalogInventory\Model\Source\Backorders $backorders
@@ -39,10 +46,13 @@ public function __construct(
3946
\Magento\Backend\Block\Template\Context $context,
4047
\Magento\CatalogInventory\Model\Source\Backorders $backorders,
4148
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
42-
array $data = []
49+
array $data = [],
50+
\Magento\Framework\Serialize\SerializerInterface $serializer = null
4351
) {
4452
$this->_backorders = $backorders;
4553
$this->stockConfiguration = $stockConfiguration;
54+
$this->serializer = $serializer ?? \Magento\Framework\App\ObjectManager::getInstance()
55+
->get(\Magento\Framework\Serialize\SerializerInterface::class);
4656
parent::__construct($context, $data);
4757
}
4858

@@ -88,6 +98,21 @@ public function getDefaultConfigValue($field)
8898
return $this->stockConfiguration->getDefaultConfigValue($field);
8999
}
90100

101+
/**
102+
* Returns min_sale_qty configuration for the ALL Customer Group
103+
* @return int
104+
*/
105+
public function getDefaultMinSaleQty()
106+
{
107+
$default = $this->stockConfiguration->getDefaultConfigValue('min_sale_qty');
108+
if (!is_numeric($default)) {
109+
$default = $this->serializer->unserialize($default);
110+
$default = isset($default[GroupInterface::CUST_GROUP_ALL]) ? $default[GroupInterface::CUST_GROUP_ALL] : 1;
111+
}
112+
113+
return (int) $default;
114+
}
115+
91116
/**
92117
* Tab settings
93118
*

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Edit\Action\Attribute\Tab;
77

8+
use Magento\Customer\Api\Data\GroupInterface;
9+
810
/**
911
* Class InventoryTest
1012
*/
@@ -68,7 +70,8 @@ protected function setUp()
6870
[
6971
'context' => $this->contextMock,
7072
'backorders' => $this->backordersMock,
71-
'stockConfiguration' => $this->stockConfigurationMock
73+
'stockConfiguration' => $this->stockConfigurationMock,
74+
'serializer' => new \Magento\Framework\Serialize\Serializer\Json(),
7275
]
7376
);
7477
}
@@ -126,6 +129,32 @@ public function testGetDefaultConfigValue()
126129
$this->assertEquals('return-value', $this->inventory->getDefaultConfigValue('field-name'));
127130
}
128131

132+
/**
133+
* @dataProvider getDefaultMinSaleQtyDataProvider
134+
* @param string $expected
135+
* @param string $default
136+
*/
137+
public function testGetDefaultMinSaleQty($expected, $default)
138+
{
139+
$this->stockConfigurationMock->method('getDefaultConfigValue')->willReturn($default);
140+
$this->assertEquals($expected, $this->inventory->getDefaultMinSaleQty());
141+
}
142+
143+
public function getDefaultMinSaleQtyDataProvider()
144+
{
145+
return [
146+
'single-default-value' => [
147+
22, '22'
148+
],
149+
'no-default-for-all-group' => [
150+
1, json_encode(['12' => '111'])
151+
],
152+
'default-for-all-group' => [
153+
5, json_encode(['12' => '111', GroupInterface::CUST_GROUP_ALL => '5'])
154+
]
155+
];
156+
}
157+
129158
/**
130159
* Run test getTabLabel method
131160
*

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/action/inventory.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
<div class="field">
133133
<input type="text" class="input-text validate-number" id="inventory_min_sale_qty"
134134
name="<?= /* @escapeNotVerified */ $block->getFieldSuffix() ?>[min_sale_qty]"
135-
value="<?= /* @escapeNotVerified */ $block->getDefaultConfigValue('min_sale_qty') * 1 ?>"
135+
value="<?= /* @escapeNotVerified */ $block->getDefaultMinSaleQty() * 1 ?>"
136136
disabled="disabled"/>
137137
</div>
138138
<div class="field choice">

0 commit comments

Comments
 (0)