How to integrate an exported Rules component in a custom module? i have created list of component fields in a Drupal 7 module, copied the exported Rules code and then pasted it into our custom module

But it is not working. Any ideas how to get it to work?

This is my exported Rule:

$rule = '{ "rules_faircent_rules" : {
"LABEL" : "Faircent Rules",
"PLUGIN" : "rule set",
"OWNER" : "rules",
"TAGS" : [ "Faircent Rules" ],
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : {
  "fc_home_city" : { "label" : "Home city ", "type" : "integer" },
  "fc_pin" : { "label" : "Pin Code", "type" : "integer" },
  "fc_loan" : { "label" : "Loan Type", "type" : "integer" }
},
"RULES" : [
  { "RULE" : {
      "PROVIDE" : { "result" : { "result1" : "Calculation result", "result" : "Calculation result" } },
      "IF" : [
        { "data_is" : { "data" : [ "fc-home-city" ], "value" : "10" } },
        { "data_is" : { "data" : [ "fc-pin" ], "value" : "5" } },
        { "data_is" : { "data" : [ "fc-loan" ], "value" : "12" } }
      ],
      "DO" : [
        { "data_set" : { "data" : [ "fc-loan" ], "value" : "35" } },
        { "data_set" : { "data" : [ "fc-home-city" ], "value" : "15" } },
        { "data_set" : { "data" : [ "fc-pin" ], "value" : "25" } },
        { "data_calc" : {
            "USING" : { "input_1" : [ "fc-home-city" ], "op" : "+", "input_2" : [ "fc-pin" ] },
            "PROVIDE" : { "result" : { "result1" : "Calculation result" } }
          }
        },
        { "data_calc" : {
            "USING" : { "input_1" : [ "result1" ], "op" : "+", "input_2" : [ "fc-loan" ] },
            "PROVIDE" : { "result" : { "result" : "Calculation result" } }
          }
        }
      ],
      "LABEL" : "Calculate over all "
    }
  }
]


}
}';

$configs['commerce_checkout_order_email'] = rules_import($rule);
echo '&lt;pre&gt;';
print_r($configs['commerce_checkout_order_email'] );


Above code is not working for me. What will be exact solution?
Here is what's needed to integrate your exported Rules component in a custom module:

&lt;?php
function MY_MODULE_NAME_default_rules_configuration() {
  $configs = array();
  $rule = '{ "my_exported_rule" : {
    "LABEL" : "My Exported Rule",
    ...,
  }
}';
  $configs['my_exported_rule'] = rules_import($rule);
  return $configs;
}
?&gt;


So to use such exported Rule, you need to run it through the function rules_import(). This will change the exported Rule in a format that is  usable for the Rules module.

To reuse this example:


Replace MY_MODULE_NAME with the machine name of your module.
Replace the value used for $rule by the content of your exported rule.
Make sure to use the machine name of your rule (= my_exported_rule in my sample) as the key in $configs.


In the sample contained in the question, the machine name of the rule is rules_faircent_rules, though that is NOT what is used in the $configs ... Therefor I think you should correct your code like so:

$configs['rules_faircent_rules'] = rules_import($rule);
echo '&lt;pre&gt;';
print_r($configs['rules_faircent_rules'] );


Refer to the articled "Drupal 7 - Defining rules within a module using PHP" for some more details.