A custom Drupal module that provides a customizable address book display for Drupal Commerce with enhanced template support.
This module is styled with Tailwind CSS 3 by default. The styles can be customized or replaced with your own.
EC Address Book extends Drupal Commerce's address book functionality by allowing you to implement custom templates for displaying user addresses. The module integrates with the Address and Profile modules to provide a flexible way to present customer address information.
- Custom templating for address book display
- Integration with Drupal Commerce address book
- Support for multiple addresses per user
- Default address management
- Full CRUD operations (Create, Read, Update, Delete)
- User-friendly address display with custom Twig templates
- Compatible with Drupal 10 and 11
- Drupal: ^10 || ^11
- Commerce Core (commerce:commerce)
- Address module (address:address)
- Profile module (profile:profile)
-
Download or clone this module into your Drupal
modules/customdirectory:cd modules/custom git clone https://github.com/t1mm1/ec-address-book.git ec_address_book -
Enable the module using Drush:
drush en ec_address_book
Or enable it through the Drupal admin interface at:
Administration > Extend -
Clear the cache:
drush cr
Once installed, users can access their address book at:
/user/{uid}/address-book
The module uses a custom Twig template for rendering the address book. To customize the display:
- Copy the
address-book_html.twigtemplate to your theme's templates directory - Modify the template according to your needs
- Clear the cache
The template receives the following variables:
addresses- Array of address objects with the following properties:profile_id- Profile entity IDis_default- Boolean indicating if this is the default addressgiven_name- First namefamily_name- Last nameorganization- Organization/company nameaddress_line1- Street address line 1address_line2- Street address line 2locality- Cityadministrative_area- State/provincepostal_code- ZIP/postal codecountry_code- Country codeedit_url- URL to edit the addressdelete_url- URL to delete the addressset_default_url- URL to set as default (null if already default)
add_url- URL to add a new address
The module implements custom access control that extends the Commerce address book access system. Users can only access their own address books unless they have administrative permissions.
ec_address_book/
├── ec_address_book.info.yml # Module definition
├── ec_address_book.module # Module hooks
├── ec_address_book.routing.yml # Route definitions
├── src/
│ └── Controller/
│ └── AddressBookController.php # Main controller
└── templates/
└── address-book_html.twig # Twig template
The AddressBookController extends the Commerce AddressBookController and can be further customized:
<?php
namespace Drupal\your_module\Controller;
use Drupal\ec_address_book\Controller\AddressBookController as BaseAddressBookController;
class CustomAddressBookController extends BaseAddressBookController {
// Your customizations here
}The module includes logging functionality. Errors are logged to the ec_address_book channel and can be viewed in the Drupal logs:
drush watchdog:show --type=ec_address_bookNo additional configuration is required. The module works out of the box with the Commerce and Profile modules.
- Ensure users have customer profiles with the type
customer - Verify that the Address field is properly configured on the customer profile
- Check that profiles are published (status = 1)
- Review logs for any errors:
drush watchdog:show --type=ec_address_book
Ensure that users have the appropriate permissions to access their address book. The module checks for _address_book_access permission.
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
For bug reports and feature requests, please use the issue queue on GitHub.
This project is licensed under the GPL-2.0+.
Pavel Kasianov.
Linkedin: https://www.linkedin.com/in/pkasianov/
Drupal org: https://www.drupal.org/u/pkasianov