1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Pricing\Price;
use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\Pricing\Amount\AmountInterface;
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
use Magento\Bundle\Model\Product\Price;
/**
* Bundle product regular price model
*/
class BundleRegularPrice extends \Magento\Catalog\Pricing\Price\RegularPrice implements RegularPriceInterface
{
/**
* @var BundleCalculatorInterface
*/
protected $calculator;
/**
* @var AmountInterface
*/
protected $maximalPrice;
/**
* @param Product $saleableItem
* @param float $quantity
* @param BundleCalculatorInterface $calculator
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
*/
public function __construct(
Product $saleableItem,
$quantity,
BundleCalculatorInterface $calculator,
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
) {
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
}
/**
* @inheritdoc
*/
public function getAmount()
{
if (!isset($this->amount[$this->getValue()])) {
$price = $this->getValue();
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
$price += $customOptionPrice->getCustomOptionRange(true, $this->getPriceCode());
}
$this->amount[$this->getValue()] = $this->calculator->getMinRegularAmount($price, $this->product);
}
return $this->amount[$this->getValue()];
}
/**
* Returns max price
*
* @return \Magento\Framework\Pricing\Amount\AmountInterface
*/
public function getMaximalPrice()
{
if (null === $this->maximalPrice) {
$price = $this->getValue();
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
$price += $customOptionPrice->getCustomOptionRange(false, $this->getPriceCode());
}
$this->maximalPrice = $this->calculator->getMaxRegularAmount($price, $this->product);
}
return $this->maximalPrice;
}
/**
* Returns min price
*
* @return \Magento\Framework\Pricing\Amount\AmountInterface
*/
public function getMinimalPrice()
{
return $this->getAmount();
}
}