Adding Fields to Ubercart Checkout

kristyb2008 - January 20, 2008 - 21:12

Hi Everyone,

I have a post open on ubercart.org but no one seems to be responding, and I'm in a bit of a jam as I need to get this working asap. Therefore, if anyone has any feedback as to what I'm doing wrong, please let me know.

On ubercart checkout I am trying to add a pane, I downloaded uc_lead from ubercart to customize it. I am trying to added three fields - Player Name, Position, Email, which will be used for a team roster. Then I need to be able to repeat this request to collect the complete roster. I have got as far as being able to have the fields display on checkout, but nothing is being saved to the db. Any suggestions?

Okay, I'm just going to take a shut in the dark, in hopes someone will be able to point out my errors. Here is the code that right now is adding a pane:

Tournament Roster
Fields: Player Name, Position, Email Address

However, nothing is being written to the database:
Once this gets figured out, I need to repeat the three fields several times to allow for someone to enter their entire team. Advice?

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

/**
* Implementation of hook_checkout_pane().
*/
function uc_lead_checkout_pane() {
$panes[] = array(
'id' => 'lead',
'callback' => 'uc_checkout_pane_lead',
'title' => t('Tournament Roster'),
'desc' => t('Tournament roster is required upon registering for a tournament.'),
'weight' => 8,
);

return $panes;
}

/**
* Implementation of hook_order().
*/
function uc_lead_order($op, &$arg1, $arg2) {
switch ($op) {
// Save the lead to the database.
case 'save':
if (!empty($arg1->lead['name'])) {
db_query("UPDATE {uc_leads} SET lead_name = '%s', lead_position = '%s', lead_email = 's' "
."WHERE order_id = %d", $arg1->lead['name'],
$arg1->lead['position'], $arg1->lead['email'], $arg1->order_id);
if (db_affected_rows() == 0) {
db_query("INSERT INTO {uc_leads} (lead_id, order_id, lead_name, lead_position, lead_email) VALUES (%d, %d, '%s', '%s', '%s')",
db_next_id('{uc_leads}_lead_id'), $arg1->order_id,
$arg1->lead['name'], $arg1->lead['position'], $arg1->lead['email']);
}
}
break;

// Load the lead from the database.
case 'load':
$result = db_query("SELECT * FROM {uc_leads} WHERE order_id = %d", $arg1->order_id);
if ($data = db_fetch_object($result)) {
$arg1->lead['name'] = $data->lead_name;
$arg1->lead['position'] = $data->lead_position;
$arg1->lead['email'] = $data->lead_email;
}
break;

// Delete the lead from the database.
case 'delete':
db_query("DELETE FROM {uc_leads} WHERE order_id = %d", $arg1->order_id);
break;
}
}

/**
* Implementation of hook_order_pane().
*/
function uc_lead_order_pane() {
$panes[] = array(
'id' => 'lead',
'callback' => 'uc_order_pane_lead',
'title' => t('Tourname Roster'),
'desc' => t(''),
'class' => 'abs-left',
'weight' => 7,
'show' => array('view'),
);

return $panes;
}

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

function uc_checkout_pane_lead($op, &$arg1, $arg2) {
switch ($op) {
case 'view':
$description = t('Tournament roster is required upon registering for Pro Hockey Tournaments');

$contents['lead_name'] = array(
'#type' => 'textfield',
'#title' => t('Player Name'),
'#default_value' => $arg1->lead['name'],
);

$contents['lead_position'] = array(
'#type' => 'textfield',
'#title' => t('Position'),
'#default_value' => $arg1->lead['position'],
);

$contents['lead_email'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#default_value' => $arg1->lead['email'],
);

return array('description' => $description, 'contents' => $contents);

case 'review':
{
$review[1] = array('title' => t('Roster'), $arg1->lead['name']);
$review[2] = array('title' => t('Position'), $arg1->lead['position']);
$review[3] = array('title' => t('Email'), $arg1->lead['email']);
}
return $review;

}
}

function uc_order_pane_lead($op, $arg1) {
switch ($op) {
case 'view':
if (empty($arg1->lead['name'])) {
$lead = t('None specified');
}
else {
$lead = $arg1->lead['name'];
}
return t('Roster: !lead', array('!lead' => $lead));
}
}

Hey, K!

PepeMty - January 20, 2008 - 22:11

The Überdudes run a very good and amiable support --Monday to Friday.

I'm pretty sure they will help you out on this, just bump your question tomorrow. ;-)

Warm regards from sunny México!
Pepe
:-)

hehe Thanks, Pepe.

rszrama - January 21, 2008 - 01:07

hehe Thanks, Pepe. Occasionally I browse d.o on the weekends and am rewarded with a chance to help here, too. ^_^ I think the answer to the main question posed is a little less than direct. Honestly, I don't think that during checkout completion is the best time to have the customer submit the roster. I've hypothesized various ways of purchasing nodes on the forums at Ubercart.org in the past, and I'd go that direction instead... have the customer create a roster node, fill in all the info there, and then use a small bit of PHP to get the "registration" product added to the cart with an attribute reference to the node ID of the roster.

You might check out this thread for some ideas.

----------------------
Drupal by Wombats | Current Drupal project: http://www.ubercart.org

Thanks

kristyb2008 - January 21, 2008 - 02:04

Thanks Pepe -- just wish the problem would have happened during the week, cause I need to find a solution to be able to release my site.

RsZrama - I sent you an email, I like what you suggested, however I'm not really too sure how I can accomplish it. As I'm no where near programmer level. Anyways, I sent you the site to check out and hopefully you can provide me some feedback. Thanks.

No sweat.

PepeMty - January 21, 2008 - 16:37

I'm just a grateful Übercart user (still messing with it, though).

Warm regards from sunny México!
Pepe
:-)

 
 

Drupal is a registered trademark of Dries Buytaert.