Skip to content

Commit b5d4966

Browse files
committed
MAGETWO-55729: [Customer] Optimize performance for bundled products with lots of product options
- MAGETWO-60826: Wrong Regular price for dynamic bundle
1 parent f0b932f commit b5d4966

File tree

8 files changed

+214
-391
lines changed

8 files changed

+214
-391
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function addPriceFilter($product, $searchMin, $useRegularPrice = false)
197197
if ($product->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
198198
$this->addPriceData();
199199
if ($useRegularPrice) {
200-
$minimalPriceExpression = 'minimal_price';
200+
$minimalPriceExpression = 'price';
201201
} else {
202202
$this->getCatalogRuleProcessor()->addPriceData($this, 'selection.product_id');
203203
$minimalPriceExpression = 'LEAST(minimal_price, IFNULL(catalog_rule_price, minimal_price))';

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/BundlePriceAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract public function getTestCases();
3838
/**
3939
* @param array $strategyModifiers
4040
* @param string $productSku
41-
* @return \Magento\Catalog\Api\Data\ProductInterface
41+
* @return void
4242
* @throws \Magento\Framework\Exception\NoSuchEntityException
4343
* @throws \Magento\Framework\Exception\InputException
4444
* @throws \Magento\Framework\Exception\StateException
@@ -54,12 +54,12 @@ protected function prepareFixture($strategyModifiers, $productSku)
5454
$bundleProduct = call_user_func_array([$this, $modifier['modifierName']], $modifier['data']);
5555
} else {
5656
throw new \Magento\Framework\Exception\InputException(
57-
sprintf('Modifier %s does not exists', $modifier['modifierName'])
57+
__('Modifier %s does not exists', $modifier['modifierName'])
5858
);
5959
}
6060
}
6161

62-
return $this->productRepository->save($bundleProduct);
62+
$this->productRepository->save($bundleProduct);
6363
}
6464

6565
/**

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundlePriceCalculatorTest.php

Lines changed: 121 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getTestCases()
7777
{
7878
return [
7979
'#1 Testing price for dynamic bundle product with one simple' => [
80-
'strategy' => $this->getProductWithOneSimple(),
80+
'strategy' => $this->getBundleConfiguration1(),
8181
'expectedResults' => [
8282
// just price from simple1
8383
'minimalPrice' => 10,
@@ -87,7 +87,7 @@ public function getTestCases()
8787
],
8888

8989
'#2 Testing price for dynamic bundle product with three simples and different qty' => [
90-
'strategy' => $this->getProductWithDifferentQty(),
90+
'strategy' => $this->getBundleConfiguration2(),
9191
'expectedResults' => [
9292
// min price from simples 3*10 or 30
9393
'minimalPrice' => 30,
@@ -97,14 +97,34 @@ public function getTestCases()
9797
],
9898

9999
'#3 Testing price for dynamic bundle product with four simples and different price' => [
100-
'strategy' => $this->getProductWithDifferentPrice(),
100+
'strategy' => $this->getBundleConfiguration3(),
101101
'expectedResults' => [
102102
// 10
103103
'minimalPrice' => 10,
104104
// 10 + 20 + 30
105105
'maximalPrice' => 60
106106
]
107-
]
107+
],
108+
109+
'#4 Testing price for dynamic bundle with two non required options' => [
110+
'strategy' => $this->getBundleConfiguration4(),
111+
'expectedResults' => [
112+
// 1 * 10
113+
'minimalPrice' => 10,
114+
// 3 * 20 + 1 * 10 + 3 * 20
115+
'maximalPrice' => 130
116+
]
117+
],
118+
119+
'#5 Testing price for dynamic bundle with two required options' => [
120+
'strategy' => $this->getBundleConfiguration5(),
121+
'expectedResults' => [
122+
// 1 * 10 + 1 * 10
123+
'minimalPrice' => 20,
124+
// 3 * 20 + 1 * 10 + 3 * 20
125+
'maximalPrice' => 130
126+
]
127+
],
108128
];
109129
}
110130

@@ -113,7 +133,7 @@ public function getTestCases()
113133
*
114134
* @return array
115135
*/
116-
private function getProductWithOneSimple()
136+
private function getBundleConfiguration1()
117137
{
118138
$optionsData = [
119139
[
@@ -142,7 +162,7 @@ private function getProductWithOneSimple()
142162
*
143163
* @return array
144164
*/
145-
private function getProductWithDifferentQty()
165+
private function getBundleConfiguration2()
146166
{
147167
$optionsData = [
148168
[
@@ -179,7 +199,7 @@ private function getProductWithDifferentQty()
179199
*
180200
* @return array
181201
*/
182-
private function getProductWithDifferentPrice()
202+
private function getBundleConfiguration3()
183203
{
184204
$optionsData = [
185205
[
@@ -210,4 +230,98 @@ private function getProductWithDifferentPrice()
210230
],
211231
];
212232
}
233+
234+
/**
235+
* Dynamic bundle with two non required options and special price
236+
* @return array
237+
*/
238+
private function getBundleConfiguration4()
239+
{
240+
$optionsData = [
241+
[
242+
'title' => 'Op1',
243+
'required' => false,
244+
'type' => 'radio',
245+
'links' => [
246+
[
247+
'sku' => 'simple1',
248+
'qty' => 1,
249+
],
250+
[
251+
'sku' => 'simple2',
252+
'qty' => 3,
253+
],
254+
]
255+
],
256+
[
257+
'title' => 'Op2',
258+
'required' => false,
259+
'type' => 'checkbox',
260+
'links' => [
261+
[
262+
'sku' => 'simple1',
263+
'qty' => 1,
264+
],
265+
[
266+
'sku' => 'simple2',
267+
'qty' => 3,
268+
],
269+
]
270+
]
271+
];
272+
273+
return [
274+
[
275+
'modifierName' => 'addSimpleProduct',
276+
'data' => [$optionsData]
277+
],
278+
];
279+
}
280+
281+
/**
282+
* Dynamic bundle with two required options
283+
* @return array
284+
*/
285+
private function getBundleConfiguration5()
286+
{
287+
$optionsData = [
288+
[
289+
'title' => 'Op1',
290+
'required' => true,
291+
'type' => 'radio',
292+
'links' => [
293+
[
294+
'sku' => 'simple1',
295+
'qty' => 1,
296+
],
297+
[
298+
'sku' => 'simple2',
299+
'qty' => 3,
300+
],
301+
]
302+
],
303+
[
304+
'title' => 'Op2',
305+
'required' => true,
306+
'type' => 'checkbox',
307+
'links' => [
308+
[
309+
'sku' => 'simple1',
310+
'qty' => 1,
311+
],
312+
[
313+
'sku' => 'simple2',
314+
'qty' => 3,
315+
],
316+
]
317+
]
318+
];
319+
320+
return [
321+
[
322+
'modifierName' => 'addSimpleProduct',
323+
'data' => [$optionsData]
324+
],
325+
];
326+
}
213327
}

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/DynamicBundleWithCatalogPriceRuleCalculatorTest.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ public function getTestCases()
5959
]
6060
],
6161

62-
'#2 Testing price for dynamic bundle with one required option and special price' => [
63-
'strategy' => $this->getBundleProductConfiguration2(),
64-
'expectedResults' => [
65-
// 0.5 * 10 * 0.9
66-
'minimalPrice' => 4.5,
67-
68-
// 0.5 * 10 * 0.9
69-
'maximalPrice' => 4.5
70-
]
71-
],
72-
7362
'#3 Testing price for dynamic bundle with one non required option' => [
7463
'strategy' => $this->getBundleProductConfiguration3(),
7564
'expectedResults' => [
@@ -177,38 +166,6 @@ private function getBundleProductConfiguration1()
177166
];
178167
}
179168

180-
/**
181-
* Dynamic bundle with one required option and special price
182-
* @return array
183-
*/
184-
private function getBundleProductConfiguration2()
185-
{
186-
$optionsData = [
187-
[
188-
'title' => 'Op1',
189-
'required' => true,
190-
'type' => 'checkbox',
191-
'links' => [
192-
[
193-
'sku' => 'simple1',
194-
'qty' => 1,
195-
],
196-
]
197-
]
198-
];
199-
200-
return [
201-
[
202-
'modifierName' => 'addSpecialPrice',
203-
'data' => [50]
204-
],
205-
[
206-
'modifierName' => 'addSimpleProduct',
207-
'data' => [$optionsData]
208-
],
209-
];
210-
}
211-
212169
/**
213170
* Dynamic bundle with one non required option
214171
* @return array
@@ -473,16 +430,4 @@ private function getBundleProductConfiguration9()
473430
],
474431
];
475432
}
476-
477-
/**
478-
* @param \Magento\Catalog\Model\Product $bundleProduct
479-
* @param int $discount
480-
* @return \Magento\Catalog\Model\Product
481-
*/
482-
protected function addSpecialPrice(\Magento\Catalog\Model\Product $bundleProduct, $discount)
483-
{
484-
$bundleProduct->setSpecialPrice($discount);
485-
486-
return $bundleProduct;
487-
}
488433
}

0 commit comments

Comments
 (0)