After enabling any one role for optional pricing, UC starts reporting zero price for any product when the current user has that role. That happens due to the following lines in uc_price_per_role.module, function uc_price_per_role_find_price:

  foreach ($weights as $rid => $weight) {
    if (isset($user->roles[$rid]) && $enabled[$rid] && isset($prices[$rid])) {
      return $prices[$rid];
    }
  }

$prices[$rid] equals "0.00" for any product/role if the price was not manually set. So isset($prices[$rid]) is always true, and the price for the first enabled role is always returned - even if it's zero.
To fix that, you just need to change IF conditions to the following:

  foreach ($weights as $rid => $weight) {
    if (isset($user->roles[$rid]) && $enabled[$rid] && (float)$prices[$rid]) {
      return $prices[$rid];
    }
  }

Now the first available price would be returned, and FALSE if none is available, - as it's supposed to be by design.

Comments

longwave’s picture

Status: Needs review » Fixed

This wouldn't work if you actually intended a product to be free for certain roles and not for others; the free price would be ignored.

An alternate fix has been committed, that correctly shows an empty field in the product edit page if a price has not yet been set, instead of defaulting to $0.00.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.