Skip to content

Commit

Permalink
Merge remote-tracking branch 'mpi/MC-20225' into Chaika-PR-2019-09-26
Browse files Browse the repository at this point in the history
  • Loading branch information
veloraven committed Sep 26, 2019
2 parents cdb0e5f + b2a4ec9 commit acae330
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
* @since 101.0.0
*/
class Eav extends AbstractModifier
Expand Down Expand Up @@ -1048,6 +1049,10 @@ private function isScopeGlobal($attribute)
*/
private function getAttributeModel($attribute)
{
// The statement below solves performance issue related to loading same attribute options on different models
if ($attribute instanceof EavAttribute) {
return $attribute;
}
$attributeId = $attribute->getAttributeId();

if (!array_key_exists($attributeId, $this->attributesCache)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ protected function getAttributes()
foreach ($attributes as $key => $attribute) {
if (isset($configurableData[$key])) {
$attributes[$key] = array_replace_recursive($attribute, $configurableData[$key]);
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
$attributes[$key]['values'] = array_merge(
isset($attribute['values']) ? $attribute['values'] : [],
isset($configurableData[$key]['values'])
Expand Down Expand Up @@ -412,14 +413,15 @@ private function prepareAttributes(
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
'chosen' => [],
];
foreach ($attribute->getOptions() as $option) {
if (!empty($option->getValue())) {
$options = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : [];
foreach ($options as $option) {
if (!empty($option['value'])) {
$attributes[$attribute->getAttributeId()]['options'][] = [
'attribute_code' => $attribute->getAttributeCode(),
'attribute_label' => $attribute->getStoreLabel(0),
'id' => $option->getValue(),
'label' => $option->getLabel(),
'value' => $option->getValue(),
'id' => $option['value'],
'label' => $option['label'],
'value' => $option['value'],
'__disableTmpl' => true,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Magento\Framework\Escaper;

/**
* Associated products helper
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AssociatedProducts
Expand Down Expand Up @@ -231,6 +233,8 @@ public function getConfigurableAttributesData()
*
* @return void
* @throws \Zend_Currency_Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* phpcs:disable Generic.Metrics.NestingLevel
*/
protected function prepareVariations()
{
Expand Down Expand Up @@ -262,14 +266,15 @@ protected function prepareVariations()
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
'chosen' => [],
];
foreach ($attribute->getOptions() as $option) {
if (!empty($option->getValue())) {
$attributes[$attribute->getAttributeId()]['options'][$option->getValue()] = [
$options = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : [];
foreach ($options as $option) {
if (!empty($option['value'])) {
$attributes[$attribute->getAttributeId()]['options'][$option['value']] = [
'attribute_code' => $attribute->getAttributeCode(),
'attribute_label' => $attribute->getStoreLabel(0),
'id' => $option->getValue(),
'label' => $option->getLabel(),
'value' => $option->getValue(),
'id' => $option['value'],
'label' => $option['label'],
'value' => $option['value'],
];
}
}
Expand Down

0 comments on commit acae330

Please sign in to comment.