I really like the simplicity of this module, I just can't get it to work.
I'm using Drupal 6.15 and kept modules to a bear minimum. Installation was fine, the 'Discount' displays and is easy to use, but nothing happens. No discount is applied. I've tried it several times with lots of different combinations, checked it in the shopping cart and at checkout but I can't get it to apply the discount.

Thanks,

Rob

Comments

roblav’s picture

Title: Not working » No discount applied
freelock’s picture

I have the same result -- discount is not shown on product, not shown in cart, shown in checkout, not applied on checkout review screen or actual transaction. ???

jeremydvt’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta1
Category: support » bug

I'm having much the same problem as in the comment above.

I see the correct discount on the checkout page (in the payment method box) but it is not displayed on the review page, nor applied to the final amount that the user pays.

Happy to help with further info if it helps.

If it changes anything i am using discounts in conjunction with a signup enabled product.

emptyvoid’s picture

Priority: Normal » Critical

I would agree without the discount actually getting applied this module is virtually useless.. I

It would appear that most of the hooks to modify the cart_item and the theme displays are missing from this module to make it actually work. The module doesn't have the "hook_order" function which would be used to modify the order and actually save the discount when completing the order.

I really like the interface for this as it is very user friendly compared to the other modules for discounts. But sadly not applying the discounts to actual products make it useless.

Drupal 6.16
Ubercart 6.x-2.x-dev (2010-Mar-01)
Ubercart Bulk Discount 6.x-1.x-dev (2009-Dec-14)

awebb’s picture

I'll take a look into it soon.

gedur’s picture

I´ve the same problem, I can see the discount on Order total preview but it doesn´t apply on the review order.
thanks for take a look

adshill’s picture

Agreed... discount is not applied after the checkout screen rendering the module useless. Wish I'd read this before setting it up as it took forever! Please put a notification on the module page that it currently is NOT ready for production sites until this bug is fixed - otherwise it can create major issues for people!

Thanks,

Adam

adshill’s picture

Title: No discount applied » No discount applied at confirmation - Not production ready

Actually as I thoroughly test I'm noticing that some discounts just simply don't get applied at all as the original poster wrote. Seems to be random, for some products it works (at checkout at least) and others not. This is a real shame as otherwise the module is great. Sadly I'm not a coder so can't really help other than debugging.

adshill’s picture

Component: Documentation » Code
emptyvoid’s picture

The following is my rather hackish attempt at getting the module to work at 2:00 am the night before the project was due.
It appears to work, however I didn't have a lot of time to test it. Based on my initial tests it does work and applies correctly for several different product types.

// $Id: uc_bulk_discount.module,v 1.1.2.1 2009/12/14 21:25:40 awebb Exp $

/**
 * uc_bulk_discount.module
 * ------------------------------------
 *  
 * This module provides users with the 'manage discounts' role the ability to 
 * specify quantity discounts ( percentage ) for specific users and all users 
 * of specified roles on products.
 * 
 * > When a site visitor logs in, special discounts goes into effect.
 * 
 * > Discounts are specified with quantity tiers.
 * 
 * > User discounts override role discounts.
 * 
 * > If user has multiple roles with special discounts, then the greatest 
 *   discount is used.
 * 
 * > Display discount tiers for this user on the product page.
 *   Got to encourage those sales :-)
 * 
 * > Discounts apply to all product types ( attribute combinations ).
 * 
 */

//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------

/**
 * Module permissions.
 */
define( 'UCBD_PERM_MANAGE_DISCOUNTS', 'manage discounts' );

/**
 * Pricing rule types.
 */
define( 'UCBD_TYPE_USER', 'user' );
define( 'UCBD_TYPE_ROLE', 'role' );

//------------------------------------------------------------------------------
// Drupal hooks
//------------------------------------------------------------------------------

/**
 * Implementation of hook_perm().
 *
 * @see http://api.drupal.org/api/function/hook_perm/6
 */
function uc_bulk_discount_perm( ) {

  return array ( 
    UCBD_PERM_MANAGE_DISCOUNTS 
  );
}

//------------------------------------------------------------------------------

