Skip to content

Commit 59f6edb

Browse files
committed
MAGETWO-86125: Sorting on price of configurable products in catalog not working properly
1 parent 718c71f commit 59f6edb

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

app/code/Magento/Config/Model/Config.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ public function save()
126126

127127
$oldConfig = $this->_getConfig(true);
128128

129-
$deleteTransaction = $this->_transactionFactory->create();
130129
/* @var $deleteTransaction \Magento\Framework\DB\Transaction */
131-
$saveTransaction = $this->_transactionFactory->create();
130+
$deleteTransaction = $this->_transactionFactory->create();
132131
/* @var $saveTransaction \Magento\Framework\DB\Transaction */
132+
$saveTransaction = $this->_transactionFactory->create();
133133

134134
$changedPaths = [];
135135
// Extends for old config data
@@ -144,9 +144,20 @@ public function save()
144144
$extraOldGroups,
145145
$oldConfig,
146146
$saveTransaction,
147-
$deleteTransaction,
148-
$changedPaths
147+
$deleteTransaction
149148
);
149+
150+
if (isset($groupData['fields'])) {
151+
$groupPath = $sectionId . '/' . $groupId;
152+
foreach ($groupData['fields'] as $fieldId => $fieldData) {
153+
/** @var $field \Magento\Config\Model\Config\Structure\Element\Field */
154+
$field = $this->_configStructure->getElement($groupPath . '/' . $fieldId);
155+
$path = $field->getGroupPath() . '/' . $fieldId;
156+
if ($this->isValueChanged($oldConfig, $path, $fieldData)) {
157+
$changedPaths[] = $path;
158+
}
159+
}
160+
}
150161
}
151162

152163
try {
@@ -174,6 +185,25 @@ public function save()
174185
return $this;
175186
}
176187

188+
/**
189+
* Check is config value changed
190+
*
191+
* @param array $oldConfig
192+
* @param string $path
193+
* @param array $fieldData
194+
* @return bool
195+
*/
196+
private function isValueChanged(array $oldConfig, string $path, array $fieldData)
197+
{
198+
if (isset($oldConfig[$path]['value'])) {
199+
$result = !isset($fieldData['value']) || $oldConfig[$path]['value'] !== $fieldData['value'];
200+
} else {
201+
$result = empty($fieldData['inherit']);
202+
}
203+
204+
return $result;
205+
}
206+
177207
/**
178208
* Process group data
179209
*
@@ -185,7 +215,6 @@ public function save()
185215
* @param array &$oldConfig
186216
* @param \Magento\Framework\DB\Transaction $saveTransaction
187217
* @param \Magento\Framework\DB\Transaction $deleteTransaction
188-
* @param array &$changedPaths
189218
* @return void
190219
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
191220
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -199,8 +228,7 @@ protected function _processGroup(
199228
array &$extraOldGroups,
200229
array &$oldConfig,
201230
\Magento\Framework\DB\Transaction $saveTransaction,
202-
\Magento\Framework\DB\Transaction $deleteTransaction,
203-
array &$changedPaths = []
231+
\Magento\Framework\DB\Transaction $deleteTransaction
204232
) {
205233
$groupPath = $sectionPath . '/' . $groupId;
206234
$scope = $this->getScope();
@@ -300,13 +328,9 @@ protected function _processGroup(
300328
} else {
301329
$deleteTransaction->addObject($backendModel);
302330
}
303-
if ($oldConfig[$path]['value'] !== $fieldData['value']) {
304-
$changedPaths[] = $path;
305-
}
306331
} elseif (!$inherit) {
307332
$backendModel->unsConfigId();
308333
$saveTransaction->addObject($backendModel);
309-
$changedPaths[] = $path;
310334
}
311335
}
312336
}
@@ -321,8 +345,7 @@ protected function _processGroup(
321345
$extraOldGroups,
322346
$oldConfig,
323347
$saveTransaction,
324-
$deleteTransaction,
325-
$changedPaths
348+
$deleteTransaction
326349
);
327350
}
328351
}

0 commit comments

Comments
 (0)