4 replies [Last post]
FastDesign's picture
Offline
Joined: 02/10/2010
Juice: 34

Is there a way to set a minimum order value based on a user role? I have some wholesale clients that I want to enforce a minimum order of $300 on. Is there a way I can use conditional actions for this?

Thanks in advance for any insight.

FastDesign's picture
Offline
Joined: 02/10/2010
Juice: 34
minimum order value based on role

We ended up using a mod to function uc_cart_checkout() to restrict the minimum order value to roles. Works very well.

Client site is www.rougeliving.com which has wholesale and retail pricing, restriction to box quantities for wholesale clients, and a stack more customisation. Will post details in Live Sites soon.

mimetic2's picture
Offline
Joined: 08/07/2007
Juice: 478
Re: minimum order value based on role

can you elaborate more on this? I want to do the same thing

vladiz's picture
Offline
Joined: 10/12/2009
Juice: 34
Re: set minimum order value based on user role

need that too, any advice?

FastDesign's picture
Offline
Joined: 02/10/2010
Juice: 34
set minimum order value based on role

I made the following modification to uc_cart.pages.inc. I would rather use a theme override or create a module to handle this, but it's beyond my abilities, so I'll just have to be careful when upgrading to a new version of Ubercart.

Essentially I have two roles that I want to apply the minimum order value to: wholesale - general and wholesale - agent, which are covered in an if statement. It would be better to use the role ID, but again, I didn't have the time or ability to work that out.

Any suggestions on alternate approaches would be welcome, but this 'fix' achieved our objectives.

function uc_cart_checkout() {
  global $user;

  $items = uc_cart_get_contents();
  if (count($items) == 0 || !variable_get('uc_checkout_enabled', TRUE)) {
    drupal_goto('cart');
  }

  $context = array(
    'revision' => 'altered',
    'type' => 'amount',
  );

  if (in_array("wholesale - general", $user->roles) || in_array("wholesale - agent", $user->roles)) {
  if (($min = uc_price(variable_get('uc_minimum_subtotal', 0), $context)) > 0) {
    $subtotal = 0;
    if (is_array($items) && count($items) > 0) {
      foreach ($items as $item) {
        $data = module_invoke($item->module, 'cart_display', $item);
        if (!empty($data)) {
          $subtotal += $data['#total'];
        }
      }
    }
    if ($subtotal < $min) {
      $context = array(
        'revision' => 'formatted-original',
        'type' => 'amount',
      );
      drupal_set_message(variable_get('uc_minimum_subtotal_text', t('The minimum wholesale order for checkout is !min, additional items or quantities need to be added to process order.', array('!min' => uc_price($min, $context)))), 'error');
      drupal_goto('cart');
    }
  }
  }

  // Send anonymous users to login page when anonymous checkout is disabled.
  if (!$user->uid && !variable_get('uc_checkout_anonymous', TRUE)) {
    drupal_set_message(t('You must login before you can proceed to checkout.'));
    if (variable_get('user_register', 1) != 0) {
      drupal_set_message(t('If you do not have an account yet, you should <a href="!url">register now</a>.', array('!url' => url('user/register'))));
    }
    $_SESSION['checkout-redirect'] = TRUE;
    drupal_goto('user');
  }
  else {
    unset($_SESSION['checkout-redirect']);
  }

  $list = _line_item_list();
  foreach ($list as $line_item) {
    if (function_exists($line_item['callback'])) {
      $line_item['callback']('cart-preview', $items);
    }
  }

  drupal_add_js(drupal_get_path('module', 'uc_cart') .'/uc_cart.js');
  $output = drupal_get_form('uc_cart_checkout_form');

  return $output;
}