omg, a talking sausage.

price handler

Ubercart 2.x Price Handler and Old Price

Ubercart 2.x introduced a new way of handling product prices. It is called price_handler().

This is very nice, and most of the discount and TAX modules are using this new function to override the product price, but what if you need the new price and the old price on the same product?

Let's say you would like to show your visitors the product price before it was discounted.

You obviously should not change the condribution modules or the Ubercart core. You should just simply create your own module or use the general module you have created earlier (You got one, right?) and just paste the following lines at the bottom.

This function will create the price handler. Don't forget to replace 'your_module' with your module name everywhere.

/**
* Implementation of hook_uc_price_handler().
*/
function your_module_uc_price_handler() {
return array(
'alter' => array(
'title' => t('Old price handler'),
'description' => t('Adds old price to product.'),
'callback' => 'your_module_price_handler_alter',
),
);
}

 

This function will save the original Sell Price and put it on the node object for further use.

/**
* This is just a function to save the original sell price and put it on the node.
*/
function your_module_price_handler_alter(&$price_info, &$context, &$options) {
if (isset($context['subject']['node'])
&& $context['subject']['field'] == 'sell_price'
&& !isset($context['subject']['node']->old_price)) {
$node = $context['subject']['node'];
$context['subject']['node']->old_price = $node->sell_price;
}
}