Skip to content

Commit d3c682e

Browse files
committed
MAGETWO-91570: [2.2.x] - [Github]Can not save attribute #5907
- swatches fix
1 parent 18cb5bd commit d3c682e

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,17 @@ define([
182182
}
183183
editForm.on('submit', function () {
184184
editForm
185-
.find('input[name^="option"]')
185+
.find('#manage-options-panel input[name^="option"]')
186186
.each(function() {
187187
optionsValues.push(this.name + '=' + jQuery(this).val());
188-
this.closest('tr').hide()
189188
});
190189
jQuery('<input>')
191190
.attr({
192191
type: 'hidden',
193192
name: 'serialized_options'
194193
})
195194
.val(JSON.stringify(optionsValues))
196-
.prependTo('#edit_form');
195+
.prependTo(editForm);
197196
optionPanel.find('table')
198197
.replaceWith(jQuery('<div>').text(jQuery.mage.__('Sending attribute values as package.')));
199198
});

app/code/Magento/Swatches/Controller/Adminhtml/Product/Attribute/Plugin/Save.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Save
2424
public function beforeDispatch(Attribute\Save $subject, RequestInterface $request)
2525
{
2626
$data = $request->getPostValue();
27+
$data['serialized_options'] = $data['serialized_swatch_values'];
28+
unset($data['serialized_swatch_values']);
2729
if (isset($data['frontend_input'])) {
2830
switch ($data['frontend_input']) {
2931
case 'swatch_visual':

app/code/Magento/Swatches/view/adminhtml/web/js/product-attributes.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ define([
414414
};
415415

416416
$(function () {
417+
var editForm = $('#edit_form');
417418
$('#frontend_input').bind('change', function () {
418419
swatchProductAttributes.bindAttributeInputType();
419420
});
@@ -427,6 +428,34 @@ define([
427428
$('.attribute-popup .collapse, [data-role="advanced_fieldset-content"]')
428429
.collapsable()
429430
.collapse('hide');
431+
432+
editForm.on('submit', function () {
433+
var activePanel,
434+
swatchValues = [],
435+
swatchVisualPanel = $('#swatch-visual-options-panel'),
436+
swatchTextPanel = $('#swatch-text-options-panel');
437+
438+
activePanel = swatchTextPanel.is(":visible") ? swatchTextPanel : swatchVisualPanel;
439+
440+
activePanel
441+
.find('table input')
442+
.each(function() {
443+
swatchValues.push(this.name + '=' + $(this).val());
444+
});
445+
446+
$('<input>')
447+
.attr({
448+
type: 'hidden',
449+
name: 'serialized_swatch_values'
450+
})
451+
.val(JSON.stringify(swatchValues))
452+
.prependTo(editForm);
453+
454+
[swatchVisualPanel, swatchTextPanel].forEach(function(el) {
455+
$(el).find('table')
456+
.replaceWith($('<div>').text($.mage.__('Sending swatch values as package.')));
457+
});
458+
});
430459
});
431460

432461
window.saveAttributeInNewSet = swatchProductAttributes.saveAttributeInNewSet;

0 commit comments

Comments
 (0)