|Issue tags:||1.2 blocker|
A bit after Commerce got its uninstall code (with the "reactivate field" approach), Drupal core got its own fix, which consists of disallowing the disabling of modules that provide field types, if fields / instances of those types exist. Those dependencies are calculated on the fly, and if you have a "product_reference" field on module X, it won't allow you to disable the product_reference module until module X gets disabled and the offending field removed.
The problem begins when you know that X = Line item, because the Product Reference module already depends on Line items, and then Drupal creates a circular dependency, making it impossible for Commerce to be disabled / uninstalled through the UI.
People on the queues figured out a way around that: use "drush pm-disable commerce", which disables all modules without making a fuss.
However, you still can't uninstall correctly, since various Commerce submodules call functions from commerce.module (commerce_delete_instances / commerce_delete_fields) without including the commerce.module file, assuming it is already loaded. However, if you've just disabled everything through Drush, that is not true.
The current patch is in #6. It does four things:
1) Documents the situation described in the summary.
2) Updates the commerce.module weight to be bigger than the weight of field.module, then using a hook_system_info_alter() to unrequire the field type providing modules that Commerce ships with (customer, line_item, price, product_reference). This reverses the damage done by core, allowing all modules to be disabled through the UI.
3) Adds the module_load_include() lines needed to always load commerce.module, making uninstall possible when all modules are disabled.
4) Adds code to commerce_delete_instances() that removes field display settings for the entity type / bundle being uninstalled, so that cruft doesn't remain.
This code was copied from field_attach_delete_bundle(), the function that Core recommends for deleting fields and field instances on module uninstall, unusable for Commerce because it doesn't contain the "reactivate" hack invented for Commerce.
Problems with the current patch
Deleted data doesn't get purged by cron after uninstall, you get stuck with rows that have deleted = 1 in field_config and field_config_instance, as well as field_deleted_* tables. This is because when cron runs, the fields are inactive again, entity types are gone, and the purge can't happen.
It's just dead data though, Commerce can be installed again without a problem.
There could be several fixes to this:
1) Provide a script that deletes the rows with deleted = 1 and drops the field_deleted_* tables.
2) Do it on commerce_uninstall(). Panic if the tables are big.
3) Bring back the "required" state for customer_reference and line_item_reference fields, so that at least that data gets purged.
I tried adding the manual call to field_purge that #1 had, but it doesn't really work when "required" is removed from all modules.