/**
 * Implementation of hook_menu().
 * 
 * Implemented pages:
 * 
 * 	node/{nid}/edit/discounts/add            ( local task )
 *  node/{nid}/edit/discounts/edit/{pdid}    ( local task )
 *  node/{nid}/edit/discounts/delete/{pdid}  ( local task )
 * 
 *  where {nid} is a product node.
 * 
 * @see http://api.drupal.org/api/function/hook_menu/6
 */
function uc_bulk_discount_menu( ) {
  $items = array();
    
  $items['node/%node/edit/discounts'] = array(
    'title' => 'Discounts',
    'page callback' => 'uc_bulk_discount_list_discounts',
    'page arguments' => array(1),
    'access callback' => 'uc_bulk_discount_admin_access',
    'access arguments' => array(1),
    'weight' => -6,
    'type' => MENU_LOCAL_TASK,
    'file' => 'uc_bulk_discount.admin.inc',
  );
    
  $items['node/%node/edit/discounts/add'] = array(
    'title' => 'Add product discount rule',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('uc_bulk_discount_add_discount_form', 1),
    'access callback' => 'uc_bulk_discount_admin_access',
    'access arguments' => array(1),
    'weight' => -8,
    'type' => MENU_LOCAL_TASK,
    'file' => 'uc_bulk_discount.admin.inc',
  );
  
  $items['node/%node/edit/discounts/edit/%discount_rule'] = array(
    'title' => 'Edit product discount rule',
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('uc_bulk_discount_edit_discount_form', 1, 5),
    'access callback' => 'uc_bulk_discount_admin_access',
    'access arguments' => array(1),
    'weight' => -6,
    'type' => MENU_LOCAL_TASK,
    'file' => 'uc_bulk_discount.admin.inc',
  );
    
  $items['node/%node/edit/discounts/delete/%discount_rule'] = array(
    'title' => 'Delete product discount rule',
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('uc_bulk_discount_delete_discount_form', 1, 5),
    'access callback' => 'uc_bulk_discount_admin_access',
    'access arguments' => array(1),
    'weight' => -4,
    'type' => MENU_LOCAL_TASK,
    'file' => 'uc_bulk_discount.admin.inc',
  );
  
  return $items;
}

//------------------------------------------------------------------------------

/**
 * Implementation of hook_theme().
 *
 * @see http://api.drupal.org/api/function/hook_theme/6
 */
function uc_bulk_discount_theme( ) {  
  return array(
    'uc_bulk_discount_rule_listing' => array(
      'arguments' => array( 'node' => NULL, 'discount_rules' => NULL ),
      'file'      => 'uc_bulk_discount.admin.inc',
    ),
    'uc_bulk_discount_product_discounts' => array(
      'arguments' => array( 'form' => NULL ),
    ),
    'uc_bulk_discount_cart_block_content' => array(
      'arguments' => array(),
    )
  );  
}

//------------------------------------------------------------------------------

/**
 * Implementation of hook_nodeapi(). 
 *
 * @see http://api.drupal.org/api/function/hook_nodeapi/6
 */
function uc_bulk_discount_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  
  switch ($op) {
    case 'delete':
      // Clear all existing product rules when a node is deleted.
      module_load_include( 'inc', 'uc_bulk_discount', 'uc_bulk_discount.api' );
      
      $discount_rules = uc_bulk_discount_select_rules(
        array(
        	'nid' => $node->nid,
        ),
        TRUE
      );
      
      foreach ($discount_rules as $rule) {
        uc_bulk_discount_remove_rule($rule);
      }      
      break;    
  }  
}

//------------------------------------------------------------------------------

/**
 * Implementation of hook_user(). 
 *
 * @see http://api.drupal.org/api/function/hook_user/6
 */
function uc_bulk_discount_user($op, &$edit, &$account, $category = NULL) {
  
  switch ($op) {
    case 'delete':
      // Clear all user rules when the corresponding user is deleted.
      module_load_include( 'inc', 'uc_bulk_discount', 'uc_bulk_discount.api' );
      
      $discount_rules = uc_bulk_discount_select_rules(
        array(
          'type' => UCBD_TYPE_USER,
        	'xid'  => $account->uid,
        ),
        TRUE
      );
      
      foreach ($discount_rules as $rule) {
        uc_bulk_discount_remove_rule($rule);
      }      
      break;     
  }
}

