Skip to content

Commit cdf9ba3

Browse files
authored
ENGCOM-9159: Add caching for product attributes used in sales rules #33537
2 parents 4a125b0 + 479f7d3 commit cdf9ba3

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,47 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\SalesRule\Model\Plugin;
78

9+
use Magento\Quote\Model\Quote\Config;
810
use Magento\SalesRule\Model\ResourceModel\Rule as RuleResource;
911

10-
/**
11-
* Quote Config Product Attributes Class
12-
*/
1312
class QuoteConfigProductAttributes
1413
{
1514
/**
1615
* @var RuleResource
1716
*/
18-
protected $_ruleResource;
17+
private $ruleResource;
18+
19+
/**
20+
* @var array|null
21+
*/
22+
private $activeAttributeCodes;
1923

2024
/**
2125
* @param RuleResource $ruleResource
2226
*/
2327
public function __construct(RuleResource $ruleResource)
2428
{
25-
$this->_ruleResource = $ruleResource;
29+
$this->ruleResource = $ruleResource;
2630
}
2731

2832
/**
2933
* Append sales rule product attribute keys to select by quote item collection
3034
*
31-
* @param \Magento\Quote\Model\Quote\Config $subject
35+
* @param Config $subject
3236
* @param array $attributeKeys
3337
*
3438
* @return array
3539
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3640
*/
37-
public function afterGetProductAttributes(\Magento\Quote\Model\Quote\Config $subject, array $attributeKeys)
41+
public function afterGetProductAttributes(Config $subject, array $attributeKeys): array
3842
{
39-
$attributes = $this->_ruleResource->getActiveAttributes();
40-
foreach ($attributes as $attribute) {
41-
$attributeKeys[] = $attribute['attribute_code'];
43+
if ($this->activeAttributeCodes === null) {
44+
$this->activeAttributeCodes = array_column($this->ruleResource->getActiveAttributes(), 'attribute_code');
4245
}
43-
return $attributeKeys;
46+
47+
return array_merge($attributeKeys, $this->activeAttributeCodes);
4448
}
4549
}

0 commit comments

Comments
 (0)