In addition to the...

FLEXICHARGE_CHARGE                 +/-
FLEXICHARGE_CHARGE_PCT_SUBTOTAL    % of current total
FLEXICHARGE_CHARGE_PCT_ITEMTOTAL   % of item total

...operators, I propose that a FLEXICHARGE_CHARGE_PER_ITEM operator be introduced to Flexicharge.

This would allow administrators to easily configure ecommerce to calculate shipping surcharges at a flat rate per item, rather than as a percentage of item total or subtotal.

For instance, in my case, I sell CDs online, and need to configure ecommerce to charge customers as follows:

CD 1 = $16
CD 2 = $16
CD 3 = $16
  SUBTOTAL = $48
Handling charge = $3
$0.50 postage per item = $1.50
  TOTAL = $52.50

I'll followup to this issue with an example of how I hacked custom.inc to perform this calculation.

Comments

bjornarneson’s picture

In order to achieve the PER_UNIT charge as requested above. I hacked the FLEXICHARGE_CHARGE_PCT_ITEMTOTAL operator in custom.inc. See below.

/**
 * 'General' charge calculation
 *
 * FLEXICHARGE_CHARGE                 +/-
 * FLEXICHARGE_CHARGE_PCT_SUBTOTAL    % of current total
 * FLEXICHARGE_CHARGE_PCT_ITEMTOTAL   % of item total
 *
 */
function general_custom_flexicharge_calculate(&$txn, $misc, $total) {

  $this_total = 0;
  // Do the pct if needed
  if (($misc->operator != FLEXICHARGE_CHARGE) && $misc->rate) {
    $factor = 1;
    if($misc->rate < 0 ) {$factor = -1;}
    $pct = ($misc->rate * $factor) / 100;
  }

  switch ($misc->operator) {
    
	case FLEXICHARGE_CHARGE:
      return $misc->rate;
    
	case FLEXICHARGE_CHARGE_PCT_SUBTOTAL:
      return ($total * $pct * $factor);
    
	case FLEXICHARGE_CHARGE_PCT_ITEMTOTAL:
      $value = 0;
      foreach ((array)$txn->items as $item) {
          if ($item->ptype == 'tangible') {     // add this check, only charge shipping for tangible items
          if (product_has_quantity($item)) {
            // $value += ($item->price * $item->qty); // we only care about the quantity, not the price
            $value += $item->qty; 
          }
          //else {
          //  $value += $item->price;
          // }
        }
	  }
      //return ($value * $pct * $factor); // the $pct and $factor calculation is unused
      return ($value * $misc->rate); // multiply the item quantity by the rate per unit
   }
}

sime’s picture

This will be possible in v4

Also http://drupal.org/node/161099 marked a duplicate of this.

gordon’s picture

Status: Active » Postponed