Generic.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Usps\Model\Source;
  7. use Magento\Shipping\Model\Carrier\Source\GenericInterface;
  8. use Magento\Usps\Model\Carrier;
  9. /**
  10. * Generic source
  11. */
  12. class Generic implements GenericInterface
  13. {
  14. /**
  15. * @var \Magento\Usps\Model\Carrier
  16. */
  17. protected $shippingUsps;
  18. /**
  19. * Carrier code
  20. *
  21. * @var string
  22. */
  23. protected $code = '';
  24. /**
  25. * @param \Magento\Usps\Model\Carrier $shippingUsps
  26. */
  27. public function __construct(Carrier $shippingUsps)
  28. {
  29. $this->shippingUsps = $shippingUsps;
  30. }
  31. /**
  32. * Returns array to be used in multiselect on back-end
  33. *
  34. * @return array
  35. */
  36. public function toOptionArray()
  37. {
  38. $options = [];
  39. $codes = $this->shippingUsps->getCode($this->code);
  40. if ($codes) {
  41. foreach ($codes as $code => $title) {
  42. $options[] = ['value' => $code, 'label' => __($title)];
  43. }
  44. }
  45. return $options;
  46. }
  47. }