diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Inventory.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Inventory.php index 4aa01b467d451..01107412d1006 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Inventory.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Inventory.php @@ -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 * @@ -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 @@ -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); } @@ -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 * diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php index fb8a3d221b029..13e1b33a47d9a 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Edit\Action\Attribute\Tab; +use Magento\Customer\Api\Data\GroupInterface; + /** * Class InventoryTest */ @@ -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(), ] ); } @@ -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 * diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/action/inventory.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/action/inventory.phtml index efc06d675c369..96e07ceb4d305 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/action/inventory.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/action/inventory.phtml @@ -132,7 +132,7 @@