Skip to content

Commit e800256

Browse files
committed
ACP2E-3523: Issue with Default Attribute Option Value Behavior for Multiselect
1 parent 0f13c20 commit e800256

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ public function execute()
272272
if (array_key_exists('reset_is-default_option', $data) && $data['reset_is-default_option']) {
273273
unset($data['reset_is-default_option']);
274274
$data['default_value'] = null;
275+
} else {
276+
$data['default_value'] = implode(",", $data['default']);
275277
}
276278

277279
$model->addData($data);

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/js.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ script;
259259
setRowVisibility('default_value_yesno', defaultValueYesnoVisibility);
260260
setRowVisibility('is_global', scopeVisibility);
261261
262-
var elems = document.getElementsByName('default[]');
262+
var elems = document.querySelectorAll('input[name^="default["]');
263263
for (var i = 0; i < elems.length; i++) {
264264
elems[i].type = optionDefaultInputType;
265265
}

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $stores = $block->getStoresSortedBySortOrder();
7878
<input data-role="order" type="hidden" name="option[order][<%- data.id %>]" value="<%- data.sort_order %>" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()):?> disabled="disabled"<?php endif; ?>/>
7979
</td>
8080
<td class="col-default control-table-actions-cell">
81-
<input class="input-radio" type="<%- data.intype %>" name="default[]" value="<%- data.id %>" <%- data.checked %><?php if ($block->getReadOnly()):?>disabled="disabled"<?php endif;?>/>
81+
<input class="input-radio" type="<%- data.intype %>" name="default[<%- data.id %>]" value="<%- data.id %>" <%- data.checked %><?php if ($block->getReadOnly()):?>disabled="disabled"<?php endif;?>/>
8282
</td>
8383
<?php foreach ($stores as $_store):?>
8484
<td class="col-<%- data.id %>"><input name="option[value][<%- data.id %>][<?= (int) $_store->getId() ?>]" value="<%- data.store<?= /* @noEscape */ (int) $_store->getId() ?> %>" class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID):?> required-option required-unique<?php endif; ?>" type="text" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()):?> disabled="disabled"<?php endif;?>/></td>

app/code/Magento/Catalog/view/adminhtml/web/js/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ define([
9595
}
9696
},
9797
reset: function () {
98-
jQuery('input[name="default[]"]').prop('checked', false);
98+
jQuery('input[name^="default["]').prop('checked', false);
9999
jQuery('input[name="reset_is-default_option"]').val(1);
100100
},
101101

app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ protected function _saveOption(AbstractModel $object)
400400
}
401401

402402
if ($object->getDefaultValue()) {
403-
$defaultValue[] = $object->getDefaultValue();
403+
$defaultValue = array_unique(array_merge($defaultValue, explode(",", $object->getDefaultValue())));
404404
}
405405

406406
$this->_saveDefaultValue($object, $defaultValue);

0 commit comments

Comments
 (0)