Skip to content

Commit aaf37c1

Browse files
author
Michail Slabko
committed
MAGETWO-43780: [GITHUB] 'Manage Stock' option with 'No' value is not saved if change it for existing product
1 parent 4985ace commit aaf37c1

File tree

1 file changed

+14
-1
lines changed
  • app/code/Magento/CatalogInventory/Block/Adminhtml/Form/Field

1 file changed

+14
-1
lines changed

app/code/Magento/CatalogInventory/Block/Adminhtml/Form/Field/Stock.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,34 @@ class Stock extends \Magento\Framework\Data\Form\Element\Select
3636
*/
3737
protected $_factoryText;
3838

39+
/**
40+
* Core registry
41+
*
42+
* @var \Magento\Framework\Registry
43+
*/
44+
protected $coreRegistry;
45+
3946
/**
4047
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
4148
* @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
4249
* @param \Magento\Framework\Escaper $escaper
4350
* @param \Magento\Framework\Data\Form\Element\TextFactory $factoryText
51+
* @param \Magento\Framework\Registry $coreRegistry
4452
* @param array $data
4553
*/
4654
public function __construct(
4755
\Magento\Framework\Data\Form\Element\Factory $factoryElement,
4856
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
4957
\Magento\Framework\Escaper $escaper,
5058
\Magento\Framework\Data\Form\Element\TextFactory $factoryText,
59+
\Magento\Framework\Registry $coreRegistry,
5160
array $data = []
5261
) {
5362
$this->_factoryText = $factoryText;
5463
$this->_qty = isset($data['qty']) ? $data['qty'] : $this->_createQtyElement();
5564
unset($data['qty']);
5665
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
66+
$this->coreRegistry = $coreRegistry;
5767
$this->setName($data['name']);
5868
}
5969

@@ -164,6 +174,7 @@ protected function _disableFields()
164174
*/
165175
protected function _getJs($quantityFieldId, $inStockFieldId)
166176
{
177+
$isNewProduct = (int)$this->coreRegistry->registry('product')->isObjectNew();
167178
return "
168179
<script type='text/javascript'>
169180
require(['jquery', 'prototype', 'domReady!'], function($) {
@@ -184,7 +195,9 @@ protected function _getJs($quantityFieldId, $inStockFieldId)
184195
var stockBeforeDisable = $.Event('stockbeforedisable', {productType: productType});
185196
$('[data-tab-panel=product-details]').trigger(stockBeforeDisable);
186197
if (stockBeforeDisable.result !== false) {
187-
var manageStockValue = (qty.val() === '') ? 0 : 1,
198+
var manageStockValue = {$isNewProduct}
199+
? (qty.val() === '' ? 0 : 1)
200+
: parseInt(manageStockField.val()),
188201
stockAssociations = $('#' + fieldsAssociations['{$inStockFieldId}']);
189202
stockAvailabilityField.prop('disabled', !manageStockValue);
190203
stockAssociations.prop('disabled', !manageStockValue);

0 commit comments

Comments
 (0)