ConfiguredRegularPrice.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Catalog\Pricing\Price;
  8. use Magento\Catalog\Model\Product;
  9. use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
  10. use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
  11. use Magento\Framework\Pricing\PriceCurrencyInterface;
  12. /**
  13. * Configured regular price model.
  14. */
  15. class ConfiguredRegularPrice extends RegularPrice implements ConfiguredPriceInterface
  16. {
  17. /**
  18. * Price type configured.
  19. */
  20. const PRICE_CODE = self::CONFIGURED_REGULAR_PRICE_CODE;
  21. /**
  22. * @var null|ItemInterface
  23. */
  24. private $item;
  25. /**
  26. * @var ConfiguredOptions
  27. */
  28. private $configuredOptions;
  29. /**
  30. * @param Product $saleableItem
  31. * @param float $quantity
  32. * @param CalculatorInterface $calculator
  33. * @param PriceCurrencyInterface $priceCurrency
  34. * @param ConfiguredOptions $configuredOptions
  35. * @param ItemInterface|null $item
  36. */
  37. public function __construct(
  38. Product $saleableItem,
  39. $quantity,
  40. CalculatorInterface $calculator,
  41. PriceCurrencyInterface $priceCurrency,
  42. ConfiguredOptions $configuredOptions,
  43. ItemInterface $item = null
  44. ) {
  45. $this->item = $item;
  46. $this->configuredOptions = $configuredOptions;
  47. parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
  48. }
  49. /**
  50. * @param ItemInterface $item
  51. * @return $this
  52. */
  53. public function setItem(ItemInterface $item) : ConfiguredRegularPrice
  54. {
  55. $this->item = $item;
  56. return $this;
  57. }
  58. /**
  59. * Price value of product with configured options.
  60. *
  61. * @return bool|float
  62. */
  63. public function getValue()
  64. {
  65. $basePrice = parent::getValue();
  66. return $this->item && $basePrice !== false
  67. ? $basePrice + $this->configuredOptions->getItemOptionsValue($basePrice, $this->item)
  68. : $basePrice;
  69. }
  70. }