Skip to content

Commit ac51a3c

Browse files
committed
MAGETWO-91570: [2.2.x] - [Github]Can not save attribute #5907
1 parent 0857531 commit ac51a3c

File tree

2 files changed

+47
-4
lines changed
  • app/code/Magento/Catalog

2 files changed

+47
-4
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Save extends Attribute
6969
* @var LayoutFactory
7070
*/
7171
private $layoutFactory;
72+
7273
/**
7374
* @var Presentation
7475
*/
@@ -124,6 +125,7 @@ public function execute()
124125
{
125126
$data = $this->getRequest()->getPostValue();
126127
if ($data) {
128+
$this->extractOptionsData($data);
127129
$setId = $this->getRequest()->getParam('set');
128130

129131
$attributeSet = null;
@@ -315,6 +317,27 @@ public function execute()
315317
return $this->returnResult('catalog/*/', [], ['error' => true]);
316318
}
317319

320+
/**
321+
* Extract options data from serialized options field.
322+
* This logic is required to overcome max_input_vars php limit
323+
* that may vary and/or be inaccessible to change on different instances.
324+
*
325+
* @param array $data
326+
* @return void
327+
*/
328+
private function extractOptionsData(&$data)
329+
{
330+
if (isset($data['serialized_options'])) {
331+
unset($data['option']);
332+
$serializedOptions = json_decode($data['serialized_options'], JSON_OBJECT_AS_ARRAY);
333+
foreach ($serializedOptions as $serializedOption) {
334+
$option = [];
335+
parse_str($serializedOption, $option);
336+
$data = array_replace_recursive($data, $option);
337+
}
338+
}
339+
}
340+
318341
/**
319342
* @param string $path
320343
* @param array $params

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ define([
1313
'jquery/ui',
1414
'prototype',
1515
'form',
16-
'validation'
16+
'validation',
17+
'mage/translate'
1718
], function (jQuery, mageTemplate, rg) {
1819
'use strict';
1920

2021
return function (config) {
21-
var attributeOption = {
22+
var optionPanel = jQuery('#manage-options-panel'),
23+
optionsValues = [],
24+
editForm = jQuery('#edit_form'),
25+
attributeOption = {
2226
table: $('attribute-options-table'),
2327
itemCount: 0,
2428
totalItems: 0,
@@ -150,7 +154,7 @@ define([
150154
attributeOption.remove(event);
151155
});
152156

153-
jQuery('#manage-options-panel').on('render', function () {
157+
optionPanel.on('render', function () {
154158
attributeOption.ignoreValidate();
155159

156160
if (attributeOption.rendered) {
@@ -176,7 +180,23 @@ define([
176180
});
177181
});
178182
}
179-
183+
editForm.on('submit', function () {
184+
editForm
185+
.find('input[name^="option"]')
186+
.each(function() {
187+
optionsValues.push(this.name + '=' + jQuery(this).val());
188+
this.closest('tr').hide()
189+
});
190+
jQuery('<input>')
191+
.attr({
192+
type: 'hidden',
193+
name: 'serialized_options'
194+
})
195+
.val(JSON.stringify(optionsValues))
196+
.prependTo('#edit_form');
197+
optionPanel.find('table')
198+
.replaceWith(jQuery('<div>').text(jQuery.mage.__('Sending attribute values as package.')));
199+
});
180200
window.attributeOption = attributeOption;
181201
window.optionDefaultInputType = attributeOption.getOptionInputType();
182202

0 commit comments

Comments
 (0)