Skip to content

Commit c9d250a

Browse files
authored
Add caching for product attributes used in sales rules
1 parent 3c5ff49 commit c9d250a

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
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

1012
/**
@@ -15,31 +17,50 @@ class QuoteConfigProductAttributes
1517
/**
1618
* @var RuleResource
1719
*/
18-
protected $_ruleResource;
20+
private $ruleResource;
21+
22+
/**
23+
* @var array|null
24+
*/
25+
private $activeAttributes;
1926

2027
/**
2128
* @param RuleResource $ruleResource
2229
*/
2330
public function __construct(RuleResource $ruleResource)
2431
{
25-
$this->_ruleResource = $ruleResource;
32+
$this->ruleResource = $ruleResource;
2633
}
2734

2835
/**
2936
* Append sales rule product attribute keys to select by quote item collection
3037
*
31-
* @param \Magento\Quote\Model\Quote\Config $subject
38+
* @param Config $subject
3239
* @param array $attributeKeys
3340
*
3441
* @return array
3542
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3643
*/
37-
public function afterGetProductAttributes(\Magento\Quote\Model\Quote\Config $subject, array $attributeKeys)
44+
public function afterGetProductAttributes(Config $subject, array $attributeKeys): array
3845
{
39-
$attributes = $this->_ruleResource->getActiveAttributes();
46+
$attributes = $this->getActiveAttributes();
47+
4048
foreach ($attributes as $attribute) {
4149
$attributeKeys[] = $attribute['attribute_code'];
4250
}
51+
4352
return $attributeKeys;
4453
}
54+
55+
/**
56+
* @return array
57+
*/
58+
private function getActiveAttributes(): array
59+
{
60+
if ($this->activeAttributes === null) {
61+
$this->activeAttributes = $this->ruleResource->getActiveAttributes();
62+
}
63+
64+
return $this->activeAttributes;
65+
}
4566
}

0 commit comments

Comments
 (0)