title: Retrieving the total discount of an order in process in ZenCart
body: <p>I'm working with ZenCart 1.5.1 and a custom mod called "TaxCloud".</p>
  
  <p>I would like to know if there is a way to retrieve an active, in process order's discount total that is being computed by the module <code>ot_coupon.php</code>. (As in an order that is not completed yet but in the middle of being completed.)</p>
  
  <p>I know that the value is stored in a variable called <code>$od_amount['total']</code>. It is also displayed on the pages <code>checkout_payment</code> and <code>checkout_confirmation</code>.</p>
  
  <p>But I need to refer to that value </p>
  
  <p>Here is the relevant code from ZenCart 1.5.1's <code>ot_coupon.php</code>. Mind you this is a part of a PHP class.</p>
  
  <pre><code>function calculate_deductions($order_total) {
  global $db, $order, $messageStack, $currencies;
  $currencyDecimalPlaces = $currencies-&gt;get_decimal_places($_SESSION['currency']);
  $od_amount = array('tax'=&gt;0, 'total'=&gt;0);
  if ($_SESSION['cc_id']) 
  {
    $coupon = $db-&gt;Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . (int)$_SESSION['cc_id'] . "'");
    $this-&gt;coupon_code = $coupon-&gt;fields['coupon_code'];
    $orderTotalDetails = $this-&gt;get_order_total($_SESSION['cc_id']);
    if ($coupon-&gt;RecordCount() &gt; 0 &amp;&amp; $orderTotalDetails['orderTotal'] != 0 ) 
    {
      if (strval($orderTotalDetails['orderTotal']) &gt;= $coupon-&gt;fields['coupon_minimum_order']) 
      {
        switch($coupon-&gt;fields['coupon_type'])
        {
          case 'S':
            $od_amount['total'] = $orderTotalDetails['shipping'];
            $od_amount['type'] = 'S';
            $od_amount['tax'] = ($this-&gt;calculate_tax == 'Standard') ? $orderTotalDetails['shippingTax'] : 0;
            if (isset($_SESSION['shipping_tax_description']) &amp;&amp; $_SESSION['shipping_tax_description'] != '') {
              $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
            }
            return $od_amount;
            break;
          case 'P':
            $od_amount['total'] = zen_round($orderTotalDetails['orderTotal']*($coupon-&gt;fields['coupon_amount']/100), $currencyDecimalPlaces);
            $od_amount['type'] = $coupon-&gt;fields['coupon_type']; 
            $ratio = $od_amount['total']/$orderTotalDetails['orderTotal'];
            break;
          case 'F':
            $od_amount['total'] = zen_round($coupon-&gt;fields['coupon_amount'] * ($orderTotalDetails['orderTotal']&gt;0), $currencyDecimalPlaces);
            $od_amount['type'] = $coupon-&gt;fields['coupon_type']; // amount off 'F' or amount off and free shipping 'O'
            $ratio = $od_amount['total']/$orderTotalDetails['orderTotal'];
            break;
        }
        switch ($this-&gt;calculate_tax) 
        {
          case 'None':
            break;
          case 'Standard':
            if ($od_amount['total'] &gt;= $orderTotalDetails['orderTotal']) $ratio = 1;
            foreach ($orderTotalDetails['orderTaxGroups'] as $key=&gt;$value) 
            {
              $od_amount['tax_groups'][$key] = zen_round($orderTotalDetails['orderTaxGroups'][$key] * $ratio, $currencyDecimalPlaces);
              $od_amount['tax'] += $od_amount['tax_groups'][$key];
              if ($od_amount['tax_groups'][$key] == 0) unset($od_amount['tax_groups'][$key]);
            }
            if (DISPLAY_PRICE_WITH_TAX == 'true' &amp;&amp; $coupon-&gt;fields['coupon_type'] == 'F') $od_amount['total'] = $od_amount['total'] + $od_amount['tax']; 
            break;
          case 'Credit Note':
            $tax_rate = zen_get_tax_rate($this-&gt;tax_class);
            $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate);
            $tax_description = zen_get_tax_description($this-&gt;tax_class);
            $od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
        }
      }
    }
  }
  
  
    return $od_amount;
  }
  </code></pre>