this is my code:
$product = node_load($product_id);
$product->attribute1 = 'example';
node_save($product );

when this code being called , the real sell_price data in database has been changed to current user's role price.

i think this is bug ,because many other modules called node_load, node_save.it does not works as your expectation.

the coresponding code in uc_price_per_role module is:
$original_price = $node->sell_price;
$price = uc_price_per_role_find_price($prices);
if ($price !== FALSE) {
$node->sell_price = $price;
}

Comments

fuzzydru’s picture

I have the same issue using version 5.1.3. Once a user with a role associated with a "role price" edits a product the product "sell price" gets saved with the "role price" value.

The only thing I can see altering the $node->sell_price is in line 232:

      case 'load':
        $result = db_query("SELECT rid, price FROM {uc_price_per_role_prices} WHERE vid = %d", $node->vid);
        $prices = array();
        while ($row = db_fetch_object($result)) {
          $prices[$row->rid] = $row->price;
        }

        $price = uc_price_per_role_find_price($prices);
        if ($price !== FALSE) {
          $node->sell_price = $price;
        }

Does anyone know how to avoid this error?

Saoirse1916’s picture

Subscribing

rferguson’s picture

Issue summary: View changes

NOTE**: This is for Drupal 7 only, but a similar fix could be applied in the right place for 6.

I've come across this same thing and have fixed the issue with a small module. Contents of the module is:

/**
 * Implements hook_node_presave().
 * It fixes role price field when using the node_save OR Views bulk operations (which in turn uses node_save). 
 * What was happening was the hooks that were running on the edit page weren't running on node save to adjust the sell price/role price fields
 */
function uc_price_per_role_fix_node_presave($node) {
  //only run if coming from outside of the node edit form. Example being running node_save
  if(arg(2) != 'edit'){
    if (isset($node->roleindependent_sell_price)) {
      // Reload original price for editing.
      $node->sell_price = $node->roleindependent_sell_price;
    }
  }
}

What it's doing is the same thing the module already does for hook_node_prepare (sets the sell price to be correct for node edit page). While doing node_save on your own, this isn't happening and the role's price is overwritten. This keeps it the same as if saving from the edit page while using node_save. Confirmed works with Views bulk operations as well (which basically just calls node_save as well).