Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FinalPrice.php
Go to the documentation of this file.
1 <?php
8 
15 
20 {
24  protected $maximalPrice;
25 
29  protected $minimalPrice;
30 
35 
39  protected $bundleOptionPrice;
40 
44  private $productOptionRepository;
45 
52  public function __construct(
53  Product $saleableItem,
54  $quantity,
57  ) {
58  parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
59  }
60 
66  public function getValue()
67  {
68  return parent::getValue() +
69  $this->getBundleOptionPrice()->getValue();
70  }
71 
77  public function getMaximalPrice()
78  {
79  if (!$this->maximalPrice) {
80  $price = $this->getBasePrice()->getValue();
81  if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
83  $customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
84  $price += $customOptionPrice->getCustomOptionRange(false);
85  }
86  $this->maximalPrice = $this->calculator->getMaxAmount($price, $this->product);
87  }
88  return $this->maximalPrice;
89  }
90 
97  private function getProductOptionRepository()
98  {
99  if (!$this->productOptionRepository) {
100  $this->productOptionRepository = ObjectManager::getInstance()->get(
101  ProductCustomOptionRepositoryInterface::class
102  );
103  }
104  return $this->productOptionRepository;
105  }
106 
112  public function getMinimalPrice()
113  {
114  return $this->getAmount();
115  }
116 
122  public function getAmount()
123  {
124  if (!$this->minimalPrice) {
125  $price = parent::getValue();
126  if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
127  $this->loadProductCustomOptions();
129  $customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
130  $price += $customOptionPrice->getCustomOptionRange(true);
131  }
132  $this->minimalPrice = $this->calculator->getAmount($price, $this->product);
133  }
134  return $this->minimalPrice;
135  }
136 
142  private function loadProductCustomOptions()
143  {
144  if (!$this->product->getOptions()) {
145  $options = [];
146  foreach ($this->getProductOptionRepository()->getProductOptions($this->product) as $option) {
147  $option->setProduct($this->product);
148  $options[] = $option;
149  }
150  $this->product->setOptions($options);
151  }
152  }
153 
159  public function getPriceWithoutOption()
160  {
161  if (!$this->priceWithoutOption) {
162  $this->priceWithoutOption = $this->calculator->getAmountWithoutOption(parent::getValue(), $this->product);
163  }
165  }
166 
172  protected function getBundleOptionPrice()
173  {
174  if (!$this->bundleOptionPrice) {
175  $this->bundleOptionPrice = $this->priceInfo->getPrice(BundleOptionPrice::PRICE_CODE);
176  }
178  }
179 }
$price
__construct(Product $saleableItem, $quantity, CalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency)
Definition: FinalPrice.php:52