Text.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValue;
  8. use Magento\Catalog\Model\Product\Option;
  9. use Magento\Catalog\Model\Product\Option\Type\Text as TextOptionType;
  10. use Magento\Quote\Model\Quote\Item as QuoteItem;
  11. use Magento\Quote\Model\Quote\Item\Option as SelectedOption;
  12. use Magento\QuoteGraphQl\Model\CartItem\DataProvider\CustomizableOptionValueInterface;
  13. /**
  14. * @inheritdoc
  15. */
  16. class Text implements CustomizableOptionValueInterface
  17. {
  18. /**
  19. * @var PriceUnitLabel
  20. */
  21. private $priceUnitLabel;
  22. /**
  23. * @param PriceUnitLabel $priceUnitLabel
  24. */
  25. public function __construct(
  26. PriceUnitLabel $priceUnitLabel
  27. ) {
  28. $this->priceUnitLabel = $priceUnitLabel;
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function getData(
  34. QuoteItem $cartItem,
  35. Option $option,
  36. SelectedOption $selectedOption
  37. ): array {
  38. /** @var TextOptionType $optionTypeRenderer */
  39. $optionTypeRenderer = $option->groupFactory($option->getType());
  40. $priceValueUnits = $this->priceUnitLabel->getData($option->getPriceType());
  41. $selectedOptionValueData = [
  42. 'id' => $selectedOption->getId(),
  43. 'label' => '',
  44. 'value' => $optionTypeRenderer->getFormattedOptionValue($selectedOption->getValue()),
  45. 'price' => [
  46. 'type' => strtoupper($option->getPriceType()),
  47. 'units' => $priceValueUnits,
  48. 'value' => $option->getPrice(),
  49. ],
  50. ];
  51. return [$selectedOptionValueData];
  52. }
  53. }