diff --git a/Model/Carrier/Customshipping.php b/Model/Carrier/Customshipping.php index bf4b68191edcb4bdf6c32ce0e48460f4534968dc..f0684dd511e4e108f52cad7d0eeec27e20cc5883 100644 --- a/Model/Carrier/Customshipping.php +++ b/Model/Carrier/Customshipping.php @@ -14,6 +14,7 @@ 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; @@ -235,7 +236,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ $destCity = $request->getDestCity(); $destStreet = $request->getDestStreet(); - list($destStreet1, $destStreet2) = $this->destStreet($destStreet); + list($destStreet1, $destStreet2, $destStreet3) = $this->destStreet($destStreet); /** Collection Origin Information */ list($originStreet, $originRegion, $originCountry, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier, $originSuburb) = $this->storeInformation(); @@ -271,7 +272,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ 'company' => $destComp, 'address1' => $destStreet1, 'address2' => $destStreet2, - 'suburb' => '', + 'suburb' => $destStreet3, 'city' => $destCity, 'province' => $destRegion, 'country_code' => $destCountry, @@ -872,10 +873,12 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ $destStreet = explode("\n", $destStreet); $destStreet1 = $destStreet[0]; $destStreet2 = $destStreet[1]; + $destStreet3 = $destStreet[2] ?? ''; } else { $destStreet1 = $destStreet; $destStreet2 = ''; + $destStreet3 = ''; } - return array($destStreet1, $destStreet2); + return array($destStreet1, $destStreet2, $destStreet3); } } diff --git a/Model/Carrier/uSub.php b/Model/Carrier/uSub.php new file mode 100644 index 0000000000000000000000000000000000000000..38040f0eb259f015ba1c4ae46523f69fc738070e --- /dev/null +++ b/Model/Carrier/uSub.php @@ -0,0 +1,25 @@ +<?php + +namespace uafrica\Customshipping\Model\Carrier; +use Magento\Checkout\Api\Data\ShippingInformationInterface; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Quote\Api\CartRepositoryInterface; + + +class uSub { + + + /** + * @throws NoSuchEntityException + */ + public function getDestSuburb() + { + $objectManager = ObjectManager::getInstance(); + $quote = $objectManager->get('Magento\Checkout\Model\ShippingInformation')->getExtensionAttributes(); + return $quote->getSuburb(); + } + + + +} diff --git a/Plugin/Checkout/Block/LayoutProcessorPlugin.php b/Plugin/Checkout/Block/LayoutProcessorPlugin.php index 183ce35586ddd42622816608fd8dfb97ebe67848..d379412da7cfd5c94e1d03968688cd2afe30a592 100644 --- a/Plugin/Checkout/Block/LayoutProcessorPlugin.php +++ b/Plugin/Checkout/Block/LayoutProcessorPlugin.php @@ -35,11 +35,11 @@ class LayoutProcessorPlugin 'id' => 'suburb' ], 'dataScope' => 'shippingAddress.extension_attributes.suburb', - 'label' => 'Suburb', + 'label' => 'Suburb(BobGo Required)', 'provider' => 'checkoutProvider', - 'visible' => true, + 'visible' => false, 'validation' => [ - 'required-entry' => true + 'required-entry' => false ], 'sortOrder' => 110, /*'customEntry' => null,*/ diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..79d332fcf0aba003f083425c3afde641c35733df 100644 --- a/view/frontend/requirejs-config.js +++ b/view/frontend/requirejs-config.js @@ -0,0 +1,9 @@ +var config = { + config: { + mixins: { + 'Magento_Checkout/js/action/set-shipping-information': { + 'uafrica_Customshipping/js/action/set-shipping-information-mixin': true + } + } + } +}; diff --git a/view/frontend/web/js/action/set-shipping-information-mixin.js b/view/frontend/web/js/action/set-shipping-information-mixin.js new file mode 100644 index 0000000000000000000000000000000000000000..1c8327be8ca8e09070cdddcbb8b065c709988745 --- /dev/null +++ b/view/frontend/web/js/action/set-shipping-information-mixin.js @@ -0,0 +1,32 @@ +/*jshint browser:true jquery:true*/ +/*global alert*/ +define([ + 'jquery', + 'mage/utils/wrapper', + 'Magento_Checkout/js/model/quote' +], function ($, wrapper, quote) { + 'use strict'; + + return function (setShippingInformationAction) { + + return wrapper.wrap(setShippingInformationAction, function (originalAction) { + var shippingAddress = quote.shippingAddress(); + if (shippingAddress['extension_attributes'] === undefined) { + shippingAddress['extension_attributes'] = {}; + } + + // var attribute = shippingAddress.customAttributes.find( + // function (element) { + // return element.attribute_code === 'suburb'; + // } + // ); + // + // shippingAddress['extension_attributes']['suburb'] = attribute.value; + + // shippingAddress['extension_attributes']['suburb'] = shippingAddress.value; + + // pass execution to original action ('Magento_Checkout/js/action/set-shipping-information') + return originalAction(); + }); + }; +});