You are here

README.txt in Ubercart Addresses 6.2

Same filename in this branch
  1. 6.2 README.txt
  2. 6.2 uc_addresses_example/README.txt
Same filename and directory in other branches
  1. 7 uc_addresses_example/README.txt
Ubercart Addresses example module
------------------------
This example module demonstrates how you can add extra address
fields through the Ubercart Addresses field handler API.

It adds three example text fields:
- A title field (for use, see http://en.wikipedia.org/wiki/Title)
- Surname prefix (such as "van", "von" or "de"
    see also: http://en.wikipedia.org/wiki/Tussenvoegsel)
- House number

The schema's of uc_addresses and uc_orders are altered to save
the extra field values.

For a quick start (and if you only need extra text fields), you
can alter the field definitions. In this example module, fields
are defined for the Ubercart Addresses field handler API and for
the schema API.
The field definitions for the field handler API can be found in
the function uc_addresses_example_uc_addresses_fields() from
uc_addresses_example.module.
The field definitions for the schema API can be found in the
function _uc_addresses_example_schema_fields() from
uc_addresses_example.install.

If you like to learn more, follow the instructions below.


Registering address fields
---------------------
You can register address fields for Ubercart Addresses by
implementing hook_uc_addresses_fields() as is done in
uc_addresses_example.module. Each field also needs a handler.
You can use existing handlers or define a new handler.
Defining a new handler is done by implementing
hook_uc_addresses_field_handlers().

This module defines a field handler for simple text fields.
You can find this handler in handlers/uc_addresses.handlers.inc.

For more information about fields and field handlers, check
the online documentation:
http://drupal.org/node/1340694


Saving field values
---------------------
When you register an address field, this doesn't mean
Ubercart Addresses automatically cares for saving it's value.
For this you need to either:
- implement a couple of hooks (see further)
- altering the schema's of uc_addresses and uc_orders.

This example module only demonstrates how to alter the schema's.


How to alter the schema's
---------------------
1. Implement hook_schema_alter() to alter the schema definitions.
2. Implement hook_install() to add the database fields.
3. Implement hook_uninstall() to remove the database fields.

This example module demonstrates a possible way to do that in
the file uc_addresses_example.install.


How to save field values using hooks
---------------------
When you use hooks to save field values, you care yourself
where its value gets stored and how it gets stored. Your
module may have created a new database table or you have
thought of another way to save the values.
1. Implement hook_uc_addresses_address_load() for loading your
   field value. This hook is invoked every time an address is
   loaded.
2. Implement hook_uc_addresses_address_insert() and
   hook_uc_addresses_address_update() for saving your field value.
   The first hook is invoked when a new address is saved, the
   second hook is invoked when an existing address is saved.
3. Implement hook_uc_addresses_address_delete() to remove your
   field value.

More information about the hooks can be found in uc_addresses.api.php.


Notes
---------------------
It's possible this example module will be extended in the future
with more examples.

More documentation of the Ubercart Addresses module can be found
online:
http://drupal.org/node/1340672

File

uc_addresses_example/README.txt
View source
  1. Ubercart Addresses example module
  2. ------------------------
  3. This example module demonstrates how you can add extra address
  4. fields through the Ubercart Addresses field handler API.
  5. It adds three example text fields:
  6. - A title field (for use, see http://en.wikipedia.org/wiki/Title)
  7. - Surname prefix (such as "van", "von" or "de"
  8. see also: http://en.wikipedia.org/wiki/Tussenvoegsel)
  9. - House number
  10. The schema's of uc_addresses and uc_orders are altered to save
  11. the extra field values.
  12. For a quick start (and if you only need extra text fields), you
  13. can alter the field definitions. In this example module, fields
  14. are defined for the Ubercart Addresses field handler API and for
  15. the schema API.
  16. The field definitions for the field handler API can be found in
  17. the function uc_addresses_example_uc_addresses_fields() from
  18. uc_addresses_example.module.
  19. The field definitions for the schema API can be found in the
  20. function _uc_addresses_example_schema_fields() from
  21. uc_addresses_example.install.
  22. If you like to learn more, follow the instructions below.
  23. Registering address fields
  24. ---------------------
  25. You can register address fields for Ubercart Addresses by
  26. implementing hook_uc_addresses_fields() as is done in
  27. uc_addresses_example.module. Each field also needs a handler.
  28. You can use existing handlers or define a new handler.
  29. Defining a new handler is done by implementing
  30. hook_uc_addresses_field_handlers().
  31. This module defines a field handler for simple text fields.
  32. You can find this handler in handlers/uc_addresses.handlers.inc.
  33. For more information about fields and field handlers, check
  34. the online documentation:
  35. http://drupal.org/node/1340694
  36. Saving field values
  37. ---------------------
  38. When you register an address field, this doesn't mean
  39. Ubercart Addresses automatically cares for saving it's value.
  40. For this you need to either:
  41. - implement a couple of hooks (see further)
  42. - altering the schema's of uc_addresses and uc_orders.
  43. This example module only demonstrates how to alter the schema's.
  44. How to alter the schema's
  45. ---------------------
  46. 1. Implement hook_schema_alter() to alter the schema definitions.
  47. 2. Implement hook_install() to add the database fields.
  48. 3. Implement hook_uninstall() to remove the database fields.
  49. This example module demonstrates a possible way to do that in
  50. the file uc_addresses_example.install.
  51. How to save field values using hooks
  52. ---------------------
  53. When you use hooks to save field values, you care yourself
  54. where its value gets stored and how it gets stored. Your
  55. module may have created a new database table or you have
  56. thought of another way to save the values.
  57. 1. Implement hook_uc_addresses_address_load() for loading your
  58. field value. This hook is invoked every time an address is
  59. loaded.
  60. 2. Implement hook_uc_addresses_address_insert() and
  61. hook_uc_addresses_address_update() for saving your field value.
  62. The first hook is invoked when a new address is saved, the
  63. second hook is invoked when an existing address is saved.
  64. 3. Implement hook_uc_addresses_address_delete() to remove your
  65. field value.
  66. More information about the hooks can be found in uc_addresses.api.php.
  67. Notes
  68. ---------------------
  69. It's possible this example module will be extended in the future
  70. with more examples.
  71. More documentation of the Ubercart Addresses module can be found
  72. online:
  73. http://drupal.org/node/1340672