When a payment module is disabled, it should disable the payment rules related to it so user doesn't have to manually do so.

Comments

recidive’s picture

Assigned: Unassigned » recidive
Status: Active » Needs review

I added a hook_modules_disabled() implementation to disable the rules.

This was a bit tricky, since commerce_payment_methods() wasn't returning the methods declared by the module being disabled.

https://github.com/recidive/drupalcommerce/tree/1061318

rszrama’s picture

Two follow-up questions:

  1. Should we also then have a hook_modules_enabled() implementation that re-enables them if the module is re-enabled?
  2. Is there any way to hide the disabled Rule from the UI? I feel like there is but can't remember the property. Reason being is if the payment method is disabled and someone goes in to view that disabled rule, it should throw warnings about the action not being found.
recidive’s picture

I've added some code to delete the rule if it's wasn't overriden, so it doesn't display as disabled in the payments admin screen and get enabled automatically when the payment module is re-enabled.

It looks like we can't hide disabled rules, so what we can do is delete the rules even if they were overridden. The caveat here is that user will loose their settings by just disabling and re-enabling the module, if they have overrode the rule.

rszrama’s picture

Status: Needs review » Needs work

I'm going to move this back to needs work for the time being, as it's not clear to me if it's up to date with current code / if recidive's GitHub repo is based on the d.o repo. To summarize the discussion above, I don't think we should destructively delete payment method rules on disable, only uninstall. This is the expected behavior, I believe - if you were to disable for an update or something, you would lose valuable configuration even though you didn't explicitly uninstall.

It looks like the second commit on that branch added something for this, but we will need some way to hide these Rules in the UI. If someone were to edit a Rule enabling a disabled payment method, I'm guessing Rules would choke because of missing data.

Part of me thinks we just shouldn't do anything... but if I had to pick one thing for us to implement, it would be to only delete the default payment rule when a payment method module is uninstalled. It's worth mentioning, too, that there may be other instances of an action enabling a disable payment method than just in the default rule we create.

svendecabooter’s picture

subscribing since this is being requested for the payment method i wrote: #1179826: delete the rule

corentin.crouvisier’s picture

Issue summary: View changes

Important process to set up, especially for the manual management of transactions and orders (create/edit/delete in admin).
Not the good place for this.