diff --git a/uafrica/Customshipping/Model/Source/Dropoff.php b/uafrica/Customshipping/Model/Source/Dropoff.php new file mode 100644 index 0000000000000000000000000000000000000000..4606fed88affd3ce7c561b626d2b0aeff10c61ff --- /dev/null +++ b/uafrica/Customshipping/Model/Source/Dropoff.php @@ -0,0 +1,12 @@ +<?php + +namespace uafrica\Customshipping\Model\Source; + +class Dropoff extends Generic +{ + /** + * Carrier code + * @var string + */ + protected string $_code = 'dropoff'; +} diff --git a/uafrica/Customshipping/Model/Source/Generic.php b/uafrica/Customshipping/Model/Source/Generic.php new file mode 100644 index 0000000000000000000000000000000000000000..f2bbce3f6147c7116ff255155103bbb7e20da8fb --- /dev/null +++ b/uafrica/Customshipping/Model/Source/Generic.php @@ -0,0 +1,56 @@ +<?php + +namespace uafrica\customshipping\Model\Source; + + +use uafrica\Customshipping\Model\Carrier\Customshipping; + +/** + * uAfrica generic source implementation + */ +class Generic implements \Magento\Framework\Data\OptionSourceInterface +{ + /** + * @var Customshipping + */ + protected Customshipping $_shippingCustomshipping; + + /** + * Carrier code + * @var string + */ + protected string $_code = ''; + + /** + * @param Customshipping $shippingCustomshipping + */ + public function __construct(Customshipping $shippingCustomshipping) + { + $this->_shippingCustomshipping = $shippingCustomshipping; + } + + /** + * Returns array to be used in multiselect on back-end + * @return array + */ + public function toOptionArray() + { + $configData = $this->_shippingCustomshipping->getCode($this->_code); + $arr = []; + if ($configData) { + $arr = array_map( + function ($code, $title) { + return [ + 'value' => $code, + 'label' => $title + ]; + }, + array_keys($configData), + $configData + ); + } + + return $arr; + } + +} diff --git a/uafrica/Customshipping/Model/Source/Method.php b/uafrica/Customshipping/Model/Source/Method.php new file mode 100644 index 0000000000000000000000000000000000000000..0c958e50750ed8d7faa332cc1903c4e13efae178 --- /dev/null +++ b/uafrica/Customshipping/Model/Source/Method.php @@ -0,0 +1,12 @@ +<?php + +namespace uafrica\Customshipping\Model\Source; + +class Method extends Generic +{ + /** + * Carrier code + * @var string + */ + protected string $_code = 'method'; +} diff --git a/uafrica/Customshipping/Model/Source/Packaging.php b/uafrica/Customshipping/Model/Source/Packaging.php new file mode 100644 index 0000000000000000000000000000000000000000..969d080a3337621d3a7d61c091cc1f768fa093e4 --- /dev/null +++ b/uafrica/Customshipping/Model/Source/Packaging.php @@ -0,0 +1,12 @@ +<?php + +namespace uafrica\Customshipping\Model\Source; + +class Packaging extends Generic +{ + /** + * Carrier code + * @var string + */ + protected string $_code = 'packaging'; +} diff --git a/uafrica/Customshipping/Model/Source/Unitofmeasure.php b/uafrica/Customshipping/Model/Source/Unitofmeasure.php new file mode 100644 index 0000000000000000000000000000000000000000..2fd77f1979280e1e25181eaf9d8446672ee353de --- /dev/null +++ b/uafrica/Customshipping/Model/Source/Unitofmeasure.php @@ -0,0 +1,12 @@ +<?php + +namespace uafrica\Customshipping\Model\Source; + +class Unitofmeasure extends Generic +{ + /** + * Carrier code + * @var string + */ + protected string $_code = 'unit_of_measure'; +}