//------------------------------------------------------------------------------

/**
 * Implementation of hook_form_alter(). 
 *
 * @see http://api.drupal.org/api/function/hook_form_alter/6
 */
function uc_bulk_discount_form_alter(&$form, $form_state, $form_id) {
	
	if ($form_id == 'user_admin_role') {
	  // Delete relevant rules when role is deleted.
		$form['#submit'][] = 'uc_bulk_discount_user_admin_role_submit';		
	}
	elseif (variable_get('uc_bulk_discount_show_discounts', TRUE)
	        && preg_match('/^uc_product_add_to_cart_form(_\d+)?/', $form_id)) {
	  
	  module_load_include('inc', 'uc_bulk_discount', 'uc_bulk_discount.api');
	  
	  // Append discount information to cart form.
	  $form['discounts'] = array(
	    '#type'  => 'markup',
	    '#value' => theme('uc_bulk_discount_product_discounts', $form['nid']['#value']),
	    '#weight' => 10,
	  );
	  $form['submit']['#weight'] = 15;
	}
}

//------------------------------------------------------------------------------
// Ubercart hooks
//------------------------------------------------------------------------------

/**
 * Implementation of hook_line_item().
 */
function uc_bulk_discount_line_item() {
  
    $items[] = array(
    'id' => 'uc_bulk_discount',
    'title' => t('Group upgrade discount'),
    'callback' => 'uc_bulk_discount_line_item_discount',
    'weight' => 5,
    'stored' => TRUE,
    'default' => FALSE,
    'calculated' => TRUE,
    'add_list' => TRUE,
    'display_only' => FALSE,
  );

  return $items;
}

//------------------------------------------------------------------------------
// Menu access handlers
//------------------------------------------------------------------------------

function uc_bulk_discount_admin_access( $node ) {
  if ( uc_product_is_product( $node ) && user_access( UCBD_PERM_MANAGE_DISCOUNTS ) ) {
    return TRUE;
  }
  return FALSE;
}

//------------------------------------------------------------------------------
// Form handlers
//------------------------------------------------------------------------------

function uc_bulk_discount_user_admin_role_submit($form, &$form_state) {
	if ($form_state['values']['op'] == t('Delete role')) {
		// Clear all role based rules when the corresponding role is deleted.
    module_load_include('inc', 'uc_bulk_discount', 'uc_bulk_discount.api');
      
    $discount_rules = uc_bulk_discount_select_rules(
      array(
        'type' => UCBD_TYPE_ROLE,
      	'xid'  => $form_state['values']['rid'],
      ),
      TRUE
    );
      
    foreach ($discount_rules as $rule) {
      uc_bulk_discount_remove_rule($rule);
    }
	}
}

//------------------------------------------------------------------------------
// Line item handlers
//------------------------------------------------------------------------------

/**
 * Handle the discount line item.
 */
function uc_bulk_discount_line_item_discount($op, $arg1) {
  module_load_include( 'inc', 'uc_bulk_discount', 'uc_bulk_discount.api' );

    switch ($op) {
  	case 'cart-preview':
	  
		$discounts = uc_bulk_discount_get_discounts($arg1);
  		
  		if (count($discounts)) {
  			$js = 'if (Drupal.jsEnabled) { $(document).ready(function() { '
        	   . ' if (window.set_line_item) { ';
		    
		    if (count($discounts) > 1) {
		      $total_discount = 0;
		      
		      foreach ($discounts as $discount) {
			$total_discount = $total_discount + $discount->amount;
		      }
		      
		      $js .= "set_line_item('uc_bulk_discount', 'Combined Quantity Discount', ". $total_discount .", ". variable_get('uc_bulk_discount_discount_weight', 5) ."); ";
		      
		      
		    } else {
		      foreach ($discounts as $discount) {
			$js .= "set_line_item('uc_bulk_discount', '". $discount->name ."', ". $discount->amount .", ". variable_get('uc_bulk_discount_discount_weight', 5) ."); ";
		     } 
		    }

		    $js .= '} }) };';
  		
  			drupal_add_js($js, 'inline');
  		}
      break;
      
    case 'load':
      
      $lines = array();
      	
      foreach (uc_bulk_discount_get_discounts($arg1->products) as $discount) {
       	$lines[] = array(
         	'id'     => 'uc_bulk_discount',
         	'title'  => $discount->name,
         	'amount' => $discount->amount,
         	'weight' => variable_get('uc_bulk_discount_discount_weight', 5),
         	'data'   => $discount->data,
       	);
      }
      return $lines;
  }
}


