diff --git a/.idea/csv-editor.xml b/.idea/csv-editor.xml index 24b6446b0b8b01e2df781370444530e768210330..d67b498506b74e8ada1997ff156a18ee8d5ddaa9 100644 --- a/.idea/csv-editor.xml +++ b/.idea/csv-editor.xml @@ -3,7 +3,7 @@ <component name="CsvFileAttributes"> <option name="attributeMap"> <map> - <entry key="$PROJECT_DIR$/uafrica/Customshipping/i18n/en_US.csv"> + <entry key="$PROJECT_DIR$/i18n/en_US.csv"> <value> <Attribute> <option name="separator" value="," /> diff --git a/.idea/php.xml b/.idea/php.xml index 0e09af40726c3560d3f3d145e050377be73a1431..0e1f041b9ee90482c568931419b52676b1beb93b 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,5 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> + <component name="PhpIncludePathManager"> + <include_path> + <path value="$PROJECT_DIR$/vendor/composer" /> + </include_path> + </component> <component name="PhpProjectSharedConfiguration" php_language_level="7.4"> <option name="suggestChangeDefaultLanguageLevel" value="false" /> </component> diff --git a/Model/Carrier/Customshipping.php b/Model/Carrier/Customshipping.php index 306e2f05d4aec66d82f57621423cb8a44897f706..c90a8ec98afeeccd34e2f53f3adb27fd8c687d77 100644 --- a/Model/Carrier/Customshipping.php +++ b/Model/Carrier/Customshipping.php @@ -239,7 +239,7 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ //Get all the origin data from the request /** Origin Information */ - list($originStreet, $originRegion, $originCountry, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier) = $this->storeInformation(); + list($originStreet, $originRegion, $originCountry, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier, $originSuburb) = $this->storeInformation(); $items = $request->getAllItems(); @@ -262,9 +262,11 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ 'address1' => $originStreet1, 'address2' => $originStreet2, 'city' => $originCity, + 'suburb' => $originSuburb, 'province' => $originRegion, 'country_code' => $originCountry, 'postal_code' => $originStreet, + ], 'destination' => [ 'company' => '', // TODO :: Add this if available @@ -290,7 +292,6 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ public function storeInformation(): array { /** Store Origin details */ - $originCountry = $this->_scopeConfig->getValue( 'general/store_information/country_id', ScopeInterface::SCOPE_STORE @@ -324,13 +325,13 @@ class Customshipping extends AbstractCarrierOnline implements \Magento\Shipping\ ScopeInterface::SCOPE_STORE ); - $storePhoneNumber = $this->_scopeConfig->getValue( - 'general/store_information/phone', + $originSuburb = $this->_scopeConfig->getValue( + 'general/store_information/suburb', ScopeInterface::SCOPE_STORE ); $baseIdentifier = $this->getBaseUrl(); - return array($originStreet, $originRegion, $originCountry, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier); + return array($originStreet, $originRegion, $originCountry, $originCity, $originStreet1, $originStreet2, $storeName, $baseIdentifier, $originSuburb); } diff --git a/Plugin/Checkout/Block/LayoutProcessorPlugin.php b/Plugin/Checkout/Block/LayoutProcessorPlugin.php new file mode 100644 index 0000000000000000000000000000000000000000..cc6ef515c515e424660c2f3c2c7703ecf79af54d --- /dev/null +++ b/Plugin/Checkout/Block/LayoutProcessorPlugin.php @@ -0,0 +1,41 @@ +<?php +namespace uafrica\Customshipping\Plugin\Checkout\Block; + +class LayoutProcessorPlugin +{ + /** + * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject + * @param array $jsLayout + * @return array + */ + public function afterProcess( + \Magento\Checkout\Block\Checkout\LayoutProcessor $subject, + array $jsLayout + ) { + + $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children'] + ['shippingAddress']['children']['shipping-address-fieldset']['children']['custom_field_text'] = [ + 'component' => 'Magento_Ui/js/form/element/abstract', + 'config' => [ + 'customScope' => 'shippingAddress.custom_attributes', + 'customEntry' => null, + 'template' => 'ui/form/field', + 'elementTmpl' => 'ui/form/element/input', + 'options' => [], + 'id' => 'suburb' + ], + 'dataScope' => 'shippingAddress.custom_attributes.custom_field_text', + 'label' => 'Suburb', + 'provider' => 'checkoutProvider', + 'visible' => true, + 'validation' => [ + 'required-entry' => true + ], + 'sortOrder' => 110, + /*'customEntry' => null,*/ + 'id' => 'suburb' + ]; + + return $jsLayout; + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 9bbe52d0ef9f0acdecdcfcb48d9918ced0cb84fa..792020a3143a4ee6abca203b862f674a96b01121 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -32,6 +32,14 @@ </field> </group> </section> + <section id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> + <group id="store_information" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> + <field id="suburb" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0"> + <label>Suburb</label> + <can_be_empty>1</can_be_empty> + </field> + </group> + </section> <section id="carriers" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <group id="uafrica" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1"> <label>uAfrica</label> diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml new file mode 100644 index 0000000000000000000000000000000000000000..7a9bd2b68f47505ebccc475551bf3937a4457ac8 --- /dev/null +++ b/etc/frontend/di.xml @@ -0,0 +1,5 @@ +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> + <type name="Magento\Checkout\Block\Checkout\LayoutProcessor"> + <plugin name="add_custom_field_checkout_shipping_form" type="uafrica\Customshipping\Plugin\Checkout\Block\LayoutProcessorPlugin" sortOrder="10"/> + </type> +</config>