I ran into a use case where i needed to rebuild a uc_node_checkout governed node with AHAH. In the process when uc_node_checkout_form_alter is called it returns an HTTP ERROR 0. The culprit seems to be below line 290 when it checks for the product node association. First it checks for the nid in the array returned by uc_node_checkout_product_map() then it checks for it in the $_GET variable, and then it defaults to sending the user to a form to select one. This redirection is what seems to be returning the HTTP ERROR 0. I added a quick check for $_POST['ucnc_product_nid'] and it appears to be working, though I'm not sure if this will cause other issues someplace else. Here is the code:
// Alter the node forms for UC Node Checkout governed node types.
foreach (uc_node_checkout_product_map() as $type => $value) {
if ($form_id == $type .'_node_form') {
// Determine the product nid that will be added to the cart when this
// node is created. First look for a single product node association.
if ($value['nid'] && !$value['view']) {
$product_nid = $value['nid'];
}
elseif ($_GET['product_nid']) {
// Otherwise look in the $_GET array.
$product_nid = $_GET['product_nid'];
}
// ADDED by richygecko
elseif ($_POST['ucnc_product_nid']) {
// Try the $_POST array
$product_nid = $_POST['ucnc_product_nid'];
}
// END ADDED
elseif (empty($form['nid']['#value']) && !$form['#programmed']) {
// If none was found, we must ask the user to specify one.
drupal_goto('ucnc-select/'. $type);
}
If this is correct, please let me know and I can supply a patch file.
Comments
Comment #1
aidanlis commentedThis seems reasonable ...
Comment #2
aidanlis commentedComment #3
aidanlis commentedI've committed this, but I'm curious as to what module you were using to rebuild the node dynamically and why it was using ucnc_product_nid instead of product_nid.
Thanks,
Comment #4
richygecko commentedThanks aidanlis, It's a custom module. My customer has a product with a "Print Setup" attribute on it and options for "First time print" and "Re-print". The Re-print option only appears if they have a previous order with this particular product in it. To do this i check if there is a node for this uc_checkout node type and use hook_form_alter to remove the option if there is not.
The customer wanted to have the data from the previous ordered product checkout node pre-filled in the checkout form, and clear the form/re-fill it if the attribute is changed. To do this in the hook_form_alter i attached [#ahah] to the attribute and in the call back is where i call drupal_rebuild_form and the error occurs. I used ucnc_product_nid because I am updating with ahah the request is sent via POST and product_nid doesn't appear in $_POST. Here is the $_POST array from dvm():