Skip to content

Commit 0ba409d

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-mpi/MAGETWO-83340
2 parents 93b676a + f658498 commit 0ba409d

File tree

65 files changed

+3513
-606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3513
-606
lines changed

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -217,42 +217,49 @@ public function getOptionHtml(Option $option)
217217
}
218218

219219
/**
220-
* Get formed data from option selection item
220+
* Get formed data from option selection item.
221221
*
222222
* @param Product $product
223223
* @param Product $selection
224+
*
224225
* @return array
225226
*/
226227
private function getSelectionItemData(Product $product, Product $selection)
227228
{
228229
$qty = ($selection->getSelectionQty() * 1) ?: '1';
229230

230231
$optionPriceAmount = $product->getPriceInfo()
231-
->getPrice('bundle_option')
232+
->getPrice(\Magento\Bundle\Pricing\Price\BundleOptionPrice::PRICE_CODE)
232233
->getOptionSelectionAmount($selection);
233234
$finalPrice = $optionPriceAmount->getValue();
234235
$basePrice = $optionPriceAmount->getBaseAmount();
235236

237+
$oldPrice = $product->getPriceInfo()
238+
->getPrice(\Magento\Bundle\Pricing\Price\BundleOptionRegularPrice::PRICE_CODE)
239+
->getOptionSelectionAmount($selection)
240+
->getValue();
241+
236242
$selection = [
237243
'qty' => $qty,
238244
'customQty' => $selection->getSelectionCanChangeQty(),
239245
'optionId' => $selection->getId(),
240246
'prices' => [
241247
'oldPrice' => [
242-
'amount' => $basePrice
248+
'amount' => $oldPrice,
243249
],
244250
'basePrice' => [
245-
'amount' => $basePrice
251+
'amount' => $basePrice,
246252
],
247253
'finalPrice' => [
248-
'amount' => $finalPrice
249-
]
254+
'amount' => $finalPrice,
255+
],
250256
],
251257
'priceType' => $selection->getSelectionPriceType(),
252258
'tierPrice' => $this->getTierPrices($product, $selection),
253259
'name' => $selection->getName(),
254-
'canApplyMsrp' => false
260+
'canApplyMsrp' => false,
255261
];
262+
256263
return $selection;
257264
}
258265

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

+27-50
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface;
99
use Magento\Catalog\Model\Product;
1010
use Magento\Framework\Pricing\Price\AbstractPrice;
11+
use Magento\Framework\App\ObjectManager;
1112

