Skip to content

Commit 5019500

Browse files
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGETWO-87815
2 parents 7137470 + dcd0dbc commit 5019500

File tree

62 files changed

+2462
-581
lines changed

Some content is hidden

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

62 files changed

+2462
-581
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,23 @@ private function getSelectionItemData(Product $product, Product $selection)
228228
$qty = ($selection->getSelectionQty() * 1) ?: '1';
229229

230230
$optionPriceAmount = $product->getPriceInfo()
231-
->getPrice('bundle_option')
231+
->getPrice(\Magento\Bundle\Pricing\Price\BundleOptionPrice::PRICE_CODE)
232232
->getOptionSelectionAmount($selection);
233233
$finalPrice = $optionPriceAmount->getValue();
234234
$basePrice = $optionPriceAmount->getBaseAmount();
235235

236+
$oldPrice = $product->getPriceInfo()
237+
->getPrice(\Magento\Bundle\Pricing\Price\BundleOptionRegularPrice::PRICE_CODE)
238+
->getOptionSelectionAmount($selection)
239+
->getValue();
240+
236241
$selection = [
237242
'qty' => $qty,
238243
'customQty' => $selection->getSelectionCanChangeQty(),
239244
'optionId' => $selection->getId(),
240245
'prices' => [
241246
'oldPrice' => [
242-
'amount' => $basePrice
247+
'amount' => $oldPrice
243248
],
244249
'basePrice' => [
245250
'amount' => $basePrice

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Serialize\Serializer\Json;
1515
use Magento\Framework\EntityManager\MetadataPool;
1616
use Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier as SelectionCollectionFilterApplier;
17+
use Magento\Bundle\Model\ResourceModel\Selection\Collection as Selections;
1718

1819
/**
1920
* Bundle Type Model
@@ -486,7 +487,9 @@ public function getSelectionsCollection($optionIds, $product)
486487
\Magento\Catalog\Api\Data\ProductInterface::class
487488
);
488489

489-
$selectionsCollection = $this->_bundleCollection->create()
490+
/** @var Selections $selectionsCollection */
491+
$selectionsCollection = $this->_bundleCollection->create();
492+
$selectionsCollection
490493
->addAttributeToSelect($this->_config->getProductAttributes())
491494
->addAttributeToSelect('tax_class_id') //used for calculation item taxes in Bundle with Dynamic Price
492495
->setFlag('product_children', true)
@@ -587,6 +590,7 @@ public function isSalable($product)
587590
foreach ($this->getOptionsCollection($product) as $option) {
588591
$hasSalable = false;
589592

593+
/** @var Selections $selectionsCollection */
590594
$selectionsCollection = $this->_bundleCollection->create();
591595
$selectionsCollection->addAttributeToSelect('status');
592596
$selectionsCollection->addQuantityFilter();
@@ -855,8 +859,9 @@ public function getSelectionsByIds($selectionIds, $product)
855859

856860
if (!$usedSelections || $usedSelectionsIds !== $selectionIds) {
857861
$storeId = $product->getStoreId();
858-
$usedSelections = $this->_bundleCollection
859-
->create()
862+
/** @var Selections $usedSelections */
863+
$usedSelections = $this->_bundleCollection->create();
864+
$usedSelections
860865
->addAttributeToSelect('*')
861866
->setFlag('product_children', true)
862867
->addStoreFilter($this->getStoreFilter($product))

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,33 @@ public function setPositionOrder()
163163
}
164164

165165
/**
166-
* Add filtering of product then havent enoght stock
166+
* Add filtering of products that have 0 items left.
167167
*
168168
* @return $this
169169
* @since 100.2.0
170170
*/
171171
public function addQuantityFilter()
172172
{
173+
$stockItemTable = $this->getTable('cataloginventory_stock_item');
174+
$stockStatusTable = $this->getTable('cataloginventory_stock_status');
173175
$this->getSelect()
174176
->joinInner(
175-
['stock' => $this->getTable('cataloginventory_stock_status')],
177+
['stock' => $stockStatusTable],
176178
'selection.product_id = stock.product_id',
177179
[]
180+
)->joinInner(
181+
['stock_item' => $stockItemTable],
182+
'selection.product_id = stock_item.product_id',
183+
[]
178184
)
179185
->where(
180-
'(selection.selection_can_change_qty or selection.selection_qty <= stock.qty) and stock.stock_status'
186+
'('
187+
. 'selection.selection_can_change_qty'
188+
. ' or '
189+
. 'selection.selection_qty <= stock.qty'
190+
. ' or '
191+
.'stock_item.manage_stock = 0'
192+
. ') and stock.stock_status = 1'
181193
);
182194
return $this;
183195
}

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

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\Pricing\Price\AbstractPrice;
1111

1212
/**
13-
* Bundle option price model
13+
* Bundle option price model with final price
1414
*/
1515
class BundleOptionPrice extends AbstractPrice implements BundleOptionPriceInterface
1616
{
@@ -26,6 +26,7 @@ class BundleOptionPrice extends AbstractPrice implements BundleOptionPriceInterf
2626

2727
/**
2828
* @var BundleSelectionFactory
29+
* @deprecated
2930
*/
3031
protected $selectionFactory;
3132

@@ -34,23 +35,32 @@ class BundleOptionPrice extends AbstractPrice implements BundleOptionPriceInterf
3435
*/
3536
protected $maximalPrice;
3637

38+
/**
39+
* @var \Magento\Bundle\Pricing\Price\BundleOptions
40+
*/
41+
private $bundleOptions;
42+
3743
/**
3844
* @param Product $saleableItem
3945
* @param float $quantity
4046
* @param BundleCalculatorInterface $calculator
4147
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
4248
* @param BundleSelectionFactory $bundleSelectionFactory
49+
* @param BundleOptions|null $bundleOptions
4350
*/
4451
public function __construct(
4552
Product $saleableItem,
4653
$quantity,
4754
BundleCalculatorInterface $calculator,
4855
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
49-
BundleSelectionFactory $bundleSelectionFactory
56+
BundleSelectionFactory $bundleSelectionFactory,
57+
BundleOptions $bundleOptions = null
5058
) {
5159
$this->selectionFactory = $bundleSelectionFactory;
5260
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
5361
$this->product->setQty($this->quantity);
62+
$this->bundleOptions = $bundleOptions ?: \Magento\Framework\App\ObjectManager::getInstance()
63+
->get(\Magento\Bundle\Pricing\Price\BundleOptions::class);
5464
}
5565

5666
/**
@@ -59,7 +69,7 @@ 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
}
6474
return $this->value;
6575
}
@@ -68,11 +78,12 @@ public function getValue()
6878
* Getter for maximal price of options
6979
*
7080
* @return bool|float
81+
* @deprecated
7182
*/
7283
public function getMaxValue()
7384
{
7485
if (null === $this->maximalPrice) {
75-
$this->maximalPrice = $this->calculateOptions(false);
86+
$this->maximalPrice = $this->bundleOptions->calculateOptions($this->product, false);
7687
}
7788
return $this->maximalPrice;
7889
}
@@ -84,21 +95,7 @@ public function getMaxValue()
8495
*/
8596
public function getOptions()
8697
{
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;
98+
return $this->bundleOptions->getOptions($this->product);
10299
}
103100

104101
/**
@@ -109,22 +106,11 @@ public function getOptions()
109106
*/
110107
public function getOptionSelectionAmount($selection)
111108
{
112-
$cacheKey = implode(
113-
'_',
114-
[
115-
$this->product->getId(),
116-
$selection->getOptionId(),
117-
$selection->getSelectionId()
118-
]
109+
return $this->bundleOptions->getOptionSelectionAmount(
110+
$this->product,
111+
$selection,
112+
false
119113
);
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];
128114
}
129115

130116
/**
@@ -135,18 +121,7 @@ public function getOptionSelectionAmount($selection)
135121
*/
136122
protected function calculateOptions($searchMin = true)
137123
{
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();
124+
return $this->bundleOptions->calculateOptions($this->product, $searchMin);
150125
}
151126

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

0 commit comments

Comments
 (0)