function uc_bulk_discount_cart_item($op, &$item) {
  
  
  switch ($op) {
  case 'load':
    module_load_include( 'inc', 'uc_bulk_discount', 'uc_bulk_discount.api' );
      $items = array($item);
      foreach (uc_bulk_discount_get_discounts($items) as $discount) {
	    // update order total
	    $item->discount_total = (string)$discount->amount;
	}
      break;
  }
}

function uc_bulk_discount_cart_pane($items) {
  
}

function uc_bulk_discount_checkout_pane() {
  
}

function uc_bulk_discount_order($op, &$arg1, $arg2) {
  module_load_include( 'inc', 'uc_bulk_discount', 'uc_bulk_discount.api' );
 
  switch ($op) {
    case 'load':
      // Do something to load payment info!
      break;
    case 'delete':
      // delete entries related to discounts
      foreach (uc_bulk_discount_get_discounts($arg1->products) as $discount) { 
	    // update order total
	    $result2 = db_query("DELETE FROM {uc_order_line_items} WHERE title = '%s' AND order_id = %d AND type = 'discount'", $discount->name, $arg1->order_id);
	}
      break;
    case 'new':
      // Do something to save payment info!
	/*
	foreach (uc_bulk_discount_get_discounts($arg1->products) as $discount) { 
	    
	}
	*/
      break;
    case 'save':
      // Do something to save payment info!
	foreach (uc_bulk_discount_get_discounts($arg1->products) as $discount) { 
	    // update order total
	    // get current discount line items
	    $result_items = db_query("SELECT * FROM {uc_order_line_items} WHERE title = '%s' AND order_id = %d AND type = 'discount'", $discount->name, $arg1->order_id);
	    // if none for this type
	    $results_count = 0;
	    while (db_fetch_array($result_items)) {
	      $results_count = $results_count + 1;
	    }
	    
	      if ($results_count == 0) {
                // add it
                uc_order_line_item_add($arg1->order_id, 'discount', $discount->name, $discount->amount, 5);
              } else if ($results_count > 1) {
                // if more than one exists
                // blow them away
                db_query("DELETE FROM {uc_order_line_items} WHERE title = '%s' AND order_id = %d AND type = 'discount'", $discount->name, $arg1->order_id);
                // then add it.
                uc_order_line_item_add($arg1->order_id, 'discount', $discount->name, $discount->amount, 5);
              }
            
	}
      break;
    case 'total':
	if ($arg1->order_id !== 0) {
	  $total_discounts = 0;      
	  foreach (uc_bulk_discount_get_discounts($arg1->products) as $discount) {
	      $total_discounts = $total_discounts + (float)$discount->amount;
	  }
	  return $total_discounts;
	}
      break;
  }
  
}


//------------------------------------------------------------------------------
// Theme functions
//------------------------------------------------------------------------------

function theme_uc_bulk_discount_product_discounts($product_nid) {

  $discount_tiers = uc_bulk_discount_get_discount_tiers($product_nid);
  
  $header = array(t('Low quantity'), t('High quantity'), t('Discount'));
  $rows   = array();
  
  foreach ($discount_tiers as $tier) {
    
    $row = array(
      $tier['low_qty'],
      $tier['high_qty'],
      sprintf( '%.2f', $tier['discount']) . '% off'
    );
        
    $rows[] = $row;    
  }  
  if (count($rows)) {
    return '<div class="discount-table">'
  	  . '<div class="table-message">' . t('Receive a volume discount when you purchase multiple individual products.') . '</div>' 
      . theme('table', $header, $rows)
      . '</div>';
  }
  return '';
}


