2 replies [Last post]
fmueller's picture
Offline
Joined: 04/02/2009
Juice: 33
Was this information Helpful?

Hi,

I have a module called price_test with this implementation of hook_uc_price_handler()

<?php
function price_test_uc_price_handler() {
 
$items['alter'] = array(
   
'title' => t('Default 2 price handler'),
   
'description' => t('The default handler ...'),
   
'callback' => 'price_test_price_handler_alter',
  );
 
$items['format'] = array(
   
'title' => t('Default 2 price handler'),
   
'description' => t('The default handler ...'),
   
'callback' => 'price_test_price_handler_format',
    );
  return
$items;
}
?>

With this function everything works as I expect it. But when I change this function so that it looks like

<?php
function price_test_uc_price_handler() {
 
$items['format'] = array(
   
'title' => t('Default 2 price handler'),
   
'description' => t('The default handler ...'),
   
'callback' => 'price_test_price_handler_format',
    );
  return
$items;
}
?>

then I get a fatal error. In my oppinion it would be nice to be able to register a formatter without needing to specify an alterer as well. This does not seem to be possible with the current implementation of uc_price(). There is only a very small modification needed in uc_price() to make that possible. Change

<?php
// Alter the price, context, and options.
foreach ($handlers['alterers'] as $alterer) {
 
$alterer($price_info, $context, $options);
}
?>

to

<?php
foreach ($handlers['alterers'] as $alterer) {
  if (
function_exists($alterer)) {
   
$alterer($price_info, $context, $options);
  }
}
?>

What do you think? (I nearly created an issue at http://drupal.org/node/add/project-issue/ubercart but since that page states that feature requests are not allowed there I decided to mention this here.)

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Return from hook_uc_price_handler() without an array key 'al

I thought we only didn't allow support requests. Not that it matters, since I think this is a bug report. Smiling

Here's a patch to the _uc_price_get_handlers() function. Since that controls which handlers are available, both when uc_price() is called, and on the settings form, I think it's a better place to make sure that all of the functions exist. Here's a patch to do that.

AttachmentSize
price_handlers.patch 796 bytes
fmueller's picture
Offline
Joined: 04/02/2009
Juice: 33
Re: Re: Return from hook_uc_price_handler() without an array key

Hello Lyle, thanx for providing this patch.