1213
/**
13-
* Bundle option price model
14+
* Bundle option price model with final price.
1415
*/
1516
class BundleOptionPrice extends AbstractPrice implements BundleOptionPriceInterface
1617
{
@@ -26,6 +27,7 @@ class BundleOptionPrice extends AbstractPrice implements BundleOptionPriceInterf
2627

2728
/**
2829
* @var BundleSelectionFactory
30+
* @deprecated
2931
*/
3032
protected $selectionFactory;
3133

@@ -34,23 +36,31 @@ class BundleOptionPrice extends AbstractPrice implements BundleOptionPriceInterf
3436
*/
3537
protected $maximalPrice;
3638

39+
/**
40+
* @var BundleOptions
41+
*/
42+
private $bundleOptions;
43+
3744
/**
3845
* @param Product $saleableItem
3946
* @param float $quantity
4047
* @param BundleCalculatorInterface $calculator
4148
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
4249
* @param BundleSelectionFactory $bundleSelectionFactory
50+
* @param BundleOptions|null $bundleOptions
4351
*/
4452
public function __construct(
4553
Product $saleableItem,
4654
$quantity,
4755
BundleCalculatorInterface $calculator,
4856
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
49-
BundleSelectionFactory $bundleSelectionFactory
57+
BundleSelectionFactory $bundleSelectionFactory,
58+
BundleOptions $bundleOptions = null
5059
) {
5160
$this->selectionFactory = $bundleSelectionFactory;
5261
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
5362
$this->product->setQty($this->quantity);
63+
$this->bundleOptions = $bundleOptions ?: ObjectManager::getInstance()->get(BundleOptions::class);
5464
}
5565

5666
/**
@@ -59,94 +69,61 @@ public function __construct(
5969
public function getValue()
6070
{
6171
if (null === $this->value) {
62-
$this->value = $this->calculateOptions();
72+
$this->value = $this->bundleOptions->calculateOptions($this->product);
6373
}
74+
6475
return $this->value;
6576
}
6677

6778
/**
68-
* Getter for maximal price of options
79+
* Getter for maximal price of options.
6980
*
7081
* @return bool|float
82+
* @deprecated
7183
*/
7284
public function getMaxValue()
7385
{
7486
if (null === $this->maximalPrice) {
75-
$this->maximalPrice = $this->calculateOptions(false);
87+
$this->maximalPrice = $this->bundleOptions->calculateOptions($this->product, false);
7688
}
89+
7790
return $this->maximalPrice;
7891
}
7992

8093
/**
81-
* Get Options with attached Selections collection
94+
* Get Options with attached Selections collection.
8295
*
8396
* @return \Magento\Bundle\Model\ResourceModel\Option\Collection
8497
*/
8598
public function getOptions()
8699
{
87-
$bundleProduct = $this->product;
88-
/** @var \Magento\Bundle\Model\Product\Type $typeInstance */
89-
$typeInstance = $bundleProduct->getTypeInstance();
90-
$typeInstance->setStoreFilter($bundleProduct->getStoreId(), $bundleProduct);
91-
92-
/** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionCollection */
93-
$optionCollection = $typeInstance->getOptionsCollection($bundleProduct);
94-
95-
$selectionCollection = $typeInstance->getSelectionsCollection(
96-
$typeInstance->getOptionsIds($bundleProduct),
97-
$bundleProduct
98-
);
99-
100-
$priceOptions = $optionCollection->appendSelections($selectionCollection, true, false);
101-
return $priceOptions;
100+
return $this->bundleOptions->getOptions($this->product);
102101
}
103102

104103
/**
105-
* Get selection amount
104+
* Get selection amount.
106105
*
107106
* @param \Magento\Bundle\Model\Selection $selection
108107
* @return \Magento\Framework\Pricing\Amount\AmountInterface
109108
*/
110109
public function getOptionSelectionAmount($selection)
111110
{
112-
$cacheKey = implode(
113-
'_',
114-
[
115-
$this->product->getId(),
116-
$selection->getOptionId(),
117-
$selection->getSelectionId()
118-
]
111+
return $this->bundleOptions->getOptionSelectionAmount(
112+
$this->product,
113+
$selection,
114+
false
119115
);
120-
121-
if (!isset($this->optionSelecionAmountCache[$cacheKey])) {
122-
$selectionPrice = $this->selectionFactory
123-
->create($this->product, $selection, $selection->getSelectionQty());
124-
$this->optionSelecionAmountCache[$cacheKey] = $selectionPrice->getAmount();
125-
}
126-
127-
return $this->optionSelecionAmountCache[$cacheKey];
128116
}
129117

130118
/**
131-
* Calculate maximal or minimal options value
119+
* Calculate maximal or minimal options value.
132120
*
133121
* @param bool $searchMin
134122
* @return bool|float
135123
*/
136124
protected function calculateOptions($searchMin = true)
137125
{
138-
$priceList = [];
139-
/* @var $option \Magento\Bundle\Model\Option */
140-
foreach ($this->getOptions() as $option) {
141-
if ($searchMin && !$option->getRequired()) {
142-
continue;
143-
}
144-
$selectionPriceList = $this->calculator->createSelectionPriceList($option, $this->product);
145-
$selectionPriceList = $this->calculator->processOptions($option, $selectionPriceList, $searchMin);
146-
$priceList = array_merge($priceList, $selectionPriceList);
147-
}
148-
$amount = $this->calculator->calculateBundleAmount(0., $this->product, $priceList);
149-
return $amount->getValue();
126+
return $this->bundleOptions->calculateOptions($this->product, $searchMin);
150127
}
151128

152129
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Pricing\Price;
9+
10+
use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Framework\Pricing\Price\AbstractPrice;
13+
use Magento\Framework\Pricing\PriceCurrencyInterface;
14+
15+
/**
16+
* Bundle option price model with final price.
17+
*/
18+
class BundleOptionRegularPrice extends AbstractPrice implements BundleOptionPriceInterface
19+
{
20+
/**
21+
* Price model code.
22+
*/
23+
const PRICE_CODE = 'bundle_option_regular_price';
24+
25+
/**
26+
* @var BundleCalculatorInterface
27+
*/
28+
protected $calculator;
29+
30+
/**
31+
* @var BundleOptions
32+
*/
33+
private $bundleOptions;
34+
35+
/**
36+
* @param Product $saleableItem
37+
* @param float $quantity
38+
* @param BundleCalculatorInterface $calculator
39+
* @param PriceCurrencyInterface $priceCurrency
40+
* @param BundleOptions $bundleOptions
41+
*/
42+
public function __construct(
43+
Product $saleableItem,
44+
$quantity,
45+
BundleCalculatorInterface $calculator,
46+
PriceCurrencyInterface $priceCurrency,
47+
BundleOptions $bundleOptions
48+
) {
49+
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
50+
$this->product->setQty($this->quantity);
51+
$this->bundleOptions = $bundleOptions;
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function getValue()
58+
{
59+
if (null === $this->value) {
60+
$this->value = $this->bundleOptions->calculateOptions($this->product);
61+
}
62+
63+
return $this->value;
64+
}
65+
66+
/**
67+
* Get Options with attached Selections collection.
68+
*
69+
* @return \Magento\Bundle\Model\ResourceModel\Option\Collection
70+
*/
71+
public function getOptions() : \Magento\Bundle\Model\ResourceModel\Option\Collection
72+
{
73+
return $this->bundleOptions->getOptions($this->product);
74+
}
75+
76+
/**
77+
* Get selection amount.
78+
*
79+
* @param \Magento\Bundle\Model\Selection $selection
80+
* @return \Magento\Framework\Pricing\Amount\AmountInterface
81+
*/
82+
public function getOptionSelectionAmount($selection) : \Magento\Framework\Pricing\Amount\AmountInterface
83+
{
84+
return $this->bundleOptions->getOptionSelectionAmount(
85+
$this->product,
86+
$selection,
87+
true
88+
);
89+
}
90+
91+
/**
92+
* Get minimal amount of bundle price with options.
93+
*
94+
* @return \Magento\Framework\Pricing\Amount\AmountInterface
95+
*/
96+
public function getAmount() : \Magento\Framework\Pricing\Amount\AmountInterface
97+
{
98+
return $this->calculator->getOptionsAmount($this->product);
99+
}
100+
}

0 commit comments

Comments
 (0)