Discount coupon code amount greater than cart order total

When discount coupon code amount is greater than cart order total, calculated order total is wrong. For example coupon code amount is $40.63 and cart order total is $35.95. Here are two steps to fix this problem. In ot_coupon.php make these changes.

1. In function calculate_deductions function comment one line.

           if ($coupon->fields['coupon_type'] == 'P') {
            $od_amount['total'] = round($orderTotal*($coupon->fields['coupon_amount']/100), 2);
            $od_amount['type'] = 'P';
            $ratio = $od_amount['total']/$orderTotal;
          } elseif ($coupon->fields['coupon_type'] == 'F') {
            $od_amount['total'] = round($coupon->fields['coupon_amount'] * ($orderTotal>0), 2);
            $od_amount['type'] = 'F';
            $ratio = $od_amount['total']/$orderTotal;
          }

          // comment this line so that the actual coupon amount is propagated.
          //if ($od_amount['total'] > $orderTotal) $od_amount['total'] = $orderTotal;
          //
          switch ($this->calculate_tax) {
            case 'None':
              if ($this->include_tax == 'true') {
                reset($order->info['tax_groups']);
                foreach ($order->info['tax_groups'] as $key=>$value) {
                  $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio;
                }
              }
            break;
            case 'Standard': ...

2. Comment three lines in process function

  function process() {
    global $order, $currencies;
    $order_total = $this->get_order_total();
    $od_amount = $this->calculate_deductions($order_total['total']);
    $this->deduction = $od_amount['total'];
    if ($od_amount['total'] > 0) {
      reset($order->info['tax_groups']);
      $tax = 0;
      while (list($key, $value) = each($order->info['tax_groups'])) {
        if ($od_amount['tax_groups'][$key]) {
          $order->info['tax_groups'][$key] -= $od_amount['tax_groups'][$key];
          $tax += $od_amount['tax_groups'][$key];
        }
      }
      if ($od_amount['type'] == 'S') $order->info['shipping_cost'] = 0;
      $order->info['total'] = $order->info['total'] - $od_amount['total'];

      //comment these lines
      //if (DISPLAY_PRICE_WITH_TAX != 'true') {
      //  $order->info['total'] -= $tax;
      //}

      $order->info['tax'] = $order->info['tax'] - $tax;
      //      if ($this->calculate_tax == "Standard") $order->info['total'] -= $tax;
      if ($order->info['total'] < 0) $order->info['total'] = 0;
      $this->output[] = array('title' => $this->title . ': ' . $this->coupon_code . ' :',
                              'text' => '-' . $currencies->format($od_amount['total']),
                              'value' => $od_amount['total']);
    }
  }

Finally check discount coupon configuration in admin to make sure it does not include shipping.

Bookmark and Share

Coupon Code Data Feed Loading & Importing Automation

Take the pain out of loading and importing multiple coupon code data into your site. This system works for all major affiliate network coupon code data feed – linkconnector, share-a-sale, commission junction, icodes, wagjag, swarmjam, groupon, livingsocial, redflagdeals, etc. Perfect for coupon affiliates, ecommerce sites/shopping carts and personal sites. The multiple coupon code loading and importing system is fast, efficient, customizable and robust.  Multiple coupon code loading and importing system can import several hundred, thousand  or even ten of thousands of coupon codes in a few seconds or minutes.
Bookmark and Share