Skip to content
Snippets Groups Projects
Select Git revision
  • 75bed96ee7eb4b672b9799e11edd87298dfc308d
  • dev default protected
  • prod protected
  • 1.0.58
  • 1.0.57
  • 1.0.52
  • 1.0.56
  • 1.0.51
  • 1.0.50
  • 1.0.33
  • 1.0.32
  • 1.0.31
  • 1.0.30
  • 1.0.29
  • 1.0.28
  • 1.0.27
  • 1.0.26
  • 1.0.25
  • 1.0.24
  • 1.0.23
  • 1.0.22
  • 1.0.21
  • 1.0.20
23 results

Generic.php

Blame
  • Generic.php 1.25 KiB
    <?php
    
    namespace bobgo\CustomShipping\Model\Source;
    
    
    use Magento\Framework\Data\OptionSourceInterface;
    use bobgo\CustomShipping\Model\Carrier\CustomShipping;
    
    /**
     * Bob Go generic source implementation
     */
    class Generic implements OptionSourceInterface
    {
        /**
         * @var CustomShipping
         */
        protected CustomShipping $_shippingCustomShipping;
    
        /**
         * Carrier code
         * @var string
         */
        protected string $_code = 'bobgo';
    
        /**
         * @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;
        }
    
    }