// The default function from uc_cart.module.
function theme_uc_bulk_discount_cart_block_content() {
  global $user;



  if (
variable_get('uc_cart_show_help_text', FALSE)) {
    $output = '<span class="cart-help-text">'
            . variable_get('uc_cart_help_text', t('Click title to display cart contents.'))
             .'</span>';
  }

 
$output .= '<div id="block-cart-contents">';

 
$items = uc_cart_get_contents();

 
$item_count = 0;
  if (!empty($items)) {
    $output .= '<table class="cart-block-table">'
              .'<tbody class="cart-block-tbody">';
    foreach ($items as $item) {
      $output .= '<tr class="cart-block-item"><td class="cart-block-item-qty">'. $item->qty .'x</td>'
               . '<td class="cart-block-item-title">'. l($item->title, 'node/'. $item->nid) .'</td>'
               . '<td class="cart-block-item-price">'. uc_currency_format($item->price) .'</td></tr>';
      if (is_array($item->data['attributes']) && !empty($item->data['attributes'])) {
        $display_item = module_invoke($item->module, 'cart_display', $item);
        $output .= '<tr><td colspan="3">'. $display_item['options']['#value'] .'</td></tr>';
      }
      $total += ($item->price) * $item->qty;
      $item_count += $item->qty;
    }

   
$output .= '</tbody></table>';
  }
  else {
    $output .= '<p>'. t('There are no products in your shopping cart.') .'</p>';
  }

 
$output .= '</div>';

 
$item_text = format_plural($item_count, '1 Item', '@count Items');
  $view = '('. l(t('View cart'), 'cart', array('rel' => 'nofollow')) .')';
  if (variable_get('uc_checkout_enabled', TRUE)) {
    $checkout = ' ('. l(t('Checkout'), 'cart/checkout', array('rel' => 'nofollow')) .')';
  }
  $output .= '<table class="cart-block-summary-table"><tbody class="cart-block-summary-tbody">'
            .'<tr class="cart-block-summary-tr"><td class="cart-block-summary-items">'
            . $item_text .'</td><td class="cart-block-summary-total">'
            .'<strong>'. t('Total:') .'</strong> '. uc_currency_format($total) .'</td></tr>';
  if ($item_count > 0) {
    $output .= '<tr><td colspan="2" class="cart-block-summary-checkout">'. $view . $checkout .'</td></tr>';
  }
  $output .= '</tbody></table>';

  return
$output;
}



//------------------------------------------------------------------------------
// Internal utilities
//------------------------------------------------------------------------------

function discount_rule_load( $pdid ) {
  module_load_include( 'inc', 'uc_bulk_discount', 'uc_bulk_discount.api' );
  return uc_bulk_discount_select_rules( array( 'pdid' => $pdid ) );  
}

//------------------------------------------------------------------------------

function uc_bulk_discount_get_discounts($products) {
	
  $discounts    = array();
  $product_data = array();
			
	foreach ($products as $product) {
	  
	  $price = ($product->price * $product->qty);
	  
	  if (!array_key_exists($product->nid, $product_data)) {
	    $product_data[$product->nid] = array(
	      'nid'   => $product->nid,
	      'title' => $product->title,
	      'qty'   => $product->qty,
	      'price' => $price,
	    );
	  }
	  else {
	    $product_data[$product->nid]['qty'] += $product->qty;
	    $product_data[$product->nid]['price'] += $price;  
	  }	  
	}
	
	foreach ($product_data as $nid => $data) {
		$amount = _uc_bulk_discount_get_discount_amount($data);
			
		if ($amount) {
			$discount = new stdClass();

			$discount->name   = t('!title quantity discount', array('!title' => $data['title']));
			$discount->amount = $amount;
			$discount->data   = array();		

			$discounts[] = $discount;
		}
	}
	
	return $discounts;	
}

//------------------------------------------------------------------------------

