Skip to content

Commit 5a1b7e0

Browse files
ihor-svizievDen4ik
andauthored
Add caching for product attributes used in sales rules
Apply suggestions from code review Co-authored-by: Denis Kopylov <dkopylov@magenius.team>
1 parent c9d250a commit 5a1b7e0

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

app/code/Magento/SalesRule/Model/Plugin/QuoteConfigProductAttributes.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class QuoteConfigProductAttributes
2222
/**
2323
* @var array|null
2424
*/
25-
private $activeAttributes;
25+
private $activeAttributeCodes;
2626

2727
/**
2828
* @param RuleResource $ruleResource
@@ -43,24 +43,18 @@ public function __construct(RuleResource $ruleResource)
4343
*/
4444
public function afterGetProductAttributes(Config $subject, array $attributeKeys): array
4545
{
46-
$attributes = $this->getActiveAttributes();
47-
48-
foreach ($attributes as $attribute) {
49-
$attributeKeys[] = $attribute['attribute_code'];
50-
}
51-
52-
return $attributeKeys;
46+
return array_merge($attributeKeys, $this->getActiveAttributeCodes());
5347
}
5448

5549
/**
5650
* @return array
5751
*/
58-
private function getActiveAttributes(): array
52+
private function getActiveAttributeCodes(): array
5953
{
60-
if ($this->activeAttributes === null) {
61-
$this->activeAttributes = $this->ruleResource->getActiveAttributes();
54+
if ($this->activeAttributeCodes === null) {
55+
$this->activeAttributeCodes = array_column($this->ruleResource->getActiveAttributes(), 'attribute_code');
6256
}
6357

64-
return $this->activeAttributes;
58+
return $this->activeAttributeCodes;
6559
}
6660
}

0 commit comments

Comments
 (0)