diff --git a/.idea/magento-uafrica-shipping-extension.iml b/.idea/magento-uafrica-shipping-extension.iml index c956989b29ad0767edc6cf3a202545927c3d1e76..07ba03395dc52591611bcc9d278dda63894a7ecf 100644 --- a/.idea/magento-uafrica-shipping-extension.iml +++ b/.idea/magento-uafrica-shipping-extension.iml @@ -1,7 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <module type="WEB_MODULE" version="4"> <component name="NewModuleRootManager"> - <content url="file://$MODULE_DIR$" /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/" isTestSource="false" packagePrefix="bobgo\BobGo\" /> + </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> </component> diff --git a/.idea/php.xml b/.idea/php.xml index 0e1f041b9ee90482c568931419b52676b1beb93b..cd2cd2c40e7fce4613bdad795583ced5d335b37b 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,5 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> + <component name="MessDetectorOptionsConfiguration"> + <option name="transferred" value="true" /> + </component> + <component name="PHPCSFixerOptionsConfiguration"> + <option name="transferred" value="true" /> + </component> + <component name="PHPCodeSnifferOptionsConfiguration"> + <option name="highlightLevel" value="WARNING" /> + <option name="transferred" value="true" /> + </component> <component name="PhpIncludePathManager"> <include_path> <path value="$PROJECT_DIR$/vendor/composer" /> @@ -8,4 +18,10 @@ <component name="PhpProjectSharedConfiguration" php_language_level="7.4"> <option name="suggestChangeDefaultLanguageLevel" value="false" /> </component> + <component name="PhpStanOptionsConfiguration"> + <option name="transferred" value="true" /> + </component> + <component name="PsalmOptionsConfiguration"> + <option name="transferred" value="true" /> + </component> </project> \ No newline at end of file diff --git a/Block/System/Config/Form/Field/Version.php b/Block/System/Config/Form/Field/Version.php index 5d071801a406da9f220bf1fd0093996f8eeb5b3d..52a54e718795145f99d5722b39118853523f6d8b 100644 --- a/Block/System/Config/Form/Field/Version.php +++ b/Block/System/Config/Form/Field/Version.php @@ -12,7 +12,7 @@ use Magento\Framework\Data\Form\Element\AbstractElement; */ 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/Model/Carrier/AdditionalInfo.php b/Model/Carrier/AdditionalInfo.php new file mode 100644 index 0000000000000000000000000000000000000000..0b002a0ff7b8fdf82842f1adceef888dd8aaf052 --- /dev/null +++ b/Model/Carrier/AdditionalInfo.php @@ -0,0 +1,80 @@ +<?php + +namespace BobGroup\BobGo\Model\Carrier; + +/** + * Get the AdditionalInfo information from the request body and return it + */ +class AdditionalInfo +{ + + /** + * @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; + } + + public function getSuburb(): mixed + { + + $data = json_decode(file_get_contents('php://input'), true); + + if (isset($data['address']['custom_attributes'][0]['value'])) { + $destSub = $data['address']['custom_attributes'][0]['value']; + //print_r($destSub); + } else { + $destSub = ''; + } + return $destSub; + } + + /** + * @return mixed|string + */ + public function getDestTelephone(): mixed + { + $data = json_decode(file_get_contents('php://input'), true); + + if (isset($data['address']['telephone'])) { + $destTelephone = $data['address']['telephone']; + } else { + $destTelephone = ''; + } + return $destTelephone; + } + + + /** + * @var \BobGroup\BobGo\Model\Carrier\AdditionalInfo + */ + public $countryFactory; + + public function __construct($countryFactory) + { + $this->countryFactory = $countryFactory; + } + + /** + * country full name + * + * @return string + */ + public function getCountryName($countryId): string + { + $countryName = ''; + $country = $this->countryFactory->create()->loadByCode($countryId); + if ($country) { + $countryName = $country->getName(); + } + return $countryName; + } +} diff --git a/Model/Carrier/BobGo.php b/Model/Carrier/BobGo.php index 431e11b6fcf31a0ed6828d9d2d30321b1d2a5785..2c556743c3ae9985de18760c4ae0361293382a59 100644 --- a/Model/Carrier/BobGo.php +++ b/Model/Carrier/BobGo.php @@ -107,7 +107,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car */ protected JsonFactory $jsonFactory; private $cartRepository; - public Company $company; + public AdditionalInfo $additionalInfo; /** @@ -135,29 +135,29 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, - \Psr\Log\LoggerInterface $logger, - Security $xmlSecurity, - \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, - \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, - \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, - \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, - \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, - \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, - \Magento\Directory\Model\RegionFactory $regionFactory, - \Magento\Directory\Model\CountryFactory $countryFactory, - \Magento\Directory\Model\CurrencyFactory $currencyFactory, - \Magento\Directory\Helper\Data $directoryData, - \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Module\Dir\Reader $configReader, + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, + \Psr\Log\LoggerInterface $logger, + Security $xmlSecurity, + \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, + \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, + \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, + \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, + \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, + \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, + \Magento\Directory\Model\RegionFactory $regionFactory, + \Magento\Directory\Model\CountryFactory $countryFactory, + \Magento\Directory\Model\CurrencyFactory $currencyFactory, + \Magento\Directory\Helper\Data $directoryData, + \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, + \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Framework\Module\Dir\Reader $configReader, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, - JsonFactory $jsonFactory, - CurlFactory $curlFactory, - array $data = [] - - ) { + JsonFactory $jsonFactory, + CurlFactory $curlFactory, + array $data = [] + ) + { $this->_storeManager = $storeManager; $this->_productCollectionFactory = $productCollectionFactory; @@ -181,7 +181,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car ); $this->jsonFactory = $jsonFactory; $this->curl = $curlFactory->create(); - $this->company = new Company(); + $this->additionalInfo = new AdditionalInfo($countryFactory); } @@ -295,35 +295,40 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car return false; } /** - * Gets the destination company name from Company Name field in the checkout page + * Gets the destination company name from AdditionalInfo Name field in the checkout page * This method is used is the last resort to get the company name since the company name is not available in _rateFactory */ $destComp = $this->getDestComp(); $destSuburb = $this->getDestSuburb(); + $destPhone = $this->getDestTelephone(); /** @var \Magento\Shipping\Model\Rate\Result $result */ $result = $this->_rateFactory->create(); $destination = $request->getDestPostcode(); - $destCountry = $request->getDestCountryId(); + $destCountryCode = $request->getDestCountryId(); $destRegion = $request->getDestRegionCode(); $destCity = $request->getDestCity(); $destStreet = $request->getDestStreet(); + $destCountry = $this->getCountryName($destCountryCode); + /** Destination Information */ [$destStreet1, $destStreet2, $destStreet3] = $this->destStreet($destStreet); - /** Origin Information */ - [$originStreet, $originRegion, $originCountry, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier, $originSuburb,$weightUnit] = $this->storeInformation(); + [$originStreet, $originRegion, $originCountryCode, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier, $originSuburb, $weightUnit, $originPhone] = $this->storeInformation(); /** Get all items in cart */ $items = $request->getAllItems(); $itemsArray = []; $itemsArray = $this->getStoreItems($items, $weightUnit, $itemsArray); + $originCountry = $this->getCountryName($originCountryCode); + + $payload = [ 'identifier' => $baseIdentifier, 'rate' => [ @@ -334,8 +339,10 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car 'city' => $originCity, 'suburb' => $originSuburb, 'province' => $originRegion, - 'country_code' => $originCountry, + 'country_code' => $originCountryCode, 'postal_code' => $originStreet, + 'telephone' => $originPhone, + 'country' => $originCountry, ], 'destination' => [ @@ -345,8 +352,10 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car 'suburb' => $destSuburb, 'city' => $destCity, 'province' => $destRegion, - 'country_code' => $destCountry, + 'country_code' => $destCountryCode, 'postal_code' => $destination, + 'telephone' => $destPhone, + 'country' => $destCountry ], 'items' => $itemsArray, ] @@ -363,7 +372,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car public function storeInformation(): array { /** Store Origin details */ - $originCountry = $this->_scopeConfig->getValue( + $originCountryCode = $this->_scopeConfig->getValue( 'general/store_information/country_id', ScopeInterface::SCOPE_STORE ); @@ -400,14 +409,20 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car 'general/store_information/suburb', ScopeInterface::SCOPE_STORE ); + $weightUnit = $this->_scopeConfig->getValue( 'general/locale/weight_unit', ScopeInterface::SCOPE_STORE ); + $originTelephone = $this->_scopeConfig->getValue( + 'general/store_information/phone', + ScopeInterface::SCOPE_STORE + ); + $baseIdentifier = $this->getBaseUrl(); - return array($originStreet, $originRegion, $originCountry, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier, $originSuburb, $weightUnit); + return array($originStreet, $originRegion, $originCountryCode, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier, $originSuburb, $weightUnit, $originTelephone); } @@ -502,7 +517,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car */ public function getTracking($trackings) { - $this->setTrackingReqeust(); + $this->setTrackingRequest(); if (!is_array($trackings)) { $trackings = [$trackings]; @@ -520,7 +535,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car * * @return void */ - protected function setTrackingReqeust() + protected function setTrackingRequest() { $r = new \Magento\Framework\DataObject(); @@ -568,12 +583,12 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car */ //Dev - $tracking->setUrl(uData::TRACKING .$trackingReference); + $tracking->setUrl(uData::TRACKING . $trackingReference); $tracking->setTracking($trackingReference); $tracking->addData($this->processTrackingDetails($trackingReference)); $result->append($tracking); - $counter ++; + $counter++; } //Tracking Details Not Available @@ -814,7 +829,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car */ protected function _formatRates(mixed $rates, Result $result): void { - if (empty($rates)) { + if (!isset($rates['rates'])) { $error = $this->_rateErrorFactory->create(); $error->setCarrierTitle($this->getConfigData('title')); $error->setErrorMessage($this->getConfigData('specificerrmsg')); @@ -824,7 +839,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car foreach ($rates['rates'] as $title) { $method = $this->_rateMethodFactory->create(); - if (isset($title)){ + if (isset($title)) { $method->setCarrier(self::CODE); @@ -865,7 +880,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car 'activity' => $checkpoint['status'], 'deliverydate' => $this->formatDate($checkpoint['time']), 'deliverytime' => $this->formatTime($checkpoint['time']), - // 'deliverylocation' => 'Unavailable',//TODO: remove this line + // 'deliverylocation' => 'Unavailable',//TODO: remove this line ]; } return $result; @@ -959,11 +974,11 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car protected function deliveryDays(int $min_delivery_date, int $max_delivery_date, $method): void { 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 . ' - ' . $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'); + $method->setCarrierTitle('delivery in ' . $min_delivery_date . ' day'); } } } @@ -973,14 +988,31 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car */ public function getDestComp(): mixed { - return $this->company->getDestComp(); + return $this->additionalInfo->getDestComp(); } + /** * @return mixed|string */ public function getDestSuburb(): mixed { - return $this->company->getSuburb(); + return $this->additionalInfo->getSuburb(); + } + + /** + * @return mixed|string + */ + public function getDestTelephone(): mixed + { + return $this->additionalInfo->getDestTelephone(); + } + + /** + * @return mixed|string + */ + public function getCountryName(mixed $country_id): mixed + { + return $this->additionalInfo->getCountryName($country_id); } /** @@ -1009,6 +1041,19 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car { foreach ($items as $item) { + if ($item->getParentItem()) continue; + + $productID = $item->getProductId(); + $product = $item->getProduct(); // Product Object + $description = ""; + + if ($product) { + $productFull = $product->load($productID); + // Remove meta tags from the description + $description = preg_replace('#<[^>]+>#', ' ', $productFull->getDescription()); + $description = preg_replace('!\s+!', ' ', $description); + } + $mass = $this->getItemWeight($weightUnit, $item); $itemsArray[] = [ @@ -1016,6 +1061,8 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car 'quantity' => $item->getQty(), 'price' => $item->getPrice(), 'weight' => round($mass), + 'name' => $item->getName(), + 'description' => $description, ]; } diff --git a/Model/Carrier/Company.php b/Model/Carrier/Company.php deleted file mode 100644 index b5547595722df67b2535db561a06aad3c28b1918..0000000000000000000000000000000000000000 --- a/Model/Carrier/Company.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -namespace BobGroup\BobGo\Model\Carrier; - -/** - * Get the Company information from the request body and return it - */ -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; - } - - public function getSuburb(): mixed - { - - $data = json_decode(file_get_contents('php://input'), true); - - if (isset($data['address']['custom_attributes'][0]['value'])) { - $destSub = $data['address']['custom_attributes'][0]['value']; - //print_r($destSub); - } else { - $destSub = ''; - } - return $destSub; - } -} diff --git a/Model/Carrier/uData.php b/Model/Carrier/uData.php index 4ccffa28748266b3e0d3e379a3c835055bc58f8b..2ef4d2bb7d05a94634a122a220d41a2f849bc495 100644 --- a/Model/Carrier/uData.php +++ b/Model/Carrier/uData.php @@ -10,12 +10,8 @@ class uData { /** Tracking Endpoint */ - //dev - public const TRACKING = 'https://api.dev.bobgo.co.za/tracking?channel=localhost&tracking_reference='; - - //production - //public const TRACKING = 'https://api.dev.bobgo.co.za/tracking?channel=%s&tracking_reference=%s'; + public const TRACKING = 'https://api.bobgo.co.za/tracking?channel=localhost&tracking_reference='; /*** RATES API Endpoint*/ - public const RATES_ENDPOINT = 'https://api.dev.bobgo.co.za/rates-at-checkout/magento'; + public const RATES_ENDPOINT = 'https://api.bobgo.co.za/rates-at-checkout/magento'; } diff --git a/Model/Carrier/uSubs.php b/Model/Carrier/uSubs.php index 283f8b5b7ddc9614c9aeef7848cec348ac303707..5f7dcd8cd5835cd0a38d14e07f69776c02f6048f 100644 --- a/Model/Carrier/uSubs.php +++ b/Model/Carrier/uSubs.php @@ -2,7 +2,7 @@ namespace BobGroup\BobGo\Model\Carrier; -/** Get Company information if available from the Estimate Shipping Methods Request Body */ +/** Get AdditionalInfo information if available from the Estimate Shipping Methods Request Body */ class uSubs { diff --git a/Readme.md b/Readme.md index 1757dd1c4aee4dbe12ae6d84e0a637e311f49e72..95f824f835a6a2b1c203521425156a1c5dde162a 100644 --- a/Readme.md +++ b/Readme.md @@ -1,29 +1,3 @@ -# Installing Magento locally - -**Note:** For more information, visit https://github.com/markshust/docker-magento - -1. Make sure you have `composer` installed globally and a GitHub personal access token configured using `composer global config github-oauth.github.com <YOUR_PERSONAL_ACCESS_TOKEN>` -2. Create a new folder, ie: `Documents/Magento` -3. `cd` into the folder -4. Run command `curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/onelinesetup | bash -s -- bobgomagento.test 2.4.4-p1 community` -5. When asked for the username and password, provide the Abobe public and private key: - -- Public key: `98b4828a495e7e0e13d80d8bf94f3b1c` -- Private key: `082ced46919bffe1b6db0f96de96d608` - -Once configured, do the following to create an admin user (and make life easier for yourself): - -- Create Admin User: `bin/magento admin:user:create` -- Disable 2FA: `bin/magento module:disable Magento_TwoFactorAuth` -- Disable Admin Captcha: `bin/magento config:set admin/captcha/enable 0` - - -### Adobe account details - -- Email: `tech@uafrica.com` -- Password: `mR3mdr0311@P` - - # Magento 2 Bob Go Shipping Extension ## Introduction @@ -41,7 +15,6 @@ A complete guide to install Magento Bob Go Shipping extension in Magento 2. Run the following command in Magento 2 root folder:</br> - >_Note: You must have composer installed on your server & at this point this option_ #### 1. Execute the following command to install the module: @@ -60,7 +33,6 @@ bin/magento setup:di:compile bin/magento setup:static-content:deploy ``` - ### Option 2: Install via zip file 1. Download the extension zip file from the link below: </br> diff --git a/composer.json b/composer.json index 76742bd4a7f0a11b0de9a1d2606feb1895ef279c..4c8558a26ce7627bd54e246acac078f987086fe3 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "bobgo/bobgo", - "description": "Streamline your shipments fulfillment's with Bob Go", + "description": "Streamline your order fulfillments with Bob Go", "type": "magento2-module", "version": "1.0.0", "authors": [