I've finally figured out how to generate a UC order from a webform submission, but I found that the uc_cart_add_item lacks support for transmitting product information when you want to create an order.

I had to do some out of the box thinking in order to get a minimal amount of information into my product $item:

/*******************************************************************************
* Hook Functions
*******************************************************************************/

function uc_adt_xpress_loader_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'webform_client_form_42') {
    $form['#submit'][] = uc_adt_xpress_loader_submit_callback;
  }
}

/*******************************************************************************
* Hook Functions (Ubercart)
*******************************************************************************/

/**
 * Implementation of hook_cart_item().
 */
function uc_adt_xpress_loader_cart_item($op, &$item) {
  switch ($op) {
    case 'load':
      // dsm(get_defined_vars());
      if ($item->nid == 45) {
      $item->price = $item->qty;      
      $item->qty = 1;
      }
      // dsm(get_defined_vars());
      break;
  }
}



/*******************************************************************************
 * Callback Functions, Forms, and Tables
 ******************************************************************************/

 function uc_adt_xpress_loader_submit_callback($form, &$form_state) {
  // create order with Xpress Theme product (node id 45).
  // because this function does not have a parameter for transporting data about the product, we will use the quantity field to supply the price that is calculated in the webform, and we will set the quantity back to 1 with hook_cart_item (where we also set the price).
  uc_cart_add_item(45, $form_state['values']['submitted_tree']['price'], $data = NULL, $cid = NULL, $msg = TRUE, $check_redirect = TRUE);
 }

Being able to transmit data into the uc_cart_add_item would probably also be cool for other users of attributes because it would allow customers to select attributes whille browsing products. the way uc works now, you can only add attributes at the checkout page right?

Comments

rszrama’s picture

So... I'm not really sure what you're trying to do here, but you do realize that the $data argument is for any data about the product, right?

Island Usurper’s picture

Status: Active » Postponed (maintainer needs more info)
tr’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Closing because of lack of follow-up from the OP. It doesn't seem a new feature or a fix is needed to accomplish what the OP was trying to do.