BundleRegularPrice.php 2.9 KB

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