├── LICENSE_AFL.txt ├── src ├── registration.php ├── etc │ ├── module.xml │ ├── frontend │ │ └── di.xml │ ├── csp_whitelist.xml │ ├── config.xml │ └── adminhtml │ │ └── system.xml ├── view │ └── frontend │ │ ├── web │ │ ├── css │ │ │ └── source │ │ │ │ └── _module.less │ │ └── js │ │ │ ├── google_maps_loader.js │ │ │ └── autocomplete.js │ │ ├── layout │ │ ├── customer_address_form.xml │ │ └── checkout_index_index.xml │ │ └── templates │ │ └── address │ │ └── autocomplete.phtml ├── composer.json ├── ViewModel │ └── Autocomplete.php ├── Helper │ └── Data.php └── Model │ └── AutocompleteConfigProvider.php ├── composer.json ├── .gitlab-ci.yml ├── README.md ├── CHANGELOG.md ├── CHANGELOG-PUBLIC.MD └── LICENSE.txt /LICENSE_AFL.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shipperhq/module-address-autocomplete/HEAD/LICENSE_AFL.txt -------------------------------------------------------------------------------- /src/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/view/frontend/web/css/source/_module.less: -------------------------------------------------------------------------------- 1 | /* 2 | * ShipperHQ 3 | * 4 | * @category ShipperHQ 5 | * @package ShipperHQ\AddressAutocomplete 6 | * @copyright Copyright (c) 2020 Zowta LTD and Zowta LLC (http://www.ShipperHQ.com) 7 | * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 8 | * @author ShipperHQ Team sales@shipperhq.com 9 | */ 10 | 11 | // We acknowledge this contribution from jmonschke via github https://github.com/shipperhq/module-address-autocomplete/issues/5 12 | // MNB-401 Changed from +1 to +5 to account for @modal-popup__z-index being higher on 2.3.5 for logged in customers 13 | @googleplaces__z-index: @modal__z-index + 5; 14 | 15 | .pac-container { 16 | z-index: @googleplaces__z-index !important; 17 | } 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shipperhq/module-address-autocomplete", 3 | "description": "ShipperHQ Address Autocomplete Tool", 4 | "type": "magento2-module", 5 | "version": "20.6.11", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "authors": [ 11 | { 12 | "name": "ShipperHQ", 13 | "email": "sales@shipperhq.com", 14 | "homepage": "http://www.Shipperhq.com" 15 | }, 16 | { 17 | "name": "Zowta LLC" 18 | } 19 | ], 20 | "support": { 21 | "documentation": "http://docs.shipperhq.com" 22 | }, 23 | "autoload": { 24 | "files": [ 25 | "src/registration.php" 26 | ], 27 | "psr-4": { 28 | "ShipperHQ\\AddressAutocomplete\\": "src/" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shipperhq/module-address-autocomplete", 3 | "description": "ShipperHQ Address Autocomplete Tool", 4 | "type": "magento2-module", 5 | "version": "20.6.11", 6 | "license": [ 7 | "OSL-3.0", 8 | "AFL-3.0" 9 | ], 10 | "authors": [ 11 | { 12 | "name": "ShipperHQ", 13 | "email": "sales@shipperhq.com", 14 | "homepage": "http://www.Shipperhq.com" 15 | }, 16 | { 17 | "name": "Zowta LLC" 18 | } 19 | ], 20 | "support": { 21 | "documentation": "http://docs.shipperhq.com" 22 | }, 23 | "require": { 24 | "shipperhq/module-shipper": "^20.0" 25 | }, 26 | "autoload": { 27 | "files": [ 28 | "registration.php" 29 | ], 30 | "psr-4": { 31 | "ShipperHQ\\AddressAutocomplete\\": "" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/etc/frontend/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | ShipperHQ\AddressAutocomplete\Model\AutocompleteConfigProvider 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/ViewModel/Autocomplete.php: -------------------------------------------------------------------------------- 1 | _scopeConfig = $scopeConfig; 28 | } 29 | 30 | /** 31 | * Get config value. 32 | * 33 | * @param string $path 34 | * @return string|null 35 | */ 36 | public function getConfig($path) 37 | { 38 | return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | include: 2 | - project: ShipperHQ/DevOps/GitLabTemplates 3 | ref: INFRA-672 4 | file: /magento/release.gitlab-ci.yml 5 | 6 | stages: 7 | - tag 8 | - release to GitLab 9 | - release to GitHub 10 | 11 | # Denote whether to build major, minor or patch release 12 | major release: 13 | stage: tag 14 | variables: 15 | VERSION_INCREMENT: "major" 16 | extends: 17 | - .m2_module_release 18 | 19 | minor release: 20 | stage: tag 21 | variables: 22 | VERSION_INCREMENT: "minor" 23 | extends: 24 | - .m2_module_release 25 | 26 | patch release: 27 | stage: tag 28 | variables: 29 | VERSION_INCREMENT: "patch" 30 | extends: 31 | - .m2_module_release 32 | 33 | # Build public release 34 | build release to GitHub: 35 | stage: release to GitHub 36 | variables: 37 | GITHUB_REPO: "git@github.com:shipperhq/module-address-autocomplete.git" 38 | when: on_success 39 | needs: 40 | - job: major release 41 | optional: true 42 | - job: minor release 43 | optional: true 44 | - job: patch release 45 | optional: true 46 | extends: 47 | - .m2_public_release 48 | 49 | -------------------------------------------------------------------------------- /src/view/frontend/layout/customer_address_form.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | ShipperHQ\AddressAutocomplete\ViewModel\Autocomplete 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/view/frontend/web/js/google_maps_loader.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ShipperHQ 3 | * 4 | * @category ShipperHQ 5 | * @package ShipperHQ\AddressAutocomplete 6 | * @copyright Copyright (c) 2020 Zowta LTD and Zowta LLC (http://www.ShipperHQ.com) 7 | * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 8 | * @author ShipperHQ Team sales@shipperhq.com 9 | */ 10 | 11 | //credit: https://gist.github.com/MattSurabian/7868115 12 | var google_maps_loaded_def = null; 13 | 14 | define(['jquery'],function ($) { 15 | 16 | if (!google_maps_loaded_def) { 17 | google_maps_loaded_def = $.Deferred(); 18 | window.google_maps_loaded = function () { 19 | google_maps_loaded_def.resolve(google.maps); 20 | } 21 | var apiKey = window.checkoutConfig.shipperhq_autocomplete.api_key; 22 | if (apiKey != 'false' && apiKey !== null) { 23 | var url = 'https://maps.googleapis.com/maps/api/js?key=' + apiKey + '&libraries=places&callback=google_maps_loaded'; 24 | require([url], function () {}, function (err) { 25 | google_maps_loaded_def.reject(); 26 | }); 27 | } 28 | } 29 | return google_maps_loaded_def.promise(); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /src/etc/csp_whitelist.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | maps.googleapis.com 18 | 19 | 20 | 21 | 22 | maps.googleapis.com 23 | 24 | 25 | 26 | 27 | maps.gstatic.com 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/view/frontend/layout/checkout_index_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 0 23 | ShipperHQ_AddressAutocomplete/js/autocomplete 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 32 | 33 | 34 | 35 | 36 | 1 37 | 0 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/Helper/Data.php: -------------------------------------------------------------------------------- 1 | scopeConfig->isSetFlag($configField, ScopeInterface::SCOPE_STORE); 57 | } 58 | 59 | /** 60 | * Get Config Value 61 | * 62 | * @param $configField 63 | * @param null $store 64 | * @return mixed 65 | */ 66 | public function getConfigValue($configField, $store = null) 67 | { 68 | return $this->scopeConfig->getValue( 69 | $configField, 70 | ScopeInterface::SCOPE_STORE, 71 | $store 72 | ); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/Model/AutocompleteConfigProvider.php: -------------------------------------------------------------------------------- 1 | helper = $helper; 51 | } 52 | 53 | /** 54 | * {@inheritdoc} 55 | */ 56 | public function getConfig() 57 | { 58 | $config['shipperhq_autocomplete'] = [ 59 | 'active' => $this->helper->getConfigValue('shipping/shipper_autocomplete/active'), 60 | 'api_key' => $this->helper->getConfigValue('shipping/shipper_autocomplete/google_api_key'), 61 | 'use_geolocation' => $this->helper->getConfigValue('shipping/shipper_autocomplete/use_geolocation'), 62 | 'use_long_postcode' => $this->helper->getConfigValue('shipping/shipper_autocomplete/use_long_postcode') 63 | ]; 64 | return $config; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ShipperHQ Address Auto-Complete 2 | 3 | The ShipperHQ Address Auto-Complete extension enhances Magento 2 stores by integrating Google's Address Auto-Complete API. This extension simplifies the checkout process by enabling address lookup functionality, improving user experience, and reducing address entry errors. 4 | 5 | You do **not** need a ShipperHQ account to use this extension. More information on ShipperHQ capabilities is available at [ShipperHQ](https://shipperhq.com/magento2). 6 | 7 | --- 8 | 9 | ## Features 10 | 11 | - **Seamless Address Auto-Complete**: Instantly suggest addresses as customers type. 12 | - **Guest & Logged-In Customer Support**: 13 | - Auto-complete available for guest checkout shipping addresses. 14 | - Auto-complete for logged-in users adding a new address to their address book. 15 | - Supports new shipping address entry at checkout. 16 | - **Google API Integration**: Requires a Google API key with access to the *Google Places API Web Service*. 17 | 18 | --- 19 | 20 | ## Requirements 21 | 22 | - Magento 2.4.4+ 23 | - Compatibility with earlier editions is possible but not maintained 24 | - Supports both Magento Opensource (Community) and Magento Commerce (Enterprise) 25 | 26 | --- 27 | 28 | ## Installation 29 | 30 | Install using Composer by running the following commands: 31 | 32 | ```bash 33 | composer require shipperhq/module-address-autocomplete 34 | composer update 35 | php bin/magento setup:upgrade 36 | ``` 37 | 38 | We recommend installing the ShipperHQ Logging module for enhanced debugging: 39 | 40 | ```bash 41 | composer require shipperhq/module-logger 42 | composer update 43 | php bin/magento setup:upgrade 44 | ``` 45 | 46 | --- 47 | 48 | ## Configuration 49 | 50 | 1. Navigate to `Stores > Configuration > Sales > Shipping Settings`. 51 | 2. Open the **ShipperHQ Address Auto-Complete** tab and enable the extension. 52 | 3. Enter your **Google API Key**. If you do not have one, register and ensure you have enabled the *Google Places API Web Service* on your [Google account](https://developers.google.com/maps/documentation/places/web-service/get-api-key). 53 | 4. Save the configuration. 54 | 5. Refresh the Magento cache from `System > Cache Management`. 55 | 56 | For further setup details, visit [our configuration guide](http://docs.shipperhq.com/configure-shipperhq-address-autocomplete/). 57 | 58 | --- 59 | 60 | ## Limitations 61 | 62 | - Address auto-complete is **not supported** on any admin forms. 63 | - Address auto-complete is **not available** for billing addresses. 64 | 65 | --- 66 | 67 | ## Support 68 | 69 | As a free extension, ShipperHQ Address Auto-Complete is provided as-is without support. 70 | 71 | --- 72 | 73 | ## Contribution 74 | 75 | Any contribution is highly appreciated. The best way to contribute code is to open a [pull request on GitHub](https://help.github.com/articles/using-pull-requests). 76 | 77 | --- 78 | 79 | ## License 80 | 81 | See license files. 82 | 83 | --- 84 | 85 | ## Copyright 86 | 87 | Copyright (c) 2015 Zowta LLC ([ShipperHQ](http://www.ShipperHQ.com)) 88 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | This project adheres to Semantic Versioning(http://semver.org/). 4 | 5 | ## 1.0.0 6 | Initial Release 7 | 8 | ## 1.0.1 9 | SHQ16-2072 address autocomplete changes 10 | 11 | ## 1.0.2 12 | SHQ16-2072 address autocomplete changes 13 | 14 | ## 1.0.3 15 | SHQ16-2112 support for address elements specific to New York, UK and Sweden 16 | 17 | ## 1.0.4 18 | SHQ16-2150 handle no API key, increase z-index and handle apartment number 19 | 20 | ## 1.0.5 21 | SHQ16-2150 handle no API key, increase z-index and handle apartment number. Also changed tagged version number 22 | 23 | ## 20.0.5 24 | SHQ16-2150 handle no API key, increase z-index and handle apartment number. Also changed tagged version number 25 | 26 | ## 20.0.6 27 | SHQ16-2244 add polyfill for IE 11 issue 28 | 29 | ## 20.1.0 30 | SHQ16-2328 moved css for autocomplete to less file 31 | 32 | ## 20.1.1 33 | M2-56 code sniffer changes 34 | 35 | ## 20.1.2 36 | Updated README with grammar corrections 37 | 38 | ## 20.1.3 39 | SHQ18-65 - handle Google API authentication errors 40 | ## 20.2.1 (2018-07-27) 41 | SHQ18-260 Disable Google Chrome autofill if address lookup is enabled 42 | 43 | 44 | ## 20.3.0 (2018-12-18) 45 | Added a setting to use extended postcodes when available 46 | 47 | 48 | ## 20.3.1 (2020-06-18) 49 | MNB-401 Fix issue with popup rendering for logged in users 50 | 51 | 52 | ## 20.3.2 (2020-12-21) 53 | MNB-532 Fix use long zip option 54 | 55 | 56 | ## 20.3.3 (2021-04-01) 57 | MNB-1058 Fix conditionals and fix issue with whole address printing in street line 1 58 | 59 | 60 | ## 20.4.0 (2021-06-01) 61 | RIV-534 support Enhanced Checkout 62 | 63 | 64 | ## 20.5.0 (2021-11-30) 65 | MNB-1843 User submitted enhancement to refactor add new address UI. MNB-1789 Fix for street address becoming uneditable on Google API error 66 | 67 | 68 | ## 20.5.1 (2022-01-17) 69 | MNB-1966 Fix for Quebec not populating and added CSP whitelist 70 | 71 | 72 | ## 20.6.0 (2022-01-24) 73 | MNB-574 Add support for placing house number after street name 74 | 75 | 76 | ## 20.6.1 (2022-05-24) 77 | MNB-2364 Resolve issue with Montreal not being populated as city 78 | 79 | 80 | ## 20.6.2 (2023-04-13) 81 | SHQ23-326 Fix issue with formatting of US addresses containing an apartment or suite number 82 | 83 | 84 | ## 20.6.3 (2024-06-03) 85 | SHQ23-2640 Remove trailing comma from stress address 86 | 87 | 88 | ## 20.6.4 (2024-09-19) 89 | SHQ23-3384 Add Google domain to connect-src in csp_whitelist.xml 90 | 91 | 92 | ## 20.6.5 (2024-10-21) 93 | SHQ23-3585 Fix issue with apartment numbers being omitted in address book 94 | 95 | 96 | ## 20.6.7 (2025-01-31) 97 | INFRA-893 Added missing build mp step 98 | 99 | 100 | ## 20.6.8 (2025-02-06) 101 | SHQ23-4310 Fix error in customer address book phtml file 102 | 103 | 104 | ## 20.6.9 (2025-08-21) 105 | SHQ23-5374 Fixing copyrights 106 | 107 | 108 | ## 20.6.10 (2025-08-21) 109 | SHQ23-5374 Fix unescaped output in phtml 110 | 111 | 112 | ## 20.6.11 (2025-11-06) 113 | INFRA-1328 - Removed incorrect case-sensitive version of file 114 | 115 | 116 | -------------------------------------------------------------------------------- /CHANGELOG-PUBLIC.MD: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | This project adheres to Semantic Versioning(http://semver.org/). 4 | 5 | ## 1.0.0 6 | Initial Release 7 | 8 | ## 1.0.1 9 | SHQ16-2072 address autocomplete changes 10 | 11 | ## 1.0.2 12 | SHQ16-2072 address autocomplete changes 13 | 14 | ## 1.0.3 15 | SHQ16-2112 support for address elements specific to New York, UK and Sweden 16 | 17 | ## 1.0.4 18 | SHQ16-2150 handle no API key, increase z-index and handle apartment number 19 | 20 | ## 1.0.5 21 | SHQ16-2150 handle no API key, increase z-index and handle apartment number. Also changed tagged version number 22 | 23 | ## 20.0.5 24 | SHQ16-2150 handle no API key, increase z-index and handle apartment number. Also changed tagged version number 25 | 26 | ## 20.0.6 27 | SHQ16-2244 add polyfill for IE 11 issue 28 | 29 | ## 20.1.0 30 | SHQ16-2328 moved css for autocomplete to less file 31 | 32 | ## 20.1.1 33 | M2-56 code sniffer changes 34 | 35 | ## 20.1.2 36 | Updated README with grammar corrections 37 | 38 | ## 20.1.3 39 | SHQ18-65 - handle Google API authentication errors 40 | ## 20.2.1 (2018-07-27) 41 | SHQ18-260 Disable Google Chrome autofill if address lookup is enabled 42 | 43 | 44 | ## 20.3.0 (2018-12-18) 45 | Added a setting to use extended postcodes when available 46 | 47 | 48 | ## 20.3.1 (2020-06-18) 49 | MNB-401 Fix issue with popup rendering for logged in users 50 | 51 | 52 | ## 20.3.2 (2020-12-21) 53 | MNB-532 Fix use long zip option 54 | 55 | 56 | ## 20.3.3 (2021-04-01) 57 | MNB-1058 Fix conditionals and fix issue with whole address printing in street line 1 58 | 59 | 60 | ## 20.4.0 (2021-06-01) 61 | RIV-534 support Enhanced Checkout 62 | 63 | 64 | ## 20.5.0 (2021-11-30) 65 | MNB-1843 User submitted enhancement to refactor add new address UI. MNB-1789 Fix for street address becoming uneditable on Google API error 66 | 67 | 68 | ## 20.5.1 (2022-01-17) 69 | MNB-1966 Fix for Quebec not populating and added CSP whitelist 70 | 71 | 72 | ## 20.6.0 (2022-01-24) 73 | MNB-574 Add support for placing house number after street name 74 | 75 | 76 | ## 20.6.1 (2022-05-24) 77 | MNB-2364 Resolve issue with Montreal not being populated as city 78 | 79 | 80 | ## 20.6.2 (2023-04-13) 81 | SHQ23-326 Fix issue with formatting of US addresses containing an apartment or suite number 82 | 83 | 84 | ## 20.6.3 (2024-06-03) 85 | SHQ23-2640 Remove trailing comma from stress address 86 | 87 | 88 | ## 20.6.4 (2024-09-19) 89 | SHQ23-3384 Add Google domain to connect-src in csp_whitelist.xml 90 | 91 | 92 | ## 20.6.5 (2024-10-21) 93 | SHQ23-3585 Fix issue with apartment numbers being omitted in address book 94 | 95 | 96 | ## 20.6.7 (2025-01-31) 97 | INFRA-893 Added missing build mp step 98 | 99 | 100 | ## 20.6.8 (2025-02-06) 101 | SHQ23-4310 Fix error in customer address book phtml file 102 | 103 | 104 | ## 20.6.9 (2025-08-21) 105 | SHQ23-5374 Fixing copyrights 106 | 107 | 108 | ## 20.6.10 (2025-08-21) 109 | SHQ23-5374 Fix unescaped output in phtml 110 | 111 | 112 | ## 20.6.11 (2025-11-06) 113 | INFRA-1328 - Removed incorrect case-sensitive version of file 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 32 | 34 | 35 |
36 | 38 | 39 | 40 | 42 | For configuration instructions and further information, please see the ShipperHQ Address Autocomplete knowledge base.

