Skip to content

Commit 3dec663

Browse files
ENGCOM-3599: Fix mass product update with group min cart qty #19095
- Merge Pull Request #19095 from pmclain/magento2:issues/17592 - Merged commits: 1. cf383a9 2. e945ba0 3. b3a4058
2 parents 8e2ca94 + b3a4058 commit 3dec663

File tree

3 files changed

+69
-7
lines changed
  • app/code/Magento/Catalog

3 files changed

+69
-7
lines changed

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

Lines changed: 38 additions & 5 deletions
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,20 +31,29 @@ 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
3542
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
3643
* @param array $data
44+
* @param \Magento\Framework\Serialize\SerializerInterface|null $serializer
3745
*/
3846
public function __construct(
3947
\Magento\Backend\Block\Template\Context $context,
4048
\Magento\CatalogInventory\Model\Source\Backorders $backorders,
4149
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
42-
array $data = []
50+
array $data = [],
51+
\Magento\Framework\Serialize\SerializerInterface $serializer = null
4352
) {
4453
$this->_backorders = $backorders;
4554
$this->stockConfiguration = $stockConfiguration;
55+
$this->serializer = $serializer ?? \Magento\Framework\App\ObjectManager::getInstance()
56+
->get(\Magento\Framework\Serialize\SerializerInterface::class);
4657
parent::__construct($context, $data);
4758
}
4859

@@ -70,11 +81,13 @@ public function getFieldSuffix()
7081
* Retrieve current store id
7182
*
7283
* @return int
84+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
7385
*/
7486
public function getStoreId()
7587
{
76-
$storeId = $this->getRequest()->getParam('store');
77-
return (int) $storeId;
88+
$storeId = (int)$this->getRequest()->getParam('store');
89+
90+
return $storeId;
7891
}
7992

8093
/**
@@ -88,6 +101,22 @@ public function getDefaultConfigValue($field)
88101
return $this->stockConfiguration->getDefaultConfigValue($field);
89102
}
90103

104+
/**
105+
* Returns min_sale_qty configuration for the ALL Customer Group
106+
*
107+
* @return float
108+
*/
109+
public function getDefaultMinSaleQty()
110+
{
111+
$default = $this->stockConfiguration->getDefaultConfigValue('min_sale_qty');
112+
if (!is_numeric($default)) {
113+
$default = $this->serializer->unserialize($default);
114+
$default = $default[GroupInterface::CUST_GROUP_ALL] ?? 1;
115+
}
116+
117+
return (float) $default;
118+
}
119+
91120
/**
92121
* Tab settings
93122
*
@@ -99,6 +128,8 @@ public function getTabLabel()
99128
}
100129

101130
/**
131+
* Return Tab title.
132+
*
102133
* @return \Magento\Framework\Phrase
103134
*/
104135
public function getTabTitle()
@@ -107,22 +138,24 @@ public function getTabTitle()
107138
}
108139

109140
/**
110-
* @return bool
141+
* @inheritdoc
111142
*/
112143
public function canShowTab()
113144
{
114145
return true;
115146
}
116147

117148
/**
118-
* @return bool
149+
* @inheritdoc
119150
*/
120151
public function isHidden()
121152
{
122153
return false;
123154
}
124155

125156
/**
157+
* Get availability status.
158+
*
126159
* @param string $fieldName
127160
* @return bool
128161
* @SuppressWarnings(PHPMD.UnusedFormalParameter)

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)