I would like to show on every product page difference between sell price and price using computed field. I am not familiar with PHP so I need a little help what exactly to put into Computed Code and Display Format. Or is there any way how to solve this please? Thank you for any help.

Comments

abbbu’s picture

any ideas please?

doublejosh’s picture

I might recommend you do this in your node template. Take the price value and do some calculation to show the "original" price. Basically, fake it on the display layer. Since I'm assuming this is for face sale purpose anyway :)

Denys Babenko’s picture

Here's how I did it. Expert comments are highly welcome.

You should paste this function to template.php of your theme and change 'theme' in function's name to your theme's name.
template.php can be found in your theme directory (otherwise create empty file template.php)

function theme_uc_product_price($price, $context, $options = array()){
  // Checks context for display sell price
  // the one that by default shown next to product image
  // if context match and sell price is lower than list price
  // shows both prices with altered classes so that you can
  // use color and font decoration to highlight your sale price
  if($context['field'] == 'sell_price' && in_array('display',$context['class'])){
    $list_price = (float)$context['subject']['node']->list_price;
    $sell_price = (float)$context['subject']['node']->sell_price;
    if($list_price > $sell_price){
      
    	$sale_price = theme_uc_product_price($price, $context, $options);
      
    	// Value "you" save in percent
    	$save_percent = round( 100 - ( $sell_price * 100 / $list_price) );
    	// output html
      $sale_price .= '<div class="uc-sell-discount-percent product-info '. implode(' ', (array)$context['class']) .'">';
      $sale_price .=  t("You save !save_percent%", array('!save_percent' => $save_percent));
      $sale_price .= '</div>';
      
      return $sale_price;
    }  
  } 
  return theme_uc_product_price($price, $context, $options);
}

Add this to CSS of your theme. In case it displays wrong you should adjust it here.

.uc-sell-discount-percent{
  clear: right;
  float: right;
  color: red;
}
andrews501’s picture

Hello,

I am trying to add this code to template.php using Acquia Prosper theme of uberdrupal-6.x-1.0-alpha7-core.tar (drupal 6.19), however, after adding it according to the instructions here an Error 500 message appears when I click on to see the product. Any suggestions, please?

Many thanks

tugboatfixer’s picture

This is also what I have been looking for and have found no solution other than computed fields. I am not a PHP coder so I don't know how to use it. All I would like is to have a field on a product view display "You Save" this much percent or actual dollar amount. Maybe I am asking the wrong question but I have searched for the answer with every keyword possible. Thanks in advance for any help.

philsward’s picture

I agree... stock ubercart sucks when it comes to marketing a product... This type of "MSRP", Our Price, You Save idea is implemented on countless websites... hell, even walmart does that sort of thing in store :)