Skip to content

Commit 5f82777

Browse files
committed
MAGETWO-55729: [Customer] Optimize performance for bundled products with lots of product options
- MAGETWO-60467: Simple product name not displayed as options on product page
1 parent 0a0da3e commit 5f82777

File tree

5 files changed

+13
-41
lines changed

5 files changed

+13
-41
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function addQuantityFilter()
177177
*/
178178
public function getNewEmptyItem()
179179
{
180-
if ($this->itemPrototype == null) {
180+
if (null === $this->itemPrototype) {
181181
$this->itemPrototype = parent::getNewEmptyItem();
182182
}
183183
return clone $this->itemPrototype;
@@ -200,7 +200,7 @@ public function addPriceFilter($product, $searchMin, $useRegularPrice = false)
200200
$minimalPriceExpression = 'minimal_price';
201201
} else {
202202
$this->getCatalogRuleProcessor()->addPriceData($this, 'selection.product_id');
203-
$minimalPriceExpression = 'LEAST(minimal_price, IFNULL(catalog_rule_price, 99999999))';
203+
$minimalPriceExpression = 'LEAST(minimal_price, IFNULL(catalog_rule_price, minimal_price))';
204204
}
205205
$orderByValue = new \Zend_Db_Expr(
206206
'(' .

app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\Bundle\Model\Product\Price;
1010
use Magento\Bundle\Pricing\Price\BundleSelectionFactory;
1111
use Magento\Catalog\Model\Product;
12-
use Magento\Framework\App\ObjectManager;
1312
use Magento\Framework\Pricing\Adjustment\Calculator as CalculatorBase;
1413
use Magento\Framework\Pricing\Amount\AmountFactory;
1514
use Magento\Framework\Pricing\SaleableInterface;
@@ -199,23 +198,24 @@ protected function getSelectionAmounts(Product $bundleProduct, $searchMin, $useR
199198
}
200199
$canSkipRequiredOptions = $searchMin && !$shouldFindMinOption;
201200

201+
/** @var \Magento\Bundle\Model\Product\Type $typeInstance */
202+
$typeInstance = $bundleProduct->getTypeInstance();
202203
$priceList = [];
204+
203205
foreach ($this->getBundleOptions($bundleProduct) as $option) {
204206
/** @var \Magento\Bundle\Model\Option $option */
205207
if ($this->canSkipOption($option, $canSkipRequiredOptions)) {
206208
continue;
207209
}
208210

209-
/** @var \Magento\Bundle\Model\Product\Type $typeInstance */
210-
$typeInstance = $bundleProduct->getTypeInstance();
211211
$selectionsCollection = $typeInstance->getSelectionsCollection(
212212
[(int)$option->getOptionId()],
213213
$bundleProduct
214214
);
215215
$selectionsCollection->removeAttributeToSelect();
216216
$selectionsCollection->addQuantityFilter();
217217

218-
if ($option->isMultiSelection() && !$searchMin) {
218+
if (!$searchMin && $option->isMultiSelection()) {
219219
$selectionsCollection->addPriceData();
220220

221221
foreach ($selectionsCollection as $selection) {
@@ -278,7 +278,7 @@ protected function getSelectionAmounts(Product $bundleProduct, $searchMin, $useR
278278
*/
279279
protected function canSkipOption($option, $canSkipRequiredOption)
280280
{
281-
return ($canSkipRequiredOption && !$option->getRequired());
281+
return $canSkipRequiredOption && !$option->getRequired();
282282
}
283283

284284
/**
@@ -289,9 +289,9 @@ protected function canSkipOption($option, $canSkipRequiredOption)
289289
*/
290290
protected function hasRequiredOption($bundleProduct)
291291
{
292-
/** @var \Magento\Bundle\Model\Product\Type $typeInstance */
293-
$typeInstance = $bundleProduct->getTypeInstance();
294-
$collection = $typeInstance->getOptionsCollection($bundleProduct);
292+
$collection = clone $this->getBundleOptions($bundleProduct);
293+
$collection->clear();
294+
295295
return $collection->addFilter(\Magento\Bundle\Model\Option::KEY_REQUIRED, 1)->getSize() > 0;
296296
}
297297

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan
4242
* @param Product $selection
4343
* @param float $quantity
4444
* @param array $arguments
45-
* @throws \InvalidArgumentException
4645
* @return BundleSelectionPrice
4746
*/
4847
public function create(
@@ -54,12 +53,7 @@ public function create(
5453
$arguments['bundleProduct'] = $bundleProduct;
5554
$arguments['saleableItem'] = $selection;
5655
$arguments['quantity'] = $quantity ? floatval($quantity) : 1.;
57-
$selectionPrice = $this->objectManager->create(self::SELECTION_CLASS_DEFAULT, $arguments);
58-
if (!$selectionPrice instanceof BundleSelectionPrice) {
59-
throw new \InvalidArgumentException(
60-
get_class($selectionPrice) . ' doesn\'t extend BundleSelectionPrice'
61-
);
62-
}
63-
return $selectionPrice;
56+
57+
return $this->objectManager->create(self::SELECTION_CLASS_DEFAULT, $arguments);
6458
}
6559
}

app/code/Magento/Bundle/Test/Unit/Pricing/Price/BundleSelectionFactoryTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,4 @@ public function testCreate()
6666
->create($this->bundleMock, $this->selectionMock, 2., ['test' => 'some value'])
6767
);
6868
}
69-
70-
/**
71-
* @expectedException \InvalidArgumentException
72-
*/
73-
public function testCreateException()
74-
{
75-
$this->objectManagerMock->expects($this->once())
76-
->method('create')
77-
->with(
78-
$this->equalTo(BundleSelectionFactory::SELECTION_CLASS_DEFAULT),
79-
$this->equalTo(
80-
[
81-
'test' => 'some value',
82-
'bundleProduct' => $this->bundleMock,
83-
'saleableItem' => $this->selectionMock,
84-
'quantity' => 2.,
85-
]
86-
)
87-
)
88-
->will($this->returnValue(new \stdClass()));
89-
$this->bundleSelectionFactory->create($this->bundleMock, $this->selectionMock, 2., ['test' => 'some value']);
90-
}
9169
}

lib/internal/Magento/Framework/Pricing/Price/AbstractPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class AbstractPrice implements PriceInterface
2323
const PRICE_CODE = 'abstract_price';
2424

2525
/**
26-
* @var AmountInterface
26+
* @var AmountInterface[]
2727
*/
2828
protected $amount;
2929

0 commit comments

Comments
 (0)