I have a rule, on "saving new content", if that content is a content type group, then ... well, then create a ubercart attribute option value and also enable that value. I have a first pass at coding that, and I want to add into it, saving the option id (and probably eventually the product node id and the attribute id) that is to be paired with that "group". How do I save a cck field value for that node that is being saved? Probably this has something to do with node_save, but I'm not sure if the node has already been saved, or is about to be saved ... ? I want to set the cck field storeoptionid to be the oid.
Here is an export of the rule:
array (
'rules' =>
array (
'rules_6' =>
array (
'#type' => 'rule',
'#set' => 'event_node_insert',
'#label' => 'create a ubercart option value for a group on group node creation (adding a group)',
'#active' => 1,
'#weight' => '0',
'#categories' =>
array (
),
'#status' => 'custom',
'#conditions' =>
array (
0 =>
array (
'#type' => 'condition',
'#settings' =>
array (
'type' =>
array (
'group' => 'group',
),
'#argument map' =>
array (
'node' => 'node',
),
),
'#name' => 'rules_condition_content_is_type',
'#info' =>
array (
'label' => 'Created content is Group',
'arguments' =>
array (
'node' =>
array (
'type' => 'node',
'label' => 'Content',
),
),
'module' => 'Node',
),
'#weight' => 0,
),
),
'#actions' =>
array (
0 =>
array (
'#weight' => -4,
'#info' =>
array (
'label' => 'Execute custom PHP code to add the option',
'label callback' => false,
'module' => 'PHP',
'eval input' =>
array (
0 => 'code',
),
),
'#name' => 'rules_action_custom_php',
'#settings' =>
array (
'code' => ' module_load_include(\'inc\', \'uc_attribute\', \'uc_attribute.admin\');
$form_state = array();
$myaid->aid=2;
$form_state[\'values\'][\'name\'] = check_plain($node->field_groupname[0][\'value\']);
drupal_execute(\'uc_attribute_option_form\', $form_state, $myaid);',
'vars' =>
array (
0 => 'node',
),
),
'#type' => 'action',
),
1 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Show a configurable message on the site and enable the option on the membership product',
'label callback' => false,
'module' => 'System',
'eval input' =>
array (
0 => 'message',
),
),
'#name' => 'rules_action_drupal_message',
'#settings' =>
array (
'message' => 'Added the group name <? echo $node->field_groupname[0][\'value\'] for nid <? echo $node->nid ?> to the list of groups in the join product drop down (attribute 2) option list. <?
$myaid->aid=2;
$myproductid=19;
$myoptionname = $node->field_groupname[0][\'value\'];
$result = db_query("SELECT myoptions.oid FROM {uc_attribute_options} myoptions WHERE myoptions.name = \'%s\' AND myoptions.aid = %d", $myoptionname, $myaid->aid);
if ($row = db_fetch_object($result))
{
echo "Option id matching that name is: ";
echo $row->oid;
echo ". ";
$productresult = db_query("SELECT myprodoptions.oid FROM {uc_product_options} myprodoptions WHERE myprodoptions.nid = %d AND myprodoptions.oid = %d", $myproductid, $row->oid);
if (db_fetch_object($productresult)) {
echo "The option was already enabled. Contact developer. ";
} else {
db_query("INSERT INTO {uc_product_options} (nid, oid) VALUES (%d, %d)", $myproductid, $row->oid);
echo "Enabled option $row->oid on product (node) $myproductid";
echo ". ";
}
if ($row = db_fetch_object($result))
{
echo "Oops and there were other options matching that name: ";
echo $row->oid;
while ($row = db_fetch_object($result))
{
echo " ";
echo $row->oid;
}
echo ". ";
echo "Having more than one option with the same name is going to cause problems. Contact a developer and delete the group you just made. Create a new group with a slightly different name.";
}
$node->field_storeoptionid[0][\'value\']=$row->oid;
}
else {
echo "no options found with that name. something is really wrong. contact developer.";
}
?>
',
'error' => 0,
'#eval input' =>
array (
'rules_input_evaluator_php' =>
array (
'message' =>
array (
0 => 'node',
),
),
),
),
'#type' => 'action',
),
),
'#version' => 6003,
),
),
)
?>
Comments
Comment #1
yesct commentedopps. the formatting didn't quite work on that... I'll try again.
Comment #2
mitchell commentedClosing older issues to make the issue queue easier to navigate. If you still need assistance, please try the latest versions, read through the documentation handbooks, and search for other other issues with relevant responses. This will more than likely give you an answer to your question, or you can always open another issue. Thanks.