possible bug in uc_checkout_pane

Posts: 96
Joined: 10/29/2007
Bug Finder

I had a unique need that I solved with the terms and conditions module. I wanted to only show the t&c when they bought a certain product (this one requires a 5 month commitment). I wrote a simple function to see if the product was in the cart and I passed that into the 'enabled' flag in uc_checkout_pane. This pane shows up whether enabled is true or false. I did a work around by wrappig the entire call in my function, but thought you might want to know that you cannot disable a pane with the 'enabled' flag

function uc_gtct_checkout_pane() {

if (check_leapforward()) {
$panes[] = array(
'id' => 'gtct',
'callback' => 'uc_checkout_pane_gtct',
'title' => t('Terms and Conditions'),
'desc' => t("Please confirm if you agree with our terms and conditions that aply on all our deliveries."),
'weight' => 1,
'process' => TRUE,
'collapsible' => FALSE,
);
return $panes;
}
}

function check_leapforward()
{
$items = uc_cart_get_contents();
foreach($items as $cartitem) {
if ($cartitem->model =='VIT029') {
return true;
}
}
return false;
}

Posts: 5367
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

I think the issue is that the enabled flag in the hook is really only supposed to be for its initial setting. After the checkout pane settings have been saved to the DB through the settings form, that value overrides whatever the hook returns.

What should happen is something exactly like you've done. I think normally I'd put it in the actual pane display form and just not return any contents if the item wasn't found.