function _uc_bulk_discount_get_discount_amount($product_data) {
    
  $amount = 0;
    
  $discount_map = uc_bulk_discount_map_discounts($product_data['nid']);
  $product_qty  = $product_data['qty'];
  
  if (array_key_exists($product_qty, $discount_map)) {
    $amount = uc_bulk_discount_calculate_discount($product_data['price'], $discount_map[$product_qty]);  
  }
  return min($amount, 0);
}

//------------------------------------------------------------------------------

function uc_bulk_discount_map_discounts($product_nid, $account = NULL) {
    
  $rules = uc_bulk_discount_applicable_rules($product_nid, $account);
  $map   = array();  
  
  // Higher discount role rules override lower discount rules.
  foreach ($rules['role'] as $rule) {
  	for ($qty = $rule['low_qty']; $qty <= $rule['high_qty']; $qty++) {
  	  if (!$map[$qty] || $rule['discount'] > $map[$qty]) {
  	    $map[$qty] = $rule['discount'];
  	  }
  	}
  }
  // User rules override all role rules, even if they are lower discount.
  foreach ($rules['user'] as $rule) {
    for ($qty = $rule['low_qty']; $qty <= $rule['high_qty']; $qty++) {
  	  $map[$qty] = $rule['discount'];
  	}	 
  }
  return $map;
}

//------------------------------------------------------------------------------

function uc_bulk_discount_applicable_rules($nid, $account = NULL) {
	global $user;
	
	if (is_null($account)) {
		$account = $user;
	}
	
	$rules = uc_bulk_discount_select_rules(array('nid' => $nid), TRUE);
	
	$user_rules = array( );
	$role_rules = array( );
	
	$results = array();
	
  // Separate into type sections.
  foreach ($rules as $rule) {
    switch ($rule['type']) {
      case UCBD_TYPE_USER:
        $user_rules[$rule['xid']][] = $rule;
        break;  
          
  	 	case UCBD_TYPE_ROLE:
        $role_rules[$rule['xid']][] = $rule;
        break;                   
    }
  }	      

  // First see if there are any user rules available.
  $results['user'] = array();
  if (array_key_exists($account->uid, $user_rules)) {
  	$results['user'] = $user_rules[$account->uid];
  }
  
  // Check for role based rules.
  $results['role'] = array();  
  foreach ($account->roles as $rid => $name) {
  	if (array_key_exists($rid, $role_rules)) {
  	  $results['role'] = array_merge($results['role'], $role_rules[$rid]);  
  	}
  }  
  return $results;
}

//------------------------------------------------------------------------------

function uc_bulk_discount_get_discount_tiers($product_nid, $account = NULL) {
  
  $discount_map = uc_bulk_discount_map_discounts($product_nid, $account);
  $tiers        = array();
  
  $tier = NULL;
  foreach ($discount_map as $qty => $discount) {
    
    if (is_null($tier)
        || ($qty > ($tier['high_qty'] + 1)) 
        || ($discount != $tier['discount'])) {
          
      if (!is_null($tier)) {
        $tiers[] = $tier;
      }      
      // Start new tier.
      $tier = array(
        'low_qty' => $qty,
        'high_qty' => $qty,
        'discount' => $discount,
      );
    }
    else {
      // Continue old tier.
      $tier['high_qty'] = $qty;
    }
  }
  if (!is_null($tier)) {
    $tiers[] = $tier;  
  }
  return $tiers;
}

//------------------------------------------------------------------------------

function uc_bulk_discount_calculate_discount($price, $discount_amount) {
  return (-1 * ($price * ($discount_amount / 100)));
}

//------------------------------------------------------------------------------

It would appear the input formats are broken on drupal.org

emptyvoid’s picture

Status: Active » Needs review
adshill’s picture

Status: Needs review » Needs work

Ok.. its much better :) Thanks for the work emptyvoid

One bug I have noticed, is that if you only have one product, the discount doesn't seem to appear in the checkout page. It is applied in the review, so its there, but in the checkout it doesn't show.

Multiple products work and you see "Combined discount" but if only one then there is nothing.

Thanks!

Adam

adshill’s picture

