From 6d6f9a42272c213e8852b2803f39843710f20a13 Mon Sep 17 00:00:00 2001 From: Gundo Sifhufhi <sifhufhisg@gmail.com> Date: Mon, 30 Jan 2023 09:43:21 +0200 Subject: [PATCH] Optimization. Instructions Update. --- Model/Carrier/Company.php | 22 +++++++++++++ Model/Carrier/Customshipping.php | 54 +++++++++++++++++--------------- Readme.md | 19 +++++------ 3 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 Model/Carrier/Company.php diff --git a/Model/Carrier/Company.php b/Model/Carrier/Company.php new file mode 100644 index 0000000..4b64158 --- /dev/null +++ b/Model/Carrier/Company.php @@ -0,0 +1,22 @@ +<?php + +namespace uafrica\Customshipping\Model\Carrier; + +class Company +{ + + /** + * @return mixed|string + */ + public function getDestComp(): mixed + { + $data = json_decode(file_get_contents('php://input'), true); + + if (isset($data['address']['company'])) { + $destComp = $data['address']['company']; + } else { + $destComp = ''; + } + return $destComp; + } +} diff --git a/Model/Carrier/Customshipping.php b/Model/Carrier/Customshipping.php index 3e303b3..f1c86eb 100644 --- a/Model/Carrier/Customshipping.php +++ b/Model/Carrier/Customshipping.php @@ -14,7 +14,6 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Controller\Result\JsonFactory; use Magento\Framework\DataObject; use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\HTTP\Client\CurlFactory; use Magento\Framework\Module\Dir\Reader; use Magento\Framework\Xml\Security; @@ -107,7 +106,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ */ protected JsonFactory $jsonFactory; private $cartRepository; - private uSubs $uSubs; + private Company $company; /** @@ -181,7 +180,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ ); $this->jsonFactory = $jsonFactory; $this->curl = $curlFactory->create(); - $this->uSubs = new uSubs(); + $this->company = new Company(); } @@ -230,7 +229,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ /** @var \Magento\Shipping\Model\Rate\Result $result */ $result = $this->_rateFactory->create(); - /** Shippng Address Information **/ + $destination = $request->getDestPostcode(); $destCountry = $request->getDestCountryId(); $destRegion = $request->getDestRegionCode(); @@ -239,7 +238,9 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ list($destStreet1, $destStreet2, $destStreet3) = $this->destStreet($destStreet); - /** Collection Origin Information */ + + + /** Origin Information */ list($originStreet, $originRegion, $originCountry, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier, $originSuburb) = $this->storeInformation(); $items = $request->getAllItems(); @@ -749,15 +750,17 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ if (isset($title)){ $method->setCarrier(self::CODE); - if ($this->getConfigData('additional_info') == 1) { - $min_delivery_date = $this->getWorkingDays(date('Y-m-d'), $title['min_delivery_date']); - $max_delivery_date = $this->getWorkingDays(date('Y-m-d'), $title['max_delivery_date']); - $this->deliveryDays($min_delivery_date, $max_delivery_date, $method); + if ($this->getConfigData('additional_info') == 1) { + $min_delivery_date = $this->getWorkingDays(date('Y-m-d'), $title['min_delivery_date']); + $max_delivery_date = $this->getWorkingDays(date('Y-m-d'), $title['max_delivery_date']); - } else { + $this->deliveryDays($min_delivery_date, $max_delivery_date, $method); + + } else { $method->setCarrierTitle($this->getConfigData('title')); } + } $method->setMethod($title['service_code']); @@ -850,13 +853,6 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ return $rates; } - /** - * @return mixed|string - */ - protected function getDestComp(): mixed - { - return $this->uSubs->getDestCompany(); - } /** * @param string $destStreet @@ -885,15 +881,21 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ */ protected function deliveryDays(int $min_delivery_date, int $max_delivery_date, $method): void { - if ($min_delivery_date == $max_delivery_date) { - if ($min_delivery_date && $max_delivery_date == 1) { - $method->setCarrierTitle('delivery in '.$min_delivery_date . ' day'); - }else { - $method->setCarrierTitle('delivery in ' . $min_delivery_date . ' days'); - } - - }else{ - $method->setCarrierTitle('delivery in '.$min_delivery_date . ' - ' . $max_delivery_date . ' days'); + if ($min_delivery_date !== $max_delivery_date) { + $method->setCarrierTitle('delivery in '.$min_delivery_date . ' - ' . $max_delivery_date . ' days'); + }else{ + $method->setCarrierTitle('delivery in ' . $min_delivery_date . ' days'); + if ($min_delivery_date && $max_delivery_date == 1) { + $method->setCarrierTitle('delivery in '.$min_delivery_date . ' day'); + } } } + + /** + * @return mixed|string + */ + protected function getDestComp(): mixed + { + return $this->company->getDestComp(); + } } diff --git a/Readme.md b/Readme.md index 2cf17e2..f9d0d6c 100644 --- a/Readme.md +++ b/Readme.md @@ -83,34 +83,29 @@ Please visit [Bobgo](https://uafrica.co.za) to create an account. ### ✓ Step 3: Configure Bobgo Shipping Extension -1. Select `Bobgo` as shipping method +1. Select `Bobgo` as shipping method. -[//]: # (2. Enter API key and API secret) -2. Select `Enable` to enable the extension +2. Select `Enable` to enable the extension. -[//]: # (4. Select `Enable Debug Mode` to enable debug mode) -1. Click `Save Config` +3. Click `Save Config` -[//]: # () -[//]: # (2. Flush cache (System > Cache Management) and reindex (System > Index Management) (might be optional)) - -[//]: # () -[//]: # (3. Clear generated files(`rm -rf var/generation/*`)) ### ✓ Step 4: Address Configurations #### Admin Configurations: Update Customer Address Fields* 1. `Stores`>`Configurations`>`Customers` 2. `Customer Configuration`>`Name and Address Options` 3. In Input Field `Number of Lines in a Street Address` -4. Change to `3` Lines. +4. Disable System Value `2` > +5. Lastly ,Change to `3` Lines. #### Admin Configurations: Update Store Information* When the extension is **installed** and **enabled**, a new field will be created in the `Store Information` : `Suburb` and Fill in necessary information; -1. `Stores`>`General`>`General` +1. `Stores`> `Configuration`> `General`>`General` + 2. `Store Information`>`Suburb` ## How it works -- GitLab