Skip to content
Snippets Groups Projects
Select Git revision
  • 74332fee0cded77ecbdc2ac0b2335a1d4e6f45bf
  • 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.14 KiB
    <?php
    
    namespace BobGroup\BobGo\Model\Source;
    
    
    use Magento\Framework\Data\OptionSourceInterface;
    use BobGroup\BobGo\Model\Carrier\BobGo;
    
    /**
     * bobgo generic source implementation
     */
    class Generic implements OptionSourceInterface
    {
        /**
         * @var BobGo
         */
        protected BobGo $_shippingBobGo;
    
        /**
         * Carrier code
         * @var string
         */
        protected string $_code = '';
    
        /**
         * @param BobGo $shippingBobGo
         */
        public function __construct(BobGo $shippingBobGo)
        {
            $this->_shippingBobGo = $shippingBobGo;
        }
    
        /**
         * Returns array to be used in multiselect on back-end
         * @return array
         */
        public function toOptionArray()
        {
            $configData = $this->_shippingBobGo->getCode($this->_code);
            $arr = [];
            if ($configData) {
                $arr = array_map(
                    function ($code, $title) {
                        return [
                            'value' => $code,
                            'label' => $title
                        ];
                    },
                    array_keys($configData),
                    $configData
                );
            }
    
            return $arr;
        }
    
    }