Skip to content
Snippets Groups Projects
Select Git revision
  • 4fa38540304a0e634e9dab05020d653e762df195
  • main default protected
  • v1.298.0
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
22 results

request.go

Blame
  • Generic.php 1.25 KiB
    <?php
    
    namespace bobgo\CustomShipping\Model\Source;
    
    
    use Magento\Framework\Data\OptionSourceInterface;
    use bobgo\CustomShipping\Model\Carrier\CustomShipping;
    
    /**
     * bobgo generic source implementation
     */
    class Generic implements 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;
        }
    
    }