commit 9b4d726792b3e2fce173e044954c0ce69d09cf9d
Author: Randy Fay <randy@randyfay.com>
Date:   Thu Sep 8 17:23:50 2011 -0400

    Issue #1107788 by rfay: Refactor field creation so it can be used outside hook_enable

diff --git a/modules/customer/commerce_customer.module b/modules/customer/commerce_customer.module
index b52c256..9a07834 100644
--- a/modules/customer/commerce_customer.module
+++ b/modules/customer/commerce_customer.module
@@ -115,16 +115,37 @@ function commerce_customer_hook_info() {
  * Implements hook_enable().
  */
 function commerce_customer_enable() {
+  commerce_customer_configure_customer_types();
+}
+
+/**
+ * Configure types provided by this module.
+ */
+function commerce_customer_configure_customer_types() {
   // Add the address field to customer profile bundles.
   foreach (commerce_customer_profile_types() as $type => $profile_type) {
     commerce_customer_configure_customer_profile_type($profile_type);
   }
 }
 
+
 /**
  * Implements hook_modules_enabled().
  */
 function commerce_customer_modules_enabled($modules) {
+  commerce_customer_configure_customer_fields($modules);
+}
+
+/**
+ * Configure fields for the customer profile.
+ *
+ * @param $modules
+ *   Array of module names to be acted on.
+ */
+function commerce_customer_configure_customer_fields($modules = NULL) {
+  if (empty($modules)) {
+    $modules = module_implements('commerce_customer_profile_type_info');
+  }
   // Loop through all the enabled modules.
   foreach ($modules as $module) {
     // If the module implements hook_commerce_customer_profile_type_info()...
diff --git a/modules/line_item/commerce_line_item.module b/modules/line_item/commerce_line_item.module
index 9e8ea4b..cc7003d 100644
--- a/modules/line_item/commerce_line_item.module
+++ b/modules/line_item/commerce_line_item.module
@@ -231,16 +231,36 @@ function commerce_line_item_views_api() {
  * Implements hook_enable().
  */
 function commerce_line_item_enable() {
+  commerce_line_item_configure_line_item_types();
+}
+
+/**
+ * Implements hook_modules_enabled().
+ */
+function commerce_line_item_modules_enabled($modules) {
+  commerce_line_item_configure_line_item_fields($modules);
+}
+
+/**
+ * Configure each of the line item types.
+ */
+function commerce_line_item_configure_line_item_types() {
   // Loop through and configure all the currently defined line item types.
   foreach (commerce_line_item_types() as $line_item_type) {
     commerce_line_item_configure_line_item_type($line_item_type);
   }
 }
-
 /**
- * Implements hook_modules_enabled().
+ * Configure line item fields that other modules may provide.
+ *
+ * @param $modules
+ *   Array of module names. If empty, will process all modules that implement
+ *   hook_commerce_line_type_info().
  */
-function commerce_line_item_modules_enabled($modules) {
+function commerce_line_item_configure_line_item_fields($modules = NULL) {
+  if (empty($modules)) {
+    $modules = module_implements('commerce_line_item_type_info');
+  }
   // Reset the line item cache to get the default options and callbacks.
   commerce_line_item_types_reset();
 
diff --git a/modules/order/commerce_order.module b/modules/order/commerce_order.module
index 16e3526..d8f24cf 100644
--- a/modules/order/commerce_order.module
+++ b/modules/order/commerce_order.module
@@ -136,6 +136,13 @@ function commerce_order_enable() {
  * Implements hook_modules_enabled().
  */
 function commerce_order_modules_enabled($modules) {
+  commerce_order_configure_order_fields($modules);
+}
+
+function commerce_order_configure_order_fields($modules = NULL) {
+  if (empty($modules)) {
+    $modules = module_implements('commerce_customer_profile_type_info');
+  }
   // Loop through all the enabled modules.
   foreach ($modules as $module) {
     // If the module implements hook_commerce_customer_profile_type_info()...
diff --git a/modules/product/commerce_product.module b/modules/product/commerce_product.module
index 6109cfd..127908a 100644
--- a/modules/product/commerce_product.module
+++ b/modules/product/commerce_product.module
@@ -262,6 +262,13 @@ function commerce_product_permission() {
  * Implements hook_enable().
  */
 function commerce_product_enable() {
+  commerce_product_configure_product_types();
+}
+
+/**
+ * Configure the types provided by this module.
+ */
+function commerce_product_configure_product_types() {
   // Loop through and configure all the currently defined product types.
   foreach (commerce_product_types() as $type => $product_type) {
     commerce_product_configure_product_type($type);
@@ -272,6 +279,17 @@ function commerce_product_enable() {
  * Implements hook_modules_enabled().
  */
 function commerce_product_modules_enabled($modules) {
+  commerce_product_configure_product_fields($modules);
+}
+
+/**
+ * Configure the fields on this provided by other modules.
+ */
+function commerce_product_configure_product_fields($modules = NULL) {
+  if (empty($modules)) {
+    $modules = module_implements('commerce_product_type_info');
+  }
+
   // Loop through all the enabled modules.
   foreach ($modules as $module) {
     // If the module implements hook_commerce_product_type_info()...
