SpecialPrice.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\Catalog\Pricing\Price\RegularPrice;
  8. /**
  9. * Special price model
  10. */
  11. class SpecialPrice extends \Magento\Catalog\Pricing\Price\SpecialPrice implements DiscountProviderInterface
  12. {
  13. /**
  14. * @var float|false
  15. */
  16. protected $percent;
  17. /**
  18. * Returns discount percent
  19. *
  20. * @return bool|float
  21. */
  22. public function getDiscountPercent()
  23. {
  24. if ($this->percent === null) {
  25. $this->percent = parent::getValue();
  26. }
  27. return $this->percent;
  28. }
  29. /**
  30. * Returns price value
  31. *
  32. * @return bool|float
  33. */
  34. public function getValue()
  35. {
  36. if ($this->value !== null) {
  37. return $this->value;
  38. }
  39. $specialPrice = $this->getDiscountPercent();
  40. if ($specialPrice) {
  41. $regularPrice = $this->getRegularPrice();
  42. $this->value = $regularPrice * ($specialPrice / 100);
  43. } else {
  44. $this->value = false;
  45. }
  46. return $this->value;
  47. }
  48. /**
  49. * Returns regular price
  50. *
  51. * @return bool|float
  52. */
  53. protected function getRegularPrice()
  54. {
  55. return $this->priceInfo->getPrice(RegularPrice::PRICE_CODE)->getValue();
  56. }
  57. /**
  58. * @return bool
  59. */
  60. public function isPercentageDiscount()
  61. {
  62. return true;
  63. }
  64. }