43 | If you have questions about ShipperHQ or need support, visit http://www.ShipperHQ.com.
44 | ShipperHQ is a product of WebShopApps, developers of powerful shipping solutions for Magento.
45 | 46 | ]]> 47 |
48 | 50 | 51 | Magento\Config\Model\Config\Source\Yesno 52 | 53 | 55 | 56 | How to obtain Google API Key]]> 57 | 58 | 60 | 61 | Magento\Config\Model\Config\Source\Yesno 62 | 63 | 66 | 67 | 68 | 70 | 71 | Magento\Config\Model\Config\Source\Yesno 72 | 73 | 76 | 77 | 78 |
79 |
80 |
81 |
82 | -------------------------------------------------------------------------------- /src/view/frontend/templates/address/autocomplete.phtml: -------------------------------------------------------------------------------- 1 | getViewModel(); 18 | 19 | ?> 20 | 190 | 193 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Open Software License ("OSL") v. 3.0 3 | 4 | This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: 5 | 6 | Licensed under the Open Software License version 3.0 7 | 8 | 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: 9 | 10 | 1. to reproduce the Original Work in copies, either alone or as part of a collective work; 11 | 12 | 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; 13 | 14 | 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; 15 | 16 | 4. to perform the Original Work publicly; and 17 | 18 | 5. to display the Original Work publicly. 19 | 20 | 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. 21 | 22 | 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. 23 | 24 | 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. 25 | 26 | 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). 27 | 28 | 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. 29 | 30 | 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. 31 | 32 | 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. 33 | 34 | 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). 35 | 36 | 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. 37 | 38 | 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. 39 | 40 | 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. 41 | 42 | 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. 43 | 44 | 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 45 | 46 | 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. 47 | 48 | 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. -------------------------------------------------------------------------------- /src/view/frontend/web/js/autocomplete.js: -------------------------------------------------------------------------------- 1 | /* 2 | * ShipperHQ 3 | * 4 | * @category ShipperHQ 5 | * @package ShipperHQ\AddressAutocomplete 6 | * @copyright Copyright (c) 2020 Zowta LTD and Zowta LLC (http://www.ShipperHQ.com) 7 | * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 8 | * @author ShipperHQ Team sales@shipperhq.com 9 | */ 10 | 11 | define( 12 | [ 13 | 'jquery', 14 | 'uiComponent', 15 | 'ShipperHQ_AddressAutocomplete/js/google_maps_loader', 16 | 'Magento_Checkout/js/checkout-data' , 17 | 'uiRegistry' 18 | ], 19 | function ( 20 | $, 21 | Component, 22 | GoogleMapsLoader, 23 | checkoutData, 24 | uiRegistry 25 | ) { 26 | var componentForm = { 27 | subpremise: 'short_name', 28 | street_number: 'short_name', 29 | route: 'long_name', 30 | locality: 'long_name', 31 | administrative_area_level_1: 'long_name', 32 | country: 'short_name', 33 | postal_code: 'short_name', 34 | postal_code_suffix: 'short_name', 35 | postal_town: 'short_name', 36 | sublocality_level_1: 'short_name' 37 | }; 38 | 39 | var lookupElement = { 40 | street_number: 'street_1', 41 | route: 'street_2', 42 | locality: 'city', 43 | administrative_area_level_1: 'region', 44 | country: 'country_id', 45 | postal_code: 'postcode' 46 | }; 47 | 48 | var googleMapError = false; 49 | window.gm_authFailure = function () { 50 | $('input[name^="street"]').prop('disabled', false).prop('placeholder', '').removeAttr("style") 51 | google.maps.event.clearInstanceListeners($('input[name^="street"]')[0]); 52 | $(".pac-container").remove(); 53 | googleMapError = true; 54 | }; 55 | 56 | // MNB-574 Some European countries place the house number after the street name rather than before. 57 | var numberAfterStreetCountries = ['AT', 'BE', 'DK', 'DE', 'GR', 'IS', 'IT', 'NL', 'NO', 'PT', 'ES', 'SE', 'CH']; 58 | var numberAfterStreet = false; 59 | 60 | GoogleMapsLoader.done( 61 | function () { 62 | var enabled = window.checkoutConfig.shipperhq_autocomplete.active; 63 | 64 | var geocoder = new google.maps.Geocoder(); 65 | setTimeout( 66 | function () { 67 | if (!googleMapError) { 68 | if (enabled === '1') { 69 | var domID = uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.street').elems()[0].uid; 70 | 71 | var street = $('#' + domID); 72 | 73 | // SHQ18-260. 74 | var observer = new MutationObserver( 75 | function () { 76 | observer.disconnect(); 77 | $("#" + domID).attr("autocomplete", "new-password"); 78 | } 79 | ); 80 | 81 | street.each( 82 | function () { 83 | var self = this; 84 | 85 | observer.observe( 86 | self, 87 | { 88 | attributes: true, 89 | attributeFilter: ['autocomplete'] 90 | } 91 | ); 92 | 93 | autocomplete = new google.maps.places.Autocomplete((this),{types: ['geocode']}); 94 | autocomplete.addListener('place_changed', fillInAddress); 95 | } 96 | ); 97 | $('#' + domID).focus(geolocate); 98 | }//end if 99 | }//end if 100 | }, 101 | 5000 102 | ); 103 | } 104 | ).fail( 105 | function () { 106 | console.error("ERROR: Google maps library failed to load"); 107 | } 108 | ); 109 | 110 | var fillInAddress = function () { 111 | var place = autocomplete.getPlace(); 112 | 113 | var street = []; 114 | var region = ''; 115 | var streetNumber = ''; 116 | var city = ''; 117 | var postcode = ''; 118 | var postcodeSuffix = ''; 119 | var subpremise = ''; // This is apartment/unit/flat number etc 120 | var countryId = ''; 121 | 122 | for (var i = 0; i < place.address_components.length; i++) { 123 | var addressType = place.address_components[i].types[0]; 124 | if (componentForm[addressType]) { 125 | var value = place.address_components[i][componentForm[addressType]]; 126 | if (addressType === 'subpremise') { 127 | subpremise = value; 128 | } else if (addressType === 'street_number') { 129 | streetNumber = value; 130 | } else if (addressType === 'route') { 131 | street[1] = value; 132 | } else if (addressType === 'administrative_area_level_1') { 133 | region = value; 134 | } else if (addressType === 'sublocality_level_1') { 135 | city = value; 136 | } else if (addressType === 'postal_town') { 137 | city = value; 138 | } else if (addressType === 'locality' && (city === '' || value === 'Montréal')) { 139 | // Ignore if we are using one of other city values already. 140 | // MNB-2364 Google returns sublocality_level_1 for Montreal. Always want to use Montreal 141 | city = value; 142 | } else if (addressType === 'postal_code') { 143 | postcode = value; 144 | var thisDomID = uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.postcode').uid 145 | if ($('#' + thisDomID).length) { 146 | $('#' + thisDomID).val(postcode + postcodeSuffix); 147 | $('#' + thisDomID).trigger('change'); 148 | } 149 | } else if (addressType === 'postal_code_suffix' && window.checkoutConfig.shipperhq_autocomplete.use_long_postcode === '1') { 150 | postcodeSuffix = '-' + value; 151 | var thisDomID = uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.postcode').uid 152 | if ($('#' + thisDomID).length) { 153 | $('#' + thisDomID).val(postcode + postcodeSuffix); 154 | $('#' + thisDomID).trigger('change'); 155 | } 156 | } else { 157 | var elementId = lookupElement[addressType]; 158 | if (elementId !== undefined) { 159 | var thisDomID = uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.' + elementId).uid; 160 | if ($('#' + thisDomID).length) { 161 | $('#' + thisDomID).val(value); 162 | $('#' + thisDomID).trigger('change'); 163 | } 164 | 165 | if (elementId === 'country_id') { 166 | countryId = value; 167 | numberAfterStreet = numberAfterStreetCountries.includes(countryId); 168 | } 169 | } 170 | }//end if 171 | }//end if 172 | }//end for 173 | 174 | // SHQ23-326 US Address Format is street address, unit or apartment number 175 | if (subpremise.length > 0 && countryId !== 'US') { 176 | streetNumber = subpremise + '/' + streetNumber; 177 | } 178 | 179 | if (street.length > 0) { 180 | if (numberAfterStreet) { 181 | street[0] = street[1]; 182 | street[1] = streetNumber; 183 | } else { 184 | street[0] = streetNumber; 185 | } 186 | 187 | var domID = uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.street').elems()[0].uid; 188 | var streetString = street.join(' '); 189 | 190 | if (countryId === 'US' && subpremise !== '') { 191 | streetString += ', ' + subpremise 192 | } 193 | 194 | if ($('#' + domID).length) { 195 | $('#' + domID).val(streetString); 196 | $('#' + domID).trigger('change'); 197 | } 198 | } 199 | 200 | var cityDomID = uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.city').uid; 201 | if ($('#' + cityDomID).length) { 202 | $('#' + cityDomID).val(city); 203 | $('#' + cityDomID).trigger('change'); 204 | } 205 | 206 | if (region !== '') { 207 | // MNB-1966 AutoComplete does not fill in Quebec field when an accent mark is returned from Google. 208 | if (region === 'Québec') { 209 | region = 'Quebec' 210 | } 211 | 212 | if (uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.region_id')) { 213 | var regionDomId = uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.region_id').uid; 214 | if ($('#' + regionDomId).length) { 215 | // Search for and select region using text. 216 | $('#' + regionDomId + ' option') 217 | .filter( 218 | function () { 219 | return $.trim($(this).text()) == region; 220 | } 221 | ) 222 | .attr('selected',true); 223 | $('#' + regionDomId).trigger('change'); 224 | } 225 | } 226 | 227 | if (uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.region_id_input')) { 228 | var regionDomId = uiRegistry.get('checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset.region_id_input').uid; 229 | if ($('#' + regionDomId).length) { 230 | $('#' + regionDomId).val(region); 231 | $('#' + regionDomId).trigger('change'); 232 | } 233 | } 234 | }//end if 235 | } 236 | 237 | geolocate = function () { 238 | if (navigator.geolocation && window.checkoutConfig.shipperhq_autocomplete.use_geolocation === '1') { 239 | navigator.geolocation.getCurrentPosition( 240 | function (position) { 241 | var geolocation = { 242 | lat: position.coords.latitude, 243 | lng: position.coords.longitude 244 | }; 245 | var circle = new google.maps.Circle( 246 | { 247 | center: geolocation, 248 | radius: position.coords.accuracy 249 | } 250 | ); 251 | autocomplete.setBounds(circle.getBounds()); 252 | } 253 | ); 254 | } 255 | } 256 | return Component; 257 | } 258 | ); 259 | --------------------------------------------------------------------------------