Hello,
I really like this module and have it set up in the store. I have 3 different pricing roles for customers, ie regular customer, dealer, and wholesaler. If I want to create an order for a customer that is called in by phone, I log in as Admin and create an order in Ubercart. When I add the products to the cart, it uses the price set for the ADMIN, not the customer. So for every customer I have to change the Admin's role pricing to enter the orders.

I would like it to be possible that the customers pricing would be used when anyone creates an order using the admin/create orders functions.

Bounty available.

2dogrc

Comments

jlockhart’s picture

I know this is an old issue but I have a client complaining about this issue as well. I think I have a fix but I'm not sure its the right approach. I'm basically checking the page path and if its the admin order edit page then I load the user from the current order and pass that on to the pricing rather than the logged in user.

Here is the function with my changes, sorry its not a patch.

function uc_member_pricing_nodeapi( &$node, $op, $a3 = NULL, $a4 = NULL ) {
  global $user;
  
  /** Check to see if we are on the admin edit order form
   * If so we want to use that orders user to calculate
   * pricing, rather than the currently logged in user
   */
    if (arg(0) . '/' . arg(1) . '/' . arg(2) == 'admin/store/orders') {
      $order_user = db_result(db_query('SELECT uid FROM {uc_orders} WHERE order_id = %d', arg(3)));
      $pricing_user = user_load($order_user);
    } else {
      $pricing_user = $user;
    }
  
  switch ( $op ) {
    case 'load':
      if ( uc_product_is_product( $node ) && arg(2) != 'edit' ) {
        module_load_include( 'inc', 'uc_member_pricing', 'uc_member_pricing.api' );

        $price_rules = uc_member_pricing_select_rules(
          array( 'nid' => $node->nid ),
          TRUE
        );

        if ( count( $price_rules ) ) {
          // Separate into type sections.
          $role_rules = array( );
          $user_rules = array( );

          foreach ( $price_rules as $rule ) {
            switch ( $rule[ 'type' ] ) {
              case UCMP_TYPE_ROLE:
                $role_rules[ $rule[ 'xid' ] ] = $rule;
                break;

              case UCMP_TYPE_USER:
                $user_rules[ $rule[ 'xid' ] ] = $rule;
                break;
            }
          }

          // Find individual user price.
          if ( array_key_exists( $user->uid, $user_rules ) ) {
            $member_price = uc_member_pricing_calculate_price( $node->sell_price, $user_rules[ $pricing_user->uid ][ 'price' ] );
          }
          // Find lowest user role price.
          else {
            foreach ( $pricing_user->roles as $rid => $name ) {
              $role_price = uc_member_pricing_calculate_price( $node->sell_price, $role_rules[ $rid ][ 'price' ] );

              if ( is_null( $lowest_price ) || $role_price < $lowest_price ) {
                $lowest_price = $role_price;
              }

              $member_price = $lowest_price;
            }
          }

          // Set new product price for this site member.
          if ( !is_null( $member_price ) ) {
            $node->sell_price = max( $member_price, 0 );
          }
        }
      }
      break;

    case 'delete':
      // Remove all member prices for products being deleted.
      module_load_include( 'inc', 'uc_member_pricing', 'uc_member_pricing.api' );

      $price_rules = uc_member_pricing_select_rules(
        array( 'nid' => $node->nid ),
        TRUE
      );

      foreach ( $price_rules as $rule ) {
        uc_member_pricing_remove_rule( $rule );
      }
  }
}

Hope that helps.

rocketeerbkw’s picture

Version: 6.x-1.0-beta1 » 6.x-1.x-dev
Status: Active » Needs review

Seems kind of hacky-ish but I can't really think of a better solution. Next time I get some free time I'll do some testing and get this rolled in.

On just looking at the code, it seems like you missed a change to $pricing_user on this line if ( array_key_exists( $user->uid, $user_rules ) ) {