Base.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Pricing\PriceInfo;
  7. use Magento\Framework\Pricing\Adjustment\AdjustmentInterface;
  8. use Magento\Framework\Pricing\Adjustment\Collection;
  9. use Magento\Framework\Pricing\Price\Collection as PriceCollection;
  10. use Magento\Framework\Pricing\Price\PriceInterface;
  11. use Magento\Framework\Pricing\PriceInfoInterface;
  12. /**
  13. * Class Base
  14. * Price info base model
  15. *
  16. * @api
  17. * @since 100.0.2
  18. */
  19. class Base implements PriceInfoInterface
  20. {
  21. /**
  22. * @var PriceCollection
  23. */
  24. protected $priceCollection;
  25. /**
  26. * @var Collection
  27. */
  28. protected $adjustmentCollection;
  29. /**
  30. * @param PriceCollection $prices
  31. * @param Collection $adjustmentCollection
  32. */
  33. public function __construct(
  34. PriceCollection $prices,
  35. Collection $adjustmentCollection
  36. ) {
  37. $this->adjustmentCollection = $adjustmentCollection;
  38. $this->priceCollection = $prices;
  39. }
  40. /**
  41. * Returns array of prices
  42. *
  43. * @return PriceCollection
  44. */
  45. public function getPrices()
  46. {
  47. return $this->priceCollection;
  48. }
  49. /**
  50. * Returns price by code
  51. *
  52. * @param string $priceCode
  53. * @return PriceInterface
  54. */
  55. public function getPrice($priceCode)
  56. {
  57. return $this->priceCollection->get($priceCode);
  58. }
  59. /**
  60. * Get all registered adjustments
  61. *
  62. * @return AdjustmentInterface[]
  63. */
  64. public function getAdjustments()
  65. {
  66. return $this->adjustmentCollection->getItems();
  67. }
  68. /**
  69. * Get adjustment by code
  70. *
  71. * @param string $adjustmentCode
  72. * @throws \InvalidArgumentException
  73. * @return AdjustmentInterface
  74. */
  75. public function getAdjustment($adjustmentCode)
  76. {
  77. return $this->adjustmentCollection->getItemByCode($adjustmentCode);
  78. }
  79. }