Update: I think thmy diagnosis wasn't complete... it appears that with products without tax everything works fine, but when there is tax on just one product then that product discount doesn't show.

jtjones23’s picture

subscribe

emptyvoid’s picture

The problem when the Tax module is enabled is the client-side javascript rendering of this module may conflict with the tax module.

function uc_bulk_discount_line_item_discount($op, $arg1)

Handles loading the calculations for display on the checkout page.

Does your tax get added as a line item on review and order processing?

ahughes3’s picture

I'm creeping up on a deadline and it's looking like discounts is the only thing holding me back..Should I just use the code that emptyvoid provided?

wyattbiker’s picture

Thanks to emptyvoid for the module fix above. It works like a charm. However I wanted to show the discount breakdowns so I fixed/added couple of lines to this function in his module. To do that I added a counter in the main loop where it totals the discounts for each item (see variable $cnt) and display it using set_line_item. The original code only did Combined Quantity Discount. Looking at the original discount module, this was a bug anyway, since it only displayed the last item discount.

/**
* Handle the discount line item.
*/
function uc_bulk_discount_line_item_discount($op, $arg1) {
  module_load_include( 'inc', 'uc_bulk_discount', 'uc_bulk_discount.api' );

    switch ($op) {
  case 'cart-preview':
 
$discounts = uc_bulk_discount_get_discounts($arg1);
  if (count($discounts)) {
  $js = 'if (Drupal.jsEnabled) { $(document).ready(function() { '
           . ' if (window.set_line_item) { ';
   
    if (count($discounts) > 1) {
      $total_discount = 0;
     
      $cnt=0;
      foreach ($discounts as $discount) {
$total_discount = $total_discount + $discount->amount;
$cnt++;
$js .= "set_line_item('uc_bulk_discount$cnt', '". $discount->name ."', ". $discount->amount .", ". variable_get('uc_bulk_discount_discount_weight', 5+$cnt) ."); ";
      }
     $cnt++;
      $js .= "set_line_item('uc_bulk_discount', '***Total Quantity Discount***', ". $total_discount .", ". variable_get('uc_bulk_discount_discount_weight', 5+$cnt) ."); ";
     
     
    } else {
      foreach ($discounts as $discount) {
$js .= "set_line_item('uc_bulk_discount', '". $discount->name ."', ". $discount->amount .", ". variable_get('uc_bulk_discount_discount_weight', 5) ."); ";
     }
    }

    $js .= '} }) };';
 
  drupal_add_js($js, 'inline');
  }
      break;
     
    case 'load':
     
      $lines = array();
     
      foreach (uc_bulk_discount_get_discounts($arg1->products) as $discount) {
       $lines[] = array(
         'id'     => 'uc_bulk_discount',
         'title'  => $discount->name,
         'amount' => $discount->amount,
         'weight' => variable_get('uc_bulk_discount_discount_weight', 5),
         'data'   => $discount->data,
       );
      }
      return $lines;
  }
}
rlange77’s picture

@wyattbiker:

I applied your "patch" to my system and it works perfectly fine.
Thanks for that.

Is there a way to display the ***Total Quantity Discount*** line in the review (cart/checkout/review) and in the order as well?

Thanks for all your work you have done so far.
/rob

gausarts’s picture

Subscribing. Thanks

mccrodp’s picture

Subscribe

mennonot’s picture

subscribing. Any chance this will get applied to the module?

FluxRostrum’s picture

Ditto the thanks and praying these patches work (I'm an inexperience patcher) clients pissed. wish I read this first.

FluxRostrum’s picture

don't know what the deal is but when I used these fixes it ... it broke my whole site.

I had the file backed up so it's ..ok but why would I get a site that just displays code after installing when others have got a functional site after installing them?

zoen’s picture

Sounds like you need to add the "<?php" at the top of your modified uc_bulk_discount.module file. (Sorry if this reply is much too late.)

webstylemedia’s picture

Must confirm that this module DOESN'T WORK! DIscounts not applied on review pages, on actual payment pages and on next order pages and order emails.

Can't be used.

Guys please fix module ASAP

Thanks.

D

AviadG’s picture

subscribing