Custom Panes

Posts: 17
Joined: 01/13/2008

Hi,

I created two custom panes to display on the checkout page to collect additional information. I was wondering if I could get some assistance for creating a conditional statement that if "model" equals "Camp" display pane 1 else display pane 2? I am using the auto-sku to generate the product sku. So Camp will automatically be included in the sku (model) field for certain products created. Thanks.

Posts: 1139
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

I'm not an expert on panes but something like this should work.. (modify as needed for your module).

<?php
/**
* Implementation of hook_checkout_pane
*/
function uc_camp_checkout_pane() {
  global
$user;
 
$items = uc_cart_get_contents();
 
$containsCamp = FALSE;
  foreach (
$items AS $item) {
   
// Look for the word "camp" in the SKU, set var to TRUE if exists
   
if (eregi('camp', $item->model)) {
     
$containsCamp = TRUE;
    }
  }
 
  if (
$containsCamp == TRUE) {
   
$panes[] = array(
     
'id' => 'camp_pane',
     
'title' => t('Camp Pane'),
     
'desc' => t('Special camp pane description..'),
     
'callback' => 'camp_pane_callback',
     
'weight' => 7,
    );
  } else {
   
$panes[] = array(
     
// Put the alternate pane content here, different callback most likely...
 
}
  return
$panes;
}


// Callback for first Camp checkout pane
function camp_pane_callback($op, &$arg1, $arg2) {

switch (
$op) {
  case
'view':
 
$description = t('Some special Camp function Pane');

 
$contents['camp_pane'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Camp Pane amount'),
   
'#description' => t(''),
   
'#default_value' => $arg1->campdiscount['amt'],
   );
       
  return array(
'description' => $description, 'contents' => $contents);
       
  case
'process':
   
$arg1->campdiscount['amt'] = $arg2['campamt'];
    return
TRUE;
}
?>

Depending on what you'll need to do you may end up hooking into the order process some more, such as for a discount, adding something to a user object (such as a Role) etc. Hope this helps.

NOTE this code is untested but should give you a place to start. Smiling

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 17
Joined: 01/13/2008

Thanks so much. I actually only used the top amount because I'm using it to collect additional information on the registrants. One thing I noticed was I had to change the following:

'callback' => 'camp_pane_callback',

to:

'callback' => 'uc_checkout_pane_player',

Anyways it works perfectly. Thanks for your help.

If anyone else is interested here is the complete code based on TorgosPizza:

<?php
// $Id$

/**
* Implementation of hook_checkout_pane
*/
function uc_camp_checkout_pane() {
  global
$user;
 
$items = uc_cart_get_contents();
 
$containsCamp = FALSE;
  foreach (
$items AS $item) {
   
// Look for the word "camp" in the SKU, set var to TRUE if exists
   
if (eregi('camp', $item->model)) {
     
$containsCamp = TRUE;
    }
  }

  if (
$containsCamp == TRUE) {
   
$panes[] = array(
     
'id' => 'player',
     
'title' => t('Player Information'),
     
'desc' => t('Please complete the following information for player registering.'),
     
'callback' => 'uc_checkout_pane_player',
     
'weight' => 7,
    );
 
  return
$panes;
}
}

?>

Posts: 1139
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

Cool! Glad I could help. I should've mentioned that the callback I was using was just a string I threw in there... it would of course be specific to whatever it was your pane was trying to accomplish. Smiling

Cheers!

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com