I am using rules so that when a content type group is created, I add a option to an ubercart attribute and enable that option on a product node, then, I set the adjustments for all the combinations that use that option to have a different sku. My next thing I want to automate is creating a feature that corresponds to the group created, and the sku. How should I do this?
How do I create a subscription feature in php code? By creating form_state and calling uc_og_subscribe_feature_form_submit?
What I have in my php code is the node structure (and thus the nid) for the og group, and the sku.
Assume I wanted to create a subscription feature for node 19 and sku "1001-oprf23".
... or should I ...
module_load_include('inc', 'uc_og_subscribe', 'uc_og_subscribe.ca.inc');
$form_state = array();
$form_state['values']['nid'] = 19;
$form_state['values']['uc_group_model'] = "1001-oprf23";
drupal_execute('uc-og-subscribe-feature-form', );
but I think what I really need is 'uc_group_gid'. is that the same as the nid? I think so looking at line 141 of uc_og_subscribe.module
well, I'll try
module_load_include('inc', 'uc_og_subscribe', 'uc_og_subscribe.ca.inc');
$form_state = array();
$form_state['values']['uc_group_gid'] = 19;
$form_state['values']['uc_group_model'] = "1001-oprf23";
drupal_execute('uc-og-subscribe-feature-form', );
Thanks for any help with this.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | drupal_execute_uc_og_sub.patch | 1.02 KB | yesct |
| #9 | drupal_execute_uc_og_sub-minus_hidden_default_value.patch | 774 bytes | yesct |
Comments
Comment #1
yesct commentedopps forgot the form_state in the drupal execute:
Comment #2
yesct commentedhad to change the -'s to _'s and send some extra arguments...
with
now I get "An illegal choice has been detected. Please contact the site administrator."
I thought maybe I could send NULL for the feature/pfid since this would always be making a new feature, not editing one already existing...?
Comment #3
yesct commentedI tracked down the error message as coming from (drupal/)includes/form.inc about line 2560
and saw there it was writing to the watchdog, so I checked the Recent Log Entries report and saw there:
Illegal choice 1001-par1248 in SKU element.
so I checked the source code on my form:
node/19/edit/features/group_subscribe/add
and see:
so.. it looks like I'm getting it right: value="1001-par1248"
Maybe I need to "fill out" the rest of the form? not just the two pull downs?
Comment #4
yesct commentedmore info that might mean something:
YesCT: I added some words to figure out which "illegal choice" was getting triggered in form.inc and it was the one around line 711
[2:39pm] YesCT: the last else if part of _form_validate http://api.drupal.org/api/function/_form_validate/6
[2:40pm] YesCT: sooo, I commented out that else if, to see what would happen,
[2:41pm] YesCT: and it made the feature, put the right info in the uc_og_subscribe table
[2:42pm] YesCT: but put the wrong info in the uc_product_features table. the pfid , fid and description were ok. but the nid was set to 0.
[2:43pm] YesCT: I went in and edited the row in the database to have the right nid in uc_product_features and then it looks like it worked...
[2:43pm] YesCT: so I'm hoping that not setting (or putting the wrong nid in uc_product_features) will help me figure out what I need to do to get it to actually work (without editing core!)
Comment #5
yesct commentedI added a dsm to the uc_og_subscribe_feature_form_submit function
and when I execute the php code,
I get
when I use the gui to submit the form I get:
so I can see the nid is not getting set ... or maybe it is getting set, and then unset?
Comment #6
yesct commentedI tried changing the nid form element to be hidden and a default value instead of value:
which got me this reported by dsm
And I like that the nid is now being set... but the uc_product_features row still has the nid as 0! (this is with the else if commented out still to get it to actually go through)
Still dont know what I'm doing wrong, but thought it might be worth condidering changing the value statements to default_value statements
Comment #7
yesct commentedI added a dsm to the _form_validate in includes/form.inc and there were 17 calls to dsm... from the form inc.
new idea... looking at a dsm from inside the else if
looks like maybe the list of options is not being build correctly. I think it should be all the options that could be valid?
Comment #8
yesct commentedline 52 of uc_og_subscribe.module
$models = uc_product_get_models($node);?>
... around line 84
I'm thinking when I call the drupal execute, the $node is not loaded, and so the $modules is not getting filled out...
ah, when I call it:
drupal_execute('uc_og_subscribe_feature_form', $form_state, $productnid, $myemptyfeature);
maybe the 3rd arg is not a nid, but the node structure! and it's not my "node" which is the group I'm creating, it's the product node structure
yep. OK, so I dont have the form.inc error anymore!
which now gives me this code i'm trying in my rule to automate all the stuff I need to do on creation of a new group. the bit to add the person paying for the product to the og is the last few lines.
but the product nid is still missing from the uc_product_features table...
in uc_product.module line 1939:
it is using data['nid']
and in uc_og_subscribe.module line 151 it sets the nid part of data as:
for more context:
so... I think it should be:
it still did not work, (nid 0 in the features table)
so I looked and in uc_og_subscribe.module on line 131 there was no nid entry, so I added one:
in uc_product.module on line 1925 it tries to get the nid if it is empty... and maybe that was working for the gui form? but now it works! (both the gui form, and my php code drupal_execute)
Comment #9
yesct commentedhere are two patches, one with the change of making the nid a hidden default_value (which I'm thinking now did not really effect things) and one without the hidden default_value change.
Comment #10
yesct commentedjust adding a note that this is related to a general quest to automate some stuff dealing with groups (and ubercart)
http://www.ubercart.org/forum/support/15829/practical_advice_setting_lar...