ConfiguredPriceSelection.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Framework\Api\ExtensibleDataInterface;
  10. use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
  11. use Magento\Catalog\Pricing\Price\ConfiguredPriceInterface;
  12. /**
  13. * Configured price selection model
  14. */
  15. class ConfiguredPriceSelection
  16. {
  17. /**
  18. * @var CalculatorInterface
  19. */
  20. private $calculator;
  21. /**
  22. * @param CalculatorInterface $calculator
  23. */
  24. public function __construct(
  25. CalculatorInterface $calculator
  26. ) {
  27. $this->calculator = $calculator;
  28. }
  29. /**
  30. * Get Selection pricing list.
  31. *
  32. * @param ConfiguredPriceInterface $price
  33. * @return array
  34. */
  35. public function getSelectionPriceList(ConfiguredPriceInterface $price): array
  36. {
  37. $selectionPriceList = [];
  38. foreach ($price->getOptions() as $option) {
  39. $selectionPriceList = array_merge(
  40. $selectionPriceList,
  41. $this->createSelectionPriceList($option, $price->getProduct())
  42. );
  43. }
  44. return $selectionPriceList;
  45. }
  46. /**
  47. * Create Selection Price List.
  48. *
  49. * @param ExtensibleDataInterface $option
  50. * @param Product $product
  51. * @return array
  52. */
  53. private function createSelectionPriceList(ExtensibleDataInterface $option, Product $product): array
  54. {
  55. return $this->calculator->createSelectionPriceList($option, $product);
  56. }
  57. }