Skip to content

Commit 9d7561b

Browse files
ENGCOM-4085: Improve bundle load speeds #20877
- Merge Pull Request #20877 from thlassche/magento2:2.3-develop - Merged commits: 1. baf3cf0 2. 5b99562 3. f6d4575 4. f9595df 5. 75665aa
2 parents ef49ac6 + 75665aa commit 9d7561b

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

app/code/Magento/Tax/Observer/GetPriceConfigurationObserver.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class GetPriceConfigurationObserver implements ObserverInterface
2323
*/
2424
protected $registry;
2525

26+
/**
27+
* @var array Cache of the current bundle selection items
28+
*/
29+
private $selectionCache = [];
30+
2631
/**
2732
* @param \Magento\Framework\Registry $registry
2833
* @param \Magento\Tax\Helper\Data $taxData
@@ -44,6 +49,7 @@ public function __construct(
4449
*/
4550
public function execute(\Magento\Framework\Event\Observer $observer)
4651
{
52+
$this->selectionCache = [];
4753
if ($this->taxData->displayPriceIncludingTax()) {
4854
/** @var \Magento\Catalog\Model\Product $product */
4955
$product = $this->registry->registry('current_product');
@@ -107,15 +113,19 @@ private function updatePriceForBundle($holder, $key)
107113
/** @var \Magento\Catalog\Model\Product $product */
108114
$product = $this->registry->registry('current_product');
109115
if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
110-
$typeInstance = $product->getTypeInstance();
111-
$typeInstance->setStoreFilter($product->getStoreId(), $product);
116+
if (!isset($this->selectionCache[$product->getId()])) {
117+
$typeInstance = $product->getTypeInstance();
118+
$typeInstance->setStoreFilter($product->getStoreId(), $product);
112119

113-
$selectionCollection = $typeInstance->getSelectionsCollection(
114-
$typeInstance->getOptionsIds($product),
115-
$product
116-
);
120+
$selectionCollection = $typeInstance->getSelectionsCollection(
121+
$typeInstance->getOptionsIds($product),
122+
$product
123+
);
124+
$this->selectionCache[$product->getId()] = $selectionCollection->getItems();
125+
}
126+
$arrSelections = $this->selectionCache[$product->getId()];
117127

118-
foreach ($selectionCollection->getItems() as $selectionItem) {
128+
foreach ($arrSelections as $selectionItem) {
119129
if ($holder['optionId'] == $selectionItem->getId()) {
120130
/** @var \Magento\Framework\Pricing\Amount\Base $baseAmount */
121131
$baseAmount = $selectionItem->getPriceInfo()->getPrice(BasePrice::PRICE_CODE)->getAmount();

app/code/Magento/Tax/Test/Unit/Observer/GetPriceConfigurationObserverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testExecute($testArray, $expectedArray)
118118

119119
$product = $this->createPartialMock(
120120
\Magento\Bundle\Model\Product\Type::class,
121-
['getTypeInstance', 'getTypeId', 'getStoreId', 'getSelectionsCollection']
121+
['getTypeInstance', 'getTypeId', 'getStoreId', 'getSelectionsCollection', 'getId']
122122
);
123123
$product->expects($this->any())
124124
->method('getTypeInstance')

0 commit comments

Comments
 (0)