PriceUnitLabel.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\Config\Source\ProductPriceOptionsInterface;
  9. use Magento\Framework\Exception\NoSuchEntityException;
  10. use Magento\Store\Api\Data\StoreInterface;
  11. use Magento\Store\Model\Store;
  12. use Magento\Store\Model\StoreManagerInterface;
  13. /**
  14. * Custom Option Data provider
  15. */
  16. class PriceUnitLabel
  17. {
  18. /**
  19. * @var StoreManagerInterface
  20. */
  21. private $storeManager;
  22. /**
  23. * @param StoreManagerInterface $storeManager
  24. */
  25. public function __construct(
  26. StoreManagerInterface $storeManager
  27. ) {
  28. $this->storeManager = $storeManager;
  29. }
  30. /**
  31. * Retrieve price value unit
  32. *
  33. * @param string $priceType
  34. * @return string
  35. */
  36. public function getData(string $priceType): string
  37. {
  38. if (ProductPriceOptionsInterface::VALUE_PERCENT == $priceType) {
  39. return '%';
  40. }
  41. return $this->getCurrencySymbol();
  42. }
  43. /**
  44. * Get currency symbol
  45. *
  46. * @return string
  47. * @throws NoSuchEntityException
  48. */
  49. private function getCurrencySymbol(): string
  50. {
  51. /** @var Store|StoreInterface $store */
  52. $store = $this->storeManager->getStore();
  53. return $store->getBaseCurrency()->getCurrencySymbol();
  54. }
  55. }