AbstractMethod.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Dhl\Model\Source\Method;
  7. /**
  8. * Source model for DHL shipping methods
  9. */
  10. abstract class AbstractMethod extends \Magento\Dhl\Model\Source\Method\Generic
  11. {
  12. /**
  13. * Carrier Product Type Indicator
  14. *
  15. * @var string $_contentType
  16. */
  17. protected $_contentType;
  18. /**
  19. * Show 'none' in methods list or not;
  20. *
  21. * @var bool
  22. */
  23. protected $_noneMethod = false;
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function toOptionArray()
  28. {
  29. /* @var $carrierModel \Magento\Dhl\Model\Carrier */
  30. $carrierModel = $this->_shippingDhl;
  31. $dhlProducts = $carrierModel->getDhlProducts($this->_contentType);
  32. $options = [];
  33. foreach ($dhlProducts as $code => $title) {
  34. $options[] = ['value' => $code, 'label' => $title];
  35. }
  36. if ($this->_noneMethod) {
  37. array_unshift($options, ['value' => '', 'label' => __('None')]);
  38. }
  39. return $options;
  40. }
  41. }