Added functionality

phethean's picture
Offline
Joined: 08/07/2008
Juice: 10
Added functionality

Ok I've made some more changes to this:
Line numbers are accumulative, based on lines already inserted. Lines also replace any lines mentioned in the code.

***uc_product.module***
Changes made to display the cost price for certain role (in this case "retailer") on product view (but not on teasers, also disables Ajax Attribute Calculations functionality)

Line 735:

global $user;
if (in_array("retailer", $user->roles)){
  $node->content['display_price'] = array('#value' => theme('uc_product_display_price', $node->cost),
    '#access' => $enabled['display_price'],
    '#weight' => $weight['display_price'],
  );
} else {
  $node->content['display_price'] = array('#value' => theme('uc_product_display_price', $node->sell_price),
    '#access' => $enabled['display_price'],
    '#weight' => $weight['display_price'],
  );
}

Line 766:

if (in_array("retailer", $user->roles)){
  $node->content['sell_price'] = array('#value' => theme('uc_product_sell_price', $node->cost, $teaser),
    '#access' => $enabled['sell_price'],
    '#weight' => $weight['sell_price'],
  );
} else {
  $node->content['sell_price'] = array('#value' => theme('uc_product_sell_price', $node->sell_price, $teaser),
    '#access' => $enabled['sell_price'],
    '#weight' => $weight['sell_price'],
  );
}

***uc_attribute.module***
Applies attribute cost instead of price for user role ("retailer" again). You can set the cost in node>edit>options.

Line 315:

      foreach ($item->options as $option) {
        $op_costs += $option['cost'];
        $op_prices += $option['price'];
        $op_weight += $option['weight'];
      }
      $item->cost += $op_costs;
      global $user;
      if (in_array("retailer", $user->roles)){
         $item->price += $op_costs;
      }else{
         $item->price += $op_prices;
      }
      $item->weight += $op_weight;

Line 1476:

// Build the attribute's options array.
      global $user;
      $options = array();

Line 1481:

case 'total':
if (in_array("retailer", $user->roles)){
   $display_price = in_array($relation->aid, $priced_attributes) ? ', '. uc_currency_format(($node->sell_price + $option->cost) * $qty) : '';
} else {
   $display_price = in_array($relation->aid, $priced_attributes) ? ', '. uc_currency_format(($node->sell_price + $option->price) * $qty) : '';
}

and finally 1490:

case 'adjustment':
if (in_array("retailer", $user->roles)){
   $display_price = ($option->cost != 0 ? ', '. ($option->cost > 0 ? '+' : '') . uc_currency_format($option->cost * $qty) : '');
} else {
   $display_price = ($option->price != 0 ? ', '. ($option->price > 0 ? '+' : '') . uc_currency_format($option->price * $qty) : '');
}

I think that's all. An ugly hack but I hope this helps someone as much as it will me. I'll post any issues I get with this as I test it a bit more. Any questions or issues post here cheers!
John

Different role prices. Do you think is a good solution? By: enkara (58 replies) Thu, 07/31/2008 - 14:50