softcode / module-dawa-address
Danish address autocomplete (DAWA) for the Magento 2 checkout.
Package info
github.com/DritonCa/softcode-magento2-dawa-address
Language:JavaScript
Type:magento2-module
pkg:composer/softcode/module-dawa-address
Requires
- php: ~8.1.0||~8.2.0||~8.3.0||~8.4.0
- magento/framework: >=103.0.6
- magento/module-checkout: >=100.4
- magento/module-config: >=101.2
Requires (Dev)
- phpunit/phpunit: ^9.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Magento 2 module that adds Danish address autocomplete to the checkout using DAWA (Danmarks Adressers Web API):
- Type a postcode → the city fills in automatically
- Start typing a street → get a live address dropdown
- Works with a combined street field or separate street + house-number fields
It runs entirely in the browser (calls DAWA directly, no backend proxy) and stores no personal data, so there is nothing extra to secure or GDPR-audit.
Requirements
| Supported | |
|---|---|
| Magento Open Source / Adobe Commerce | 2.4.6 – 2.4.8 |
| PHP | 8.1 – 8.4 |
Tested by installation, setup:upgrade and setup:di:compile on Magento 2.4.6-p3 with
PHP 8.2; 2.4.7 and 2.4.8 are covered by the Composer constraints but not yet verified
on a live shop.
Installation
composer require softcode/module-dawa-address:^1.2 bin/magento module:enable Softcode_DawaAddress bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush
Configuration
Stores → Configuration → Softcode → DAWA Address:
- Enable the feature
- Choose the street mode — one combined street field, or separate street and house-number fields
- Set the CSS selectors for your postcode, city and street inputs, so it works with any checkout theme or one-page checkout
How it works
Block/Checkout/Init+Model/JsConfigProviderpass the admin settings (enabled flag, street mode, selectors) to the frontend.- The layout (
checkout_index_index.xml) loads the frontend widget on the checkout. web/js/dawa.jswires up two behaviours: postcode → city lookup, and a debounced address autocomplete rendered byweb/js/dropdown.js.
flowchart LR
A["Admin config"] --> JC["JsConfigProvider"] --> JS["dawa.js"]
JS -->|lookup| D["dawa.aws.dk<br/>(postnumre / adresser)"]
JS --> F["fills postcode · city · street"]
Loading
Only DAWA field values are written into the form inputs; nothing is sent to your server or stored.
Testing
The PHP that decides what the frontend widget receives is unit tested, and it
runs without a Magento install — Test/bootstrap.php autoloads the module and
stubs the few Magento contracts it mocks:
phpunit -c phpunit.xml.dist
JsConfigProviderTest pins the activation rules — the widget stays disabled
when the toggle is off or any CSS selector is missing (a safety guard), and the
street-mode/debounce defaults are applied. StreetModeTest checks the admin
dropdown offers exactly separate and combined.
The frontend behaviour is unit tested with Jest + jsdom (no Magento needed):
npm install
npm test
Test/js/dropdown.test.js— mouse selection, keyboardselectActive, arrow-key highlight with clamping, and hide/replace, all through the realdropdown.js.Test/js/dawa.test.js— postcode → city lookup (success and DAWA API failure), debounced autocomplete, keyboardArrowUp/ArrowDown/Enter/Escape, and that repeated focus does not stack duplicate handlers.
Only the full checkout wiring (real DAWA calls, theme layout) still needs a manual smoke test after install.
What CI checks
GitHub Actions runs on every push/PR and fails the build on:
- PHP syntax errors and Magento 2 coding-standard errors (
phpcs --standard=Magento2 -n). - PHP unit-test failures (
phpunit -c phpunit.xml.dist, run as a real gate). - Jest failures — the JS unit tests run in a separate
js-testsjob (npm ci && npm test).
Need help?
Installation or adaptation to your shop: SoftCode – Magento 2 development in Copenhagen.
License
MIT — see LICENSE.