I added two fees to my store with a price of $0.00 each. Then, I added those fees to a product, and set the product-specific fee override to $12.00. However, when looking at the product page itself, the $0.00 price is displayed instead. The fees are added to the order properly, but they just weren't displaying right in the product Add To Cart form.

So I dug in and found the problem. The theme function theme_uc_fee_price() is what determines which price is displayed in the Add To Cart form. It looks like this:

function theme_uc_fee_price($fee) {
  $fee_price = is_null($fee->default_price) ? $fee->price : $fee->default_price;
  return $fee->type == UC_FEE_TYPE_ABSOLUTE? uc_currency_format($fee_price) : $fee_price.'%';
}

The problem is in the first line of that function. is_null() is being used to check if a default price exists on the product. If the default price is null, then the override price is used instead.

This logic doesn't make sense, because it requires the default price to be NULL in order for the product-specific price to override it. This essentially means that product-specific prices can't override default prices if the default price has a value.

And on top of that, it's impossible to NOT have a default value because the form for creating the fee is required. AND: the $fee object that is passed into theme_uc_fee_price($fee) stores the value as a string, so a zero value (ie: 0.00) will never be NULL.

All of this can be fixed pretty easily by changing the first line of the theme function to:

  $fee_price = (float)$fee->price ? $fee->price : $fee->default_price;

So instead of checking if the default price is null, it checks to see if a product-specific override is available (and converts it to a float to avoid the string problem). If a product override exists, it will use that, otherwise it will use the default price.

I've attached a patch that works with the 6.x-1.0-beta2 release.

CommentFileSizeAuthor
uc_fee.add-to-cart.patch495 bytesm.stenta

Comments

agileadam’s picture

I had originally fixed this problem by changing that first line to:

$fee_price = is_null($fee->price) ? $fee->default_price : $fee->price;