Skip to content

Commit 524aec6

Browse files
MAGETWO-64669: Performance degradation for bundle product if price view set as from..to
1 parent 7758a1f commit 524aec6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public function isVirtual($product)
344344
}
345345
}
346346

347-
return $virtualCount == count($selections);
347+
return $virtualCount === $selections->getSize();
348348
}
349349

350350
return false;
@@ -627,7 +627,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
627627
if (!empty($selectionIds)) {
628628
$selections = $this->getSelectionsByIds($selectionIds, $product);
629629

630-
if (count($selections->getItems()) !== count($selectionIds)) {
630+
if ($selections->getSize() !== count($selectionIds)) {
631631
throw new \Magento\Framework\Exception\LocalizedException(
632632
__('The options you selected are not available.')
633633
);
@@ -972,7 +972,7 @@ public function hasOptions($product)
972972
->getAllIds();
973973
$collection = $this->getSelectionsCollection($optionIds, $product);
974974

975-
if (count($collection) > 0 || $product->getOptions()) {
975+
if ($collection->getSize() > 0 || $product->getOptions()) {
976976
return true;
977977
}
978978

app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,14 @@ public function getOptions()
109109
*/
110110
public function getOptionSelectionAmount($selection)
111111
{
112-
$selectionPrice = $this->selectionFactory
113-
->create($this->product, $selection, $selection->getSelectionQty());
114-
return $selectionPrice->getAmount();
112+
$cacheKey = implode('_', [$this->product->getId(), $selection->getOptionId()]);
113+
if (!isset($this->optionSelecionAmountCache[$cacheKey])) {
114+
$selectionPrice = $this->selectionFactory
115+
->create($this->product, $selection, $selection->getSelectionQty());
116+
$this->optionSelecionAmountCache[$cacheKey] = $selectionPrice->getAmount();
117+
}
118+
119+
return $this->optionSelecionAmountCache[$cacheKey];
115120
}
116121

117122
/**

0 commit comments

Comments
 (0)