From 4631e15d9449defcbc28139e00d8f6b7a3d243e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franc=C3=A9=20Wilke?= <francewilke@gmail.com>
Date: Wed, 14 Aug 2024 16:02:57 +0200
Subject: [PATCH] Fix Generic.php

---
 Block/System/Config/Form/Field/Version.php |  8 ++--
 Helper/Data.php                            |  2 +-
 Model/Carrier/BobGo.php                    |  2 +-
 Model/Source/Generic.php                   | 49 +++++++++++++++++++---
 etc/config.xml                             |  2 +-
 etc/module.xml                             |  2 +-
 6 files changed, 51 insertions(+), 14 deletions(-)

diff --git a/Block/System/Config/Form/Field/Version.php b/Block/System/Config/Form/Field/Version.php
index 5d07180..a98a00a 100644
--- a/Block/System/Config/Form/Field/Version.php
+++ b/Block/System/Config/Form/Field/Version.php
@@ -6,13 +6,13 @@ use Magento\Framework\Data\Form\Element\AbstractElement;
 /**
  * Displays Version number in System Configuration
  * @category   BobGroup
- * @package    bobgo_CustomShipping
- * @author     info@bob.co.za
- * @website    https://www.bob.co.za
+ * @package    BobGo
+ * @author     support@bobgo.co.za
+ * @website    https://www.bobgo.co.za
  */
 class Version extends \Magento\Config\Block\System\Config\Form\Field
 {
-    const EXTENSION_URL = 'https://www.bob.co.za';
+    const EXTENSION_URL = 'https://www.bobgo.co.za';
 
     /**
      * @var \BobGroup\BobGo\Helper\Data $helper
diff --git a/Helper/Data.php b/Helper/Data.php
index d0627ee..85a24f2 100644
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -8,7 +8,7 @@ use Magento\Store\Model\ScopeInterface;
 
 /**
  * @category   Bob Go
- * @package    bobgo_CustomShipping
+ * @package    BobGo
  * @author     Bob Go
  * @website    https://www.bobgo.co.za
  */
diff --git a/Model/Carrier/BobGo.php b/Model/Carrier/BobGo.php
index e02f0a1..97f5576 100644
--- a/Model/Carrier/BobGo.php
+++ b/Model/Carrier/BobGo.php
@@ -34,7 +34,7 @@ use Psr\Log\LoggerInterface;
 /**
  * Bob Go shipping implementation
  * @category   Bob Go
- * @package    bobgo_CustomShipping
+ * @package    BobGo
  * @author     Bob Go
  * @website    https://www.bobgo.co.za
  * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
diff --git a/Model/Source/Generic.php b/Model/Source/Generic.php
index 674f687..f5eb394 100644
--- a/Model/Source/Generic.php
+++ b/Model/Source/Generic.php
@@ -2,19 +2,56 @@
 
 namespace BobGroup\BobGo\Model\Source;
 
+
+use Magento\Framework\Data\OptionSourceInterface;
+use BobGroup\BobGo\Model\Carrier\BobGo;
+
 /**
- * Bob Go Free Method source implementation
+ * bobgo generic source implementation
  */
-class Freemethod extends Method
+class Generic implements OptionSourceInterface
 {
     /**
-     * {@inheritdoc}
+     * @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()
     {
-        //Returns an array of arrays, each of which has a 'value' and a 'label'. The 'value' is the code for the shipping method, and the 'label' is the name of the shipping method.
-        $arr = parent::toOptionArray();
-        array_unshift($arr, ['value' => '', 'label' => __('None')]);
+        $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;
     }
+
 }
diff --git a/etc/config.xml b/etc/config.xml
index 866d2c7..9e4c986 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -9,7 +9,7 @@
 
         <carriers>
             <bobgo>
-                <active>0</active>
+                <active>1</active>
                 <price>0.00</price>
                 <model>BobGroup\BobGo\Model\Carrier\BobGo</model>
                 <name>Fixed</name>
diff --git a/etc/module.xml b/etc/module.xml
index 5e262c8..fe2b36d 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -2,7 +2,7 @@
 <!--
 /**
  * @category   Bob Go
- * @package    bobgo_CustomShipping
+ * @package    BobGo
  * @author     Bob Go
  */
 -->
-- 
GitLab