Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How to programmatically retrieve configuration of the specific payment module?
I tried
$settings = rules_config_load('commerce_payment_MODULE_NAME');
It returns very basic info (name, ID etc) and empty "settings" array.
Cant also get it directly from DB .
It is stored in serialized array that can not be fully processed with the
unserialize()
function
Comment | File | Size | Author |
---|---|---|---|
#5 | commerce_payment-rules_defaults.patch | 679 bytes | vadym.kononenko |
#1 | default_settings-1246052.patch | 1.87 KB | Artusamak |
Comments
Comment #1
ArtusamakThe attached patch is adding the support for payment method settings declaration in the hook_commerce_payment_method_info().
You just need to declare the settings such as below:
If you are just using a payment method which is previously exposing the settings you can use the hook_commerce_payment_method_info_alter() if you want to override the default values.
Comment #2
HazaTested, works as expected ! Thanks for this patch !
Comment #3
rszrama CreditAttribution: rszrama commentedSo basically this patch just lets you define default settings inside your hook_commerce_payment_method_info() declaration (or via the alter hook)? And this in turn makes it so you can store default configuration for payment methods in code without depending on exported Rules? If so, I like it.
The one thing I see in this patch, though, is that your $action_settings variable seems to put a non-payment method setting for the action in the payment method settings array. I'm not sure how it's working. Is that a bug or was it buggy before?
Compare what you made it:
To the previous array:
Seems yours should just be this, no?
Comment #4
mrfelton CreditAttribution: mrfelton commented+1 to this functionality. Patch works as expected.
Comment #5
vadym.kononenko CreditAttribution: vadym.kononenko commentedBut why we need to rebuild all settings structure?
I've reached identical result just made such simple patch.
It just get payment method info from modules 'hook_commerce_payment_method_info()' and 'hook_commerce_payment_method_info_alter()' and fill in the rule action form with it.
It also give me ability to modify (add some conditions to set payment method visibility) any payment rule by using 'hook_default_rules_configuration_alter()'
All works like a charm in several projects.
Comment #6
pixelula CreditAttribution: pixelula commentedHi,
Patch #5 works for me. Thanks
Comment #7
bsandor CreditAttribution: bsandor commentedI heaven't understood the idea of patch #5.
Can you explain it please.
Am I right in followings:
If I apply this patch I can 'add' my modules configuration settings (which come in a rule) programmatically by using hook_commerce_payment_method_info_alter(); while without it I can not? Or I can but my settings need to be saved first than I can use this hook without the patch.
I need some clarification please.
Or at least can you add directions how to use patch#5 once i implemented the hook. (how to add settings in the implementation)
How can I fill the rule action form with it?
Thanks
Comment #8
bsandor CreditAttribution: bsandor commentedI've checked the code:
If I'm right this alter function runs only during rule action save.
It means you need to go to edit the rule action than save it for it to be effective. So basically you can do the same thing with hook_form_alter().
Or if you are writing your own module you can set it up in _payment_default_settings ()
I can not try if i'm right as I don't know what to do with this Patch#5. I need information.
Comment #9
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 5 year old patch in #5 to commerce_payment.rules_defaults.inc applied cleanly to the latest commerce 7.x-1.x-dev and already has several reviews, but there are also some outstanding questions so leaving the status as is.