0

The problem is similar like here: How to force rules configuration to load

I planned to use hook_default_rules_configuration_alter(), but after this:

  if (isset($configs['commerce_payment_paypal_ec'])) {
    foreach ($configs['commerce_payment_paypal_ec']->actions() as $action) {
      dsm($action);
    }
  }

I don't see any $settings['settings'] array:

Krumo

How can I change the saved commerce_payment_paypal_ec rule's settings by code?

1

This is a question that has came in different shapes, I'd recommend reading https://drupal.stackexchange.com/a/118316/2322 answer to get a better understanding on how drupal commerce and rules store this information. I don't know how to access the UI form the action itself.

Instead of trying to modify specific values, what I'd do is to try to replace the whole rule object with the one you want using entity_import of the rules_config object, something like:

if (isset($configs['commerce_payment_paypal_ec'])) {
    $configs['commerce_payment_paypal_ec'] = entity_import('rules_config', '{ "commerce_payment_paypal_ec" : {
        "LABEL" : "PayPal Express Checkout",
        "PLUGIN" : "reaction rule",
        "OWNER" : "rules",
        "TAGS" : [ "Commerce Payment" ],
        "REQUIRES" : [ "commerce_payment" ],
        "ON" : { "commerce_payment_methods" : [] },
        "DO" : [
          { "commerce_payment_enable_paypal_ec" : {
              "commerce_order" : [ "commerce-order" ],
              "payment_method" : { "value" : {
                  "method_id" : "paypal_ec",
                  "settings" : {
                    "api_username" : "1",
                    "api_password" : "",
                    "api_signature" : "",
                    "server" : "sandbox",
                    "currency_code" : "EUR",
                    "allow_supported_currencies" : 0,
                    "txn_type" : "auth_capture",
                    "ec_mode" : "Mark",
                    "shipping_prompt" : "0",
                    "log" : { "request" : 0, "response" : 0 },
                    "ipn_logging" : "notification",
                    "receiver_emails" : "",
                    "reference_transactions" : 0,
                    "ba_desc" : "",
                    "show_payment_instructions" : 0,
                    "update_billing_profiles" : 1,
                    "enable_bml" : 0
                  }
                }
              }
            }
          }
        ]
      }
    }');
  }
| improve this answer | |
  • Sounds good, like I said here: drupal.stackexchange.com/questions/121461/… But where? I don't think the hook_default_rules_configuration_alter() is the right place to do it. :) – Gabor Szanto Jul 5 '14 at 13:56
  • hook_default_rules_configuration_alter would be the first place where I'd put this, probably unsetting the old one before adding the new one if directly doesn't work. – pcambra Jul 6 '14 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.