@@ -36,24 +36,34 @@ class Stock extends \Magento\Framework\Data\Form\Element\Select
36
36
*/
37
37
protected $ _factoryText ;
38
38
39
+ /**
40
+ * Core registry
41
+ *
42
+ * @var \Magento\Framework\Registry
43
+ */
44
+ protected $ coreRegistry ;
45
+
39
46
/**
40
47
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
41
48
* @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
42
49
* @param \Magento\Framework\Escaper $escaper
43
50
* @param \Magento\Framework\Data\Form\Element\TextFactory $factoryText
51
+ * @param \Magento\Framework\Registry $coreRegistry
44
52
* @param array $data
45
53
*/
46
54
public function __construct (
47
55
\Magento \Framework \Data \Form \Element \Factory $ factoryElement ,
48
56
\Magento \Framework \Data \Form \Element \CollectionFactory $ factoryCollection ,
49
57
\Magento \Framework \Escaper $ escaper ,
50
58
\Magento \Framework \Data \Form \Element \TextFactory $ factoryText ,
59
+ \Magento \Framework \Registry $ coreRegistry ,
51
60
array $ data = []
52
61
) {
53
62
$ this ->_factoryText = $ factoryText ;
54
63
$ this ->_qty = isset ($ data ['qty ' ]) ? $ data ['qty ' ] : $ this ->_createQtyElement ();
55
64
unset($ data ['qty ' ]);
56
65
parent ::__construct ($ factoryElement , $ factoryCollection , $ escaper , $ data );
66
+ $ this ->coreRegistry = $ coreRegistry ;
57
67
$ this ->setName ($ data ['name ' ]);
58
68
}
59
69
@@ -164,6 +174,7 @@ protected function _disableFields()
164
174
*/
165
175
protected function _getJs ($ quantityFieldId , $ inStockFieldId )
166
176
{
177
+ $ isNewProduct = (int )$ this ->coreRegistry ->registry ('product ' )->isObjectNew ();
167
178
return "
168
179
<script type='text/javascript'>
169
180
require(['jquery', 'prototype', 'domReady!'], function($) {
@@ -184,7 +195,9 @@ protected function _getJs($quantityFieldId, $inStockFieldId)
184
195
var stockBeforeDisable = $.Event('stockbeforedisable', {productType: productType});
185
196
$('[data-tab-panel=product-details]').trigger(stockBeforeDisable);
186
197
if (stockBeforeDisable.result !== false) {
187
- var manageStockValue = (qty.val() === '') ? 0 : 1,
198
+ var manageStockValue = {$ isNewProduct }
199
+ ? (qty.val() === '' ? 0 : 1)
200
+ : parseInt(manageStockField.val()),
188
201
stockAssociations = $('#' + fieldsAssociations[' {$ inStockFieldId }']);
189
202
stockAvailabilityField.prop('disabled', !manageStockValue);
190
203
stockAssociations.prop('disabled', !manageStockValue);
0 commit comments