Jump to content
Strider

Credit Class/Gift Vouchers/Discount Coupons 5.10

Recommended Posts

Guest

Update: New Info, Still Need Help with CCGV(5.19)

 

This post is related to my post from yesterday. My web site address and test user account are listed in that other post.

 

I'm no PHP expert, but here's what I think is happening. I'm not sure if it's allowed to offer payment to the person who can resolve this for me, but I'm getting that desperate. I really need to figure out why my "Redeem" button doesn't work.

 

1) checkout_payment.php has this:

 

<?php // #################### Added CGV ######################

echo $order_total_modules->credit_selection();//ICW ADDED FOR CREDIT CLASS SYSTEM

// #################### End Added CGV ###################### ?>

 

2) order_total.php I can't tell what this does, exactly, but it has the functions of order_total, process, output, credit_selection, sub_credit_selection, update_credit_account, collect_posts, pre_confirmation_check, apply_credit, clear_posts, get_order_total_main. So, a variety of functions here.

 

3) ot_coupon.php also has a credit_selection function. I can't tell what actually calls this function. It seems this function is what actually builds the "checkout_payment_gift" form, which is used to send the code entered to the checkout confirmation page, where it is validated and applied.

 

When I View > Source in internet explorer on my checkout_payment.php file to see what is making it into the final page, the form and button which is created in ot_coupon.php in #3 above is not making it into the checkout_payment.php file.

 

That seems to be the problem, or a symptom. This part of the code in ot_coupon.php is not getting included somehow.

 

Can it be in conflict with the code in order_total? I do not know PHP well enough to know!!

 

I appreciate your help!

-Earl

 

 

Here is the code which I have loaded:

 

checkout_payment.php

<?php
/*
 $Id: checkout_payment.php,v 1.113 2003/06/29 23:03:27 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

 Copyright © 2003 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');

// #################### Begin Added CGV JONYO ######################
if (tep_session_is_registered('cot_gv')) tep_session_unregister('cot_gv');  //added to reset whether a gift voucher is used or not on this order
// #################### End Added CGV JONYO ######################

// if the customer is not logged on, redirect them to the login page
 if (!tep_session_is_registered('customer_id')) {
   $navigation->set_snapshot();
   tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
 }

// if there is nothing in the customers cart, redirect them to the shopping cart page
 if ($cart->count_contents() < 1) {
   tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
 }

// if no shipping method has been selected, redirect the customer to the shipping method selection page
 if (!tep_session_is_registered('shipping')) {
   tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 }

// avoid hack attempts during the checkout procedure by checking the internal cartID
 if (isset($cart->cartID) && tep_session_is_registered('cartID')) {
   if ($cart->cartID != $cartID) {
     tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
   }
 }

// if we have been here before and are coming back get rid of the credit covers variable
// #################### Added CGV ######################
if(tep_session_is_registered('credit_covers')) tep_session_unregister('credit_covers');  // CCGV Contribution
   if(tep_session_is_registered('cot_gv')) tep_session_unregister('cot_gv'); //CCGV
// #################### End Added CGV ######################

// Stock Check
 if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
   $products = $cart->get_products();
   for ($i=0, $n=sizeof($products); $i<$n; $i++) {
     if (tep_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
       tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
       break;
     }
   }
 }
// #################### Begin Added CGV JONYO ######################
// #################### THIS MOD IS OPTIONAL! ######################

// load the selected shipping module
  require(DIR_WS_CLASSES . 'shipping.php');
  $shipping_modules = new shipping($shipping);

// #################### End Added CGV JONYO ######################
// #################### THIS MOD WAS OPTIONAL! ######################

// if no billing destination address was selected, use the customers own address as default
 if (!tep_session_is_registered('billto')) {
   tep_session_register('billto');
   $billto = $customer_default_address_id;
 } else {
// verify the selected billing address
   $check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$billto . "'");
   $check_address = tep_db_fetch_array($check_address_query);

   if ($check_address['total'] != '1') {
     $billto = $customer_default_address_id;
     if (tep_session_is_registered('payment')) tep_session_unregister('payment');
   }
 }

 require(DIR_WS_CLASSES . 'order.php');
 $order = new order;
// #################### Added CGV ######################
 require(DIR_WS_CLASSES . 'order_total.php');//ICW ADDED FOR CREDIT CLASS SYSTEM
 $order_total_modules = new order_total;//ICW ADDED FOR CREDIT CLASS SYSTEM
 $order_total_modules->clear_posts(); // ADDED FOR CREDIT CLASS SYSTEM by Rigadin in v5.13
// #################### End Added CGV ######################

 if (!tep_session_is_registered('comments')) tep_session_register('comments');

 $total_weight = $cart->show_weight();
 $total_count = $cart->count_contents();
// #################### Added CGV ######################
 $total_count = $cart->count_contents_virtual(); //ICW ADDED FOR CREDIT CLASS SYSTEM
// #################### End Added CGV ######################

// load all enabled payment modules
 require(DIR_WS_CLASSES . 'payment.php');
 $payment_modules = new payment;

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_PAYMENT);

 $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 $breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script language="javascript"><!--
var selected;
<?php // #################### Added CGV ###################### ?>
var submitter = null;
function submitFunction() {
  submitter = 1;
  }
<?php // #################### End Added CGV ###################### ?>
function selectRowEffect(object, buttonSelect) {

 // #################### Begin Added CGV JONYO ######################
 if (!document.checkout_payment.payment[0].disabled){
 // #################### End Added CGV JONYO ######################
   if (!selected) {

   if (document.getElementById) {
     selected = document.getElementById('defaultSelected');
   } else {
     selected = document.all['defaultSelected'];
   }
 }

 if (selected) selected.className = 'moduleRow';
 object.className = 'moduleRowSelected';
 selected = object;

// one button is not an array
 if (document.checkout_payment.payment[0]) {
   document.checkout_payment.payment[buttonSelect].checked=true;
 } else {
   document.checkout_payment.payment.checked=true;
 }
// #################### Begin Added CGV JONYO ######################
 }
// #################### End Added CGV JONYO ######################
}

function rowOverEffect(object) {
 if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
 if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

<?php // #################### Begin Added CGV JONYO ###################### ?>

<?php
if (MODULE_ORDER_TOTAL_INSTALLED)
$temp=$order_total_modules->process();
$temp=$temp[count($temp)-1];
$temp=$temp['value'];

$gv_query = tep_db_query("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . $customer_id . "'");
$gv_result = tep_db_fetch_array($gv_query);

if ($gv_result['amount']>=$temp){ $coversAll=true;

?>

function clearRadeos(){
document.checkout_payment.cot_gv.checked=!document.checkout_payment.cot_gv.checked;
for (counter = 0; counter < document.checkout_payment.payment.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (document.checkout_payment.cot_gv.checked){
document.checkout_payment.payment[counter].checked = false;
document.checkout_payment.payment[counter].disabled=true;
//document.checkout_payment.cot_gv.checked=false;
} else {
document.checkout_payment.payment[counter].disabled=false;
//document.checkout_payment.cot_gv.checked=true;
}
}
}<?php } else { $coversAll=false;?>
function clearRadeos(){
document.checkout_payment.cot_gv.checked=!document.checkout_payment.cot_gv.checked;
}<?php } ?>
<?php // #################### End Added CGV JONYO ###################### ?>

//--></script>

<?php // #################### Begin Added CGV JONYO ###################### ?>
<?php // echo $payment_modules->javascript_validation(); ?>
<?php echo $payment_modules->javascript_validation($coversAll); ?>
<?php // #################### End Added CGV JONYO ###################### ?>

</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
 <tr>
   <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
   </table></td>
<!-- body_text //-->
   <td width="100%" valign="top">
<?php
// #################### Added CGV JONYO ######################
// echo tep_draw_form('checkout_payment', tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'), 'post', 'onsubmit="return check_form();"'); 
// #################### End Added CGV JONYO ######################
?><table border="0" width="100%" cellspacing="0" cellpadding="0">
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
           <td class="pageHeading">Step 2 of 4 - Secure Checkout</td>
           <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_payment.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
         </tr>
       </table></td>
     </tr>


<tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
           <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
             <tr>
               <td width="50%" align="right"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
             </tr>
           </table></td>
           <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
             <tr>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
               <td><?php echo tep_image(DIR_WS_IMAGES . 'checkout_bullet.gif'); ?></td>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
             </tr>
           </table></td>
           <td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
           <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
             <tr>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
             </tr>
           </table></td>
         </tr>
         <tr>
           <td align="center" width="25%" class="checkoutBarFrom"><?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '" class="checkoutBarFrom">' . CHECKOUT_BAR_DELIVERY . '</a>'; ?></td>
           <td align="center" width="25%" class="checkoutBarCurrent"><?php echo CHECKOUT_BAR_PAYMENT; ?></td>
           <td align="center" width="25%" class="checkoutBarTo"><?php echo CHECKOUT_BAR_CONFIRMATION; ?></td>
           <td align="center" width="25%" class="checkoutBarTo"><?php echo CHECKOUT_BAR_FINISHED; ?></td>
         </tr>
       </table>


<br>


     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
<?php
 if (isset($HTTP_GET_VARS['payment_error']) && is_object(${$HTTP_GET_VARS['payment_error']}) && ($error = ${$HTTP_GET_VARS['payment_error']}->get_error())) {
?>
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
         <tr>
           <td class="main"><b><?php echo tep_output_string_protected($error['title']); ?></b></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBoxNotice">
         <tr class="infoBoxNoticeContents">
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
               <td class="main" width="100%" valign="top"><?php echo tep_output_string_protected($error['error']); ?></td>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
             </tr>
           </table></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
<?php
 }
?>
<?php // #################### Begin Added CGV JONYO ###################### ?>
<?php // #################### THIS MOD IS OPTIONAL! ###################### ?>
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
         <tr>
           <td class="main"><b><?php echo HEADING_PRODUCTS; ?></b><?  echo ' <a href="' . tep_href_link(FILENAME_SHOPPING_CART) . '"><span class="orderEdit">(' . TEXT_EDIT . ')</span></a>'; ?></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
   <tr class="infoBoxContents">
           <td>
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
//}

for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
  echo '          <tr>' . "\n" .
       '            <td width="10%" class="main" align="right" valign="top" width="30">' . $order->products[$i]['qty'] . ' x</td>' . "\n" .
       '            <td width="60%" class="main" valign="top">' . $order->products[$i]['name'];

  if (STOCK_CHECK == 'true') {
    echo tep_check_stock($order->products[$i]['id'], $order->products[$i]['qty']);
  }

  if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
    for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
      echo '<br><nobr><small> <i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'] . '</i></small></nobr>';
    }
  }

  echo '</td>' . "\n";

  if (sizeof($order->info['tax_groups']) > 1) echo '            <td class="main" valign="top" align="right">' . tep_display_tax_value($order->products[$i]['tax']) . '% </td>' . "\n";

  echo '            <td width="30%"class="main" align="right" valign="top">' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . ' </td>' . "\n" .
       '          </tr>' . "\n";
}
?>
               <tr>
           <td COLSPAN="3" valign="top" align="right">
          <table border="0" cellspacing="0" cellpadding="3">
<?php
if (MODULE_ORDER_TOTAL_INSTALLED) {
  //$temp=$order_total_modules->process();
  echo $order_total_modules->output();
}
?>
                   </table>
        </td>
         </tr>
     </table>
  </td>
         </tr>
       </table></td>
     </tr>
<!--              </table></td>
            </tr-->
<?php // #################### End Added CGV JONYO ###################### ?>
<?php // #################### THIS MOD WAS OPTIONAL! ###################### ?>

     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
         <tr>
           <td class="main"><b><?php echo TABLE_HEADING_BILLING_ADDRESS; ?></b></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
         <tr class="infoBoxContents">
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> 
               <td class="main" width="50%" valign="top"><?php echo TEXT_SELECTED_BILLING_DESTINATION; ?><br><br><?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_PAYMENT_ADDRESS, '', 'SSL') . '">' . tep_image_button('button_change_address.gif', IMAGE_BUTTON_CHANGE_ADDRESS) . '</a>'; ?></td>
               <td align="right" width="50%" valign="top"><table border="0" cellspacing="0" cellpadding="2">
                 <tr>
                   <td class="main" align="center" valign="top"><b><?php echo TITLE_BILLING_ADDRESS; ?></b><br><?php echo tep_image(DIR_WS_IMAGES . 'arrow_south_east.gif'); ?></td>
                   <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> 
                   <td class="main" valign="top"><?php echo tep_address_label($customer_id, $billto, true, ' ', '<br>'); ?></td>
                   <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td> 
                 </tr>
               </table></td>
             </tr>
           </table></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
         <tr>
           <td class="main"><b><?php echo TABLE_HEADING_PAYMENT_METHOD; ?></b></td>
         </tr>
       </table></td>
<?php // #################### Added CGV ###################### 
 echo $order_total_modules->credit_selection();//ICW ADDED FOR CREDIT CLASS SYSTEM
// #################### End Added CGV ###################### ?>
     </tr>
     <tr>
       <td>

<?php
// #################### End Added CGV JONYO ######################
 echo tep_draw_form('checkout_payment', tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'), 'post', 'onsubmit="return check_form();"'); 
// #################### End Added CGV JONYO ######################
?>

<table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
         <tr class="infoBoxContents">
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
 $selection = $payment_modules->selection();

 if (sizeof($selection) > 1) {
?>
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
               <td class="main" width="50%" valign="top"><?php echo TEXT_SELECT_PAYMENT_METHOD; ?></td>
               <td class="main" width="50%" valign="top" align="right"><b><?php echo TITLE_PLEASE_SELECT; ?></b><br><?php echo tep_image(DIR_WS_IMAGES . 'arrow_east_south.gif'); ?></td>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
             </tr>
<?php
 } else {
?>
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
               <td class="main" width="100%" colspan="2"><?php echo TEXT_ENTER_PAYMENT_INFORMATION; ?></td>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
             </tr>
<?php
 }

 $radio_buttons = 0;
 for ($i=0, $n=sizeof($selection); $i<$n; $i++) {
?>
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
               <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
   if ( ($selection[$i]['id'] == $payment) || ($n == 1) ) {
     echo '                  <tr id="defaultSelected" class="moduleRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ')">' . "\n";
   } else {
     echo '                  <tr class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, ' . $radio_buttons . ')">' . "\n";
   }
?>
                   <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                   <td class="main" colspan="3"><b><?php echo $selection[$i]['module']; ?></b></td>
                   <td class="main" align="right">
<?php
   if (sizeof($selection) > 1) {
     echo tep_draw_radio_field('payment', $selection[$i]['id']);
   } else {
     echo tep_draw_hidden_field('payment', $selection[$i]['id']);
   }
?>
                   </td>
                   <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                 </tr>
<?php
   if (isset($selection[$i]['error'])) {
?>
                 <tr>
                   <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                   <td class="main" colspan="4"><?php echo $selection[$i]['error']; ?></td>
                   <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                 </tr>
<?php
   } elseif (isset($selection[$i]['fields']) && is_array($selection[$i]['fields'])) {
?>
                 <tr>
                   <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                   <td colspan="4"><table border="0" cellspacing="0" cellpadding="2">
<?php
     for ($j=0, $n2=sizeof($selection[$i]['fields']); $j<$n2; $j++) {
?>
                     <tr>
                       <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                       <td class="main"><?php echo $selection[$i]['fields'][$j]['title']; ?></td>
                       <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                       <td class="main" valign="top"><?php echo $selection[$i]['fields'][$j]['field']; ?></td>
                       <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                     </tr>
<?php
     }
?>
                   </table></td>
                   <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                 </tr>
<?php
   }
?>
               </table></td>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
             </tr>
<?php
   $radio_buttons++;
 }

// #################### Begin Added CGV JONYO ######################

if (tep_session_is_registered('customer_id')) {
if ($gv_result['amount']>0){
 echo ' <tr><td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td><td colspan=2>' . "\n" .
 								' <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr class="moduleRow" onmouseover="rowOverEffect(this)" onclick="clearRadeos()" onmouseout="rowOutEffect(this)" >' . "\n" .
                            '   <td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td><td class="main">' . $gv_result['text'];

 echo $order_total_modules->sub_credit_selection();
 }
}


// #################### End Added CGV JONYO ######################

?>
           </table></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
         <tr>
           <td class="main"><b><?php echo TABLE_HEADING_COMMENTS; ?></b></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
         <tr class="infoBoxContents">
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
               <td><?php echo tep_draw_textarea_field('comments', 'soft', '60', '5'); ?></td>
             </tr>
           </table></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
         <tr class="infoBoxContents">
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
               <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
               <td class="main"><b><?php echo TITLE_CONTINUE_CHECKOUT_PROCEDURE . '</b><br>' . TEXT_CONTINUE_CHECKOUT_PROCEDURE; ?></td>
               <td class="main" align="right"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>
               <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
             </tr>
           </table></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
           <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
             <tr>
               <td width="50%" align="right"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
             </tr>
           </table></td>
           <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
             <tr>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
               <td><?php echo tep_image(DIR_WS_IMAGES . 'checkout_bullet.gif'); ?></td>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
             </tr>
           </table></td>
           <td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
           <td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
             <tr>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>
               <td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>
             </tr>
           </table></td>
         </tr>
         <tr>
           <td align="center" width="25%" class="checkoutBarFrom"><?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '" class="checkoutBarFrom">' . CHECKOUT_BAR_DELIVERY . '</a>'; ?></td>
           <td align="center" width="25%" class="checkoutBarCurrent"><?php echo CHECKOUT_BAR_PAYMENT; ?></td>
           <td align="center" width="25%" class="checkoutBarTo"><?php echo CHECKOUT_BAR_CONFIRMATION; ?></td>
           <td align="center" width="25%" class="checkoutBarTo"><?php echo CHECKOUT_BAR_FINISHED; ?></td>
         </tr>
       </table></td>
     </tr>
   </table></form></td>
<!-- body_text_eof //-->
   <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
   </table></td>
 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

 

order_total.php

<?php
/*
 $Id: order_total.php,v 1.4 2003/02/11 00:04:53 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

 Copyright © 2003 osCommerce

 Released under the GNU General Public License
*/

 class order_total {
   var $modules;

// class constructor
   function order_total() {
     global $language;

     if (defined('MODULE_ORDER_TOTAL_INSTALLED') && tep_not_null(MODULE_ORDER_TOTAL_INSTALLED)) {
       $this->modules = explode(';', MODULE_ORDER_TOTAL_INSTALLED);

       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         include(DIR_WS_LANGUAGES . $language . '/modules/order_total/' . $value);
         include(DIR_WS_MODULES . 'order_total/' . $value);

         $class = substr($value, 0, strrpos($value, '.'));
         $GLOBALS[$class] = new $class;
       }
     }
   }

   function process() {
     $order_total_array = array();
     if (is_array($this->modules)) {
       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ($GLOBALS[$class]->enabled) {
           $GLOBALS[$class]->process();

           for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
             if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {
               $order_total_array[] = array('code' => $GLOBALS[$class]->code,
                                            'title' => $GLOBALS[$class]->output[$i]['title'],
                                            'text' => $GLOBALS[$class]->output[$i]['text'],
                                            'value' => $GLOBALS[$class]->output[$i]['value'],
                                            'sort_order' => $GLOBALS[$class]->sort_order);
             }
           }
         }
       }
     }

     return $order_total_array;
   }

   function output() {
     $output_string = '';
     if (is_array($this->modules)) {
       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ($GLOBALS[$class]->enabled) {
           $size = sizeof($GLOBALS[$class]->output);
           for ($i=0; $i<$size; $i++) {
             $output_string .= '              <tr>' . "\n" .
                               '                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['title'] . '</td>' . "\n" .
                               '                <td align="right" class="main">' . $GLOBALS[$class]->output[$i]['text'] . '</td>' . "\n" .
                               '              </tr>';
           }
         }
       }
     }

     return $output_string;
   }
// ############ Added CCGV Contribution ##########
//
// This function is called in checkout payment after display of payment methods. It actually calls
// two credit class functions.
//
// use_credit_amount() is normally a checkbox used to decide whether the credit amount should be applied to reduce
// the order total. Whether this is a Gift Voucher, or discount coupon or reward points etc.
//
// The second function called is credit_selection(). This in the credit classes already made is usually a redeem box.
// for entering a Gift Voucher number. Note credit classes can decide whether this part is displayed depending on
// E.g. a setting in the admin section.
//
   function credit_selection() {
     $selection_string = '';
     $close_string = '';
     $credit_class_string = '';
     if (MODULE_ORDER_TOTAL_INSTALLED) {
       $header_string = '<tr>' . "\n";
       $header_string .= '   <td><table border="0" width="100%" cellspacing="0" cellpadding="2">' . "\n";
       $header_string .= '      <tr>' . "\n";
       $header_string .= '        <td class="main"><b>' . TABLE_HEADING_CREDIT . '</b></td>' . "\n";
       $header_string .= '      </tr>' . "\n";
       $header_string .= '    </table></td>' . "\n";
       $header_string .= '  </tr>' . "\n";
       $header_string .= '<tr>' . "\n";
       $header_string .= '   <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">' . "\n";
       $header_string .= '     <tr class="infoBoxContents"><td><table border="0" width="100%" cellspacing="0" cellpadding="2">' ."\n";
       $header_string .= '       <tr><td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>' . "\n";
       $header_string .= '           <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">' . "\n";
       $close_string   = '                           </table></td>';
       $close_string  .= '<td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>';
       $close_string  .= '</tr></table></td></tr></table></td>';
       $close_string  .= '<tr><td width="100%">' .  tep_draw_separator('pixel_trans.gif', '100%', '10') . '</td></tr>';
       reset($this->modules);
       $output_string = '';



while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) {

// #################### Begin Added CGV JONYO ######################
          //$use_credit_string = $GLOBALS[$class]->use_credit_amount();
// #################### End Added CGV JONYO ######################




           if ($selection_string =='') $selection_string = $GLOBALS[$class]->credit_selection();
           if ( ($use_credit_string !='' ) || ($selection_string != '') ) {
             $output_string .=  '<tr colspan="4"><td colspan="4" width="100%">' .  tep_draw_separator('pixel_trans.gif', '100%', '10') . '</td></tr>';
             $output_string = ' <tr class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" >' . "\n" .
                              '   <td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>' .
                              '     <td class="main"><b>' . $GLOBALS[$class]->header . '</b></td>' . $use_credit_string;
             $output_string .= '<td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>';
             $output_string .= '  </tr>' . "\n";
             $output_string .= $selection_string;
           }

         }
       }
       if ($output_string != '') {
        $output_string = $header_string . $output_string;
        $output_string .= $close_string;
      }
    }
    return $output_string;
  }
// #################### Begin Added CGV JONYO ######################
function sub_credit_selection(){
	$selection_string = '';
     $close_string = '';
     $credit_class_string = '';
     if (MODULE_ORDER_TOTAL_INSTALLED) {

       reset($this->modules);
       $output_string = '';
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) {
           $use_credit_string = $GLOBALS[$class]->use_credit_amount();
           if ($selection_string =='') $selection_string = $GLOBALS[$class]->credit_selection();
           if ( ($use_credit_string !='' ) || ($selection_string != '') ) {

             $output_string = /*' <tr><td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td><td colspan=2><table border="0" cellpadding="2" cellspacing="0" width="100%"><tr class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" >' . "\n" .
                              '   <td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>' .*/
                             $use_credit_string;
             $output_string .= '<td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>';
             $output_string .= '  </tr></table></td><td width="10">' .  tep_draw_separator('pixel_trans.gif', '10', '1') .'</td></tr>' . "\n";
		  //$output_string.=$GLOBALS[$class]->use_credit_amount();
             //$output_string .= $selection_string;
           }

         }
       }
       if ($output_string != '') {
         //$output_string =  $output_string;
         //$output_string .= $close_string;
       }
     }
     return $output_string;
   }
// #################### End Added CGV JONYO ######################
//            if ($selection_string !='') {
//              $output_string .= '</td>' . "\n";
//              $output_string .= $selection_string;
//            }




// update_credit_account is called in checkout process on a per product basis. It's purpose
// is to decide whether each product in the cart should add something to a credit account.
// e.g. for the Gift Voucher it checks whether the product is a Gift voucher and then adds the amount
// to the Gift Voucher account.
// Another use would be to check if the product would give reward points and add these to the points/reward account.
//
   function update_credit_account($i) {
     if (MODULE_ORDER_TOTAL_INSTALLED) {
       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
           $GLOBALS[$class]->update_credit_account($i);
         }
       }
     }
   }
// This function is called in checkout confirmation.
// It's main use is for credit classes that use the credit_selection() method. This is usually for
// entering redeem codes(Gift Vouchers/Discount Coupons). This function is used to validate these codes.
// If they are valid then the necessary actions are taken, if not valid we are returned to checkout payment
// with an error
//
   function collect_posts() {
     global $HTTP_POST_VARS,$HTTP_SESSION_VARS;
     if (MODULE_ORDER_TOTAL_INSTALLED) {
       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
           $post_var = 'c' . $GLOBALS[$class]->code;
// #################### Begin Added CGV JONYO ######################
//            if ($HTTP_POST_VARS[$post_var]) $_SESSION[$post_var] = $HTTP_POST_VARS[$post_var];
//            if (!tep_session_is_registered($post_var)) tep_session_register($post_var);
           if ($HTTP_POST_VARS[$post_var]) {
							if (!tep_session_is_registered($post_var)) tep_session_register($post_var);
// ############ Added CCGV Contribution ##########
			$post_var = $HTTP_POST_VARS[$post_var];
// ############ End Added CCGV Contribution ##########
					}
// #################### End Added CGV JONYO ######################
           $GLOBALS[$class]->collect_posts();
         }

       }
     }
   }
// pre_confirmation_check is called on checkout confirmation. It's function is to decide whether the
// credits available are greater than the order total. If they are then a variable (credit_covers) is set to
// true. This is used to bypass the payment method. In other words if the Gift Voucher is more than the order
// total, we don't want to go to paypal etc.
//
       function pre_confirmation_check() {
// #################### Begin Added CGV JONYO ######################
     global $payment, $order, $credit_covers, $customer_id;
// #################### End Added CGV JONYO ######################
     if (MODULE_ORDER_TOTAL_INSTALLED) {

       $total_deductions  = 0;
       reset($this->modules);
       $order_total = $order->info['total'];
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         $order_total = $this->get_order_total_main($class,$order_total);
         if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
           $total_deductions = $total_deductions + $GLOBALS[$class]->pre_confirmation_check($order_total);
           $order_total = $order_total - $GLOBALS[$class]->pre_confirmation_check($order_total);
         }
       }
// #################### Begin Added CGV JONYO ######################

     $gv_query=tep_db_query("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . $customer_id . "'");
     $gv_result=tep_db_fetch_array($gv_query);
     $gv_payment_amount = $gv_result['amount'];

//        if ($order->info['total'] - $total_deductions <= 0 ) {
       if ($order->info['total'] - $gv_payment_amount <= 0 ) {
         if (tep_session_is_registered('cot_gv')) {
if(!tep_session_is_registered('credit_covers')) tep_session_register('credit_covers');
         $credit_covers = true;
         }
       }
else{   // belts and suspenders to get rid of credit_covers variable if it gets set once and they put something else in the cart
	if(tep_session_is_registered('credit_covers')) tep_session_unregister('credit_covers');
}
// #################### End Added CGV JONYO ######################
     }
   }
// this function is called in checkout process. it tests whether a decision was made at checkout payment to use
// the credit amount be applied aginst the order. If so some action is taken. E.g. for a Gift voucher the account
// is reduced the order total amount.
//
   function apply_credit() {
     if (MODULE_ORDER_TOTAL_INSTALLED) {
       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
           $GLOBALS[$class]->apply_credit();
         }
       }
     }
   }
// Called in checkout process to clear session variables created by each credit class module.
//
   function clear_posts() {
     global $HTTP_POST_VARS,$HTTP_SESSION_VARS;
     if (MODULE_ORDER_TOTAL_INSTALLED) {
       reset($this->modules);
       while (list(, $value) = each($this->modules)) {
         $class = substr($value, 0, strrpos($value, '.'));
         if ( ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) ) {
           $post_var = 'c' . $GLOBALS[$class]->code;
            if (tep_session_is_registered($post_var)) tep_session_unregister($post_var);
         }
       }
     }
   }
// Called at various times. This function calulates the total value of the order that the
// credit will be appled aginst. This varies depending on whether the credit class applies
// to shipping & tax
//
   function get_order_total_main($class, $order_total) {
     global $credit, $order;
//      if ($GLOBALS[$class]->include_tax == 'false') $order_total=$order_total-$order->info['tax'];
//      if ($GLOBALS[$class]->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];
     return $order_total;
   }
// ############ End Added CCGV Contribution ##########
 }
?>

 

ot_coupon.php

<?php
/*
$Id: ot_coupon.php,v 1.1.2.38 2006/09/01 22:52:59 Strider Exp $
*/

class ot_coupon {
var $title, $output;

function ot_coupon() {

       $this->code = 'ot_coupon';
       $this->header = MODULE_ORDER_TOTAL_COUPON_HEADER;
       $this->title = MODULE_ORDER_TOTAL_COUPON_TITLE;
       $this->description = MODULE_ORDER_TOTAL_COUPON_DESCRIPTION;
       $this->user_prompt = '';
       $this->enabled = MODULE_ORDER_TOTAL_COUPON_STATUS;
       $this->sort_order = MODULE_ORDER_TOTAL_COUPON_SORT_ORDER;
       $this->include_shipping = MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING;
       $this->include_tax = MODULE_ORDER_TOTAL_COUPON_INC_TAX;
       $this->calculate_tax = MODULE_ORDER_TOTAL_COUPON_CALC_TAX;
       $this->tax_class = MODULE_ORDER_TOTAL_COUPON_TAX_CLASS;
       $this->credit_class = true;
       $this->output = array();

}

function process() {
global $PHP_SELF, $order, $currencies;


       $order_total=$this->get_order_total();
       $od_amount = $this->calculate_credit($order_total);
       $tod_amount = 0.0; //Fred
       $this->deduction = $od_amount;
       if ($this->calculate_tax != 'None') { //Fred - changed from 'none' to 'None'!
               $tod_amount = $this->calculate_tax_deduction($order_total, $this->deduction, $this->calculate_tax);
       }

       if ($od_amount > 0) {
               $order->info['total'] = $order->info['total'] - $od_amount;
               $this->output[] = array('title' => $this->title . ':' . $this->coupon_code .':','text' => '<b>-' . $currencies->format($od_amount) . '</b>', 'value' => $od_amount); //Fred added hyphen
       }
}

function selection_test() {
       return false;
}


function pre_confirmation_check($order_total) {
global $customer_id;
       return $this->calculate_credit($order_total);
}

function use_credit_amount() {
       return $output_string;
}


function credit_selection() {
global $customer_id, $currencies, $language;

// START Checkout Display Fix by BTBlomberg

	$selection_string = '<tr><td><img src="images/pixel_trans.gif" border="0" alt="" width="1" height="1"></td><td class="main">'; 
	$selection_string .= tep_draw_form('checkout_payment_gift', tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'), 'post');
	$selection_string .= '<div>';
	$selection_string .= TEXT_ENTER_GV_CODE . tep_draw_input_field('gv_redeem_code', TEXT_ENTER_COUPON_FIELD) ;
	$selection_string .= ' ';
	$selection_string .= tep_image_submit('button_redeem.gif', IMAGE_REDEEM_VOUCHER, 'ALIGN="middle" onclick="return submitFunction()"');
	$selection_string .= '</div></form></td></tr>';

// END Checkout Display Fix by BTBlomberg

return $selection_string;
}


function collect_posts() {
// All tep_redirect URL parameters modified for this function in v5.13 by Rigadin
global $HTTP_POST_VARS, $customer_id, $currencies, $cc_id;
       if ($HTTP_POST_VARS['gv_redeem_code']) {

// get some info from the coupon table
       $coupon_query=tep_db_query("select coupon_id, coupon_amount, coupon_type, coupon_minimum_order,uses_per_coupon, uses_per_user, restrict_to_products,restrict_to_categories from " . TABLE_COUPONS . " where coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."' and coupon_active='Y'");
       $coupon_result=tep_db_fetch_array($coupon_query);

       if ($coupon_result['coupon_type'] != 'G') {

               if (tep_db_num_rows($coupon_query)==0) {
                       tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_NO_INVALID_REDEEM_COUPON), 'SSL'));
               }

               $date_query=tep_db_query("select coupon_start_date from " . TABLE_COUPONS . " where coupon_start_date <= now() and coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'");

               if (tep_db_num_rows($date_query)==0) {
                       tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_STARTDATE_COUPON), 'SSL'));
               }

               $date_query=tep_db_query("select coupon_expire_date from " . TABLE_COUPONS . " where coupon_expire_date >= now() and coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'");

   if (tep_db_num_rows($date_query)==0) {
                       tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_FINISDATE_COUPON), 'SSL'));
               }

               $coupon_count = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id']."'");
               $coupon_count_customer = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id']."' and customer_id = '" . $customer_id . "'");

               if (tep_db_num_rows($coupon_count)>=$coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0) {
                       tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES ), 'SSL'));
               }

               if (tep_db_num_rows($coupon_count_customer)>=$coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0) {
                       tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES ), 'SSL'));
               }

//**si** 09-11-05
/*
               if ($coupon_result['coupon_type']=='S') {
                       $coupon_amount = $order->info['shipping_cost'];
               } else {
                       $coupon_amount = $currencies->format($coupon_result['coupon_amount']) . ' ';
               }
               if ($coupon_result['coupon_type']=='P') $coupon_amount = $coupon_result['coupon_amount'] . '% ';
               if ($coupon_result['coupon_minimum_order']>0) $coupon_amount .= 'on orders greater than ' . $coupon_result['coupon_minimum_order'];
               if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id'); //Fred - this was commented out before
               $cc_id = $coupon_result['coupon_id']; //Fred ADDED, set the global and session variable
               tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_REDEEMED_AMOUNT), 'SSL')); // Added in v5.13a by Rigadin
*/
               global $order,$ot_coupon,$currency;
// BEGIN >>> CCVG 5.15 - Custom Modification - fix Coupon code redemption error
// Moved code up a few lines
if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id');
$cc_id = $coupon_result['coupon_id'];
// END <<< CCVG 5.15 - Custom Modification - fix Coupon code redemption error

               $coupon_amount= tep_round($ot_coupon->pre_confirmation_check($order->info['subtotal']), $currencies->currencies[$currency]['decimal_places']); // $cc_id
/* you will need to uncomment this if your tax order total module is AFTER shipping eg you have all of your tax, including tax from shipping module, in your tax total.
               if ($coupon_result['coupon_type']=='S')  {
                       //if not zero rated add vat to shipping
                       $coupon_amount = tep_add_tax($coupon_amount, '17.5');
               }
*/
               $coupon_amount_out = $currencies->format($coupon_amount) . ' ';
               if ($coupon_result['coupon_minimum_order']>0) $coupon_amount_out .= 'on orders greater than ' . $currencies->format($coupon_result['coupon_minimum_order']);

               if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id');
               $cc_id = $coupon_result['coupon_id'];

               if ( strlen($cc_id)>0 && $coupon_amount==0 ) {
                       $err_msg = ERROR_REDEEMED_AMOUNT.ERROR_REDEEMED_AMOUNT_ZERO;
               } else {
                       $err_msg = ERROR_REDEEMED_AMOUNT.$coupon_amount_out;
               }
               tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode($err_msg), 'SSL'));
//**si** 09-11-05 end

               // $_SESSION['cc_id'] = $coupon_result['coupon_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
         } // ENDIF valid coupon code
       } // ENDIF code entered 
       // v5.13a If no code entered and coupon redeem button pressed, give an alarm
       if ($HTTP_POST_VARS['submit_redeem_coupon_x']) tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_NO_REDEEM_CODE), 'SSL'));
}

function calculate_credit($amount) {
global $customer_id, $order, $cc_id;
//$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
       $od_amount = 0;
       if (isset($cc_id) ) {
               $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");
               if (tep_db_num_rows($coupon_query) !=0 ) {
                       $coupon_result = tep_db_fetch_array($coupon_query);
                       $this->coupon_code = $coupon_result['coupon_code'];
                       $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS ." where coupon_code = '". $coupon_result['coupon_code'] . "'");
                       $get_result = tep_db_fetch_array($coupon_get);
                       $c_deduct = $get_result['coupon_amount'];




// Calcul de l'affichage du coupon
                       if ($get_result['coupon_type']=='S') $c_deduct = $order->info['shipping_cost'];
//Calcul du coupon si celui ci est > 0 avec les frais d'envoie
                       if ($get_result['coupon_type']=='S' && $get_result['coupon_amount'] > 0 ) $c_deduct = $order->info['shipping_cost'] + $get_result['coupon_amount'];





                       if ($get_result['coupon_minimum_order'] <= $this->get_order_total()) {
                               if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {
                                       for ($i=0; $i<sizeof($order->products); $i++) {
                                               if ($get_result['restrict_to_products']) {
                                                       $pr_ids = split("[,]", $get_result['restrict_to_products']);
                                                       for ($ii = 0; $ii < count($pr_ids); $ii++) {
                                                               if ($pr_ids[$ii] == tep_get_prid($order->products[$i]['id'])) {
                                                                       if ($get_result['coupon_type'] == 'P') {
                                                                                       /* Fixes to Gift Voucher module 5.03
                                                                                       =================================
                                                                                       Submitted by Rob Cote, robc@traininghott.com

                                                                                       original code: $od_amount = round($amount*10)/10*$c_deduct/100;
                                                                                       $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
                                                                                       $pod_amount = round($pr_c*10)/10*$c_deduct/100;
                                                                                       */
                                                                                       //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
                                                                                       $pr_c = ($order->products[$i]['final_price'] * $order->products[$i]['qty']);

                                                                                       $pod_amount = round($pr_c*10)/10*$c_deduct/100;
                                                                                       $od_amount = $od_amount + $pod_amount;
                                                                               } else {
                                                                                       $od_amount = $c_deduct;
                                                                               }
                                                                       }
                                                               }
                                                       } else {
                                                               $cat_ids = split("[,]", $get_result['restrict_to_categories']);
                                                               for ($i=0; $i<sizeof($order->products); $i++) {
                                                                       $my_path = tep_get_product_path(tep_get_prid($order->products[$i]['id']));
                                                                       $sub_cat_ids = split("[_]", $my_path);
                                                                       for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {
                                                                               for ($ii = 0; $ii < count($cat_ids); $ii++) {
                                                                                       if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {
                                                                                               if ($get_result['coupon_type'] == 'P') {
                                                                                                       /* Category Restriction Fix to Gift Voucher module 5.04
                                                                                                       Date: August 3, 2003
                                                                                                       =================================
                                                                                                       Nick Stanko of UkiDev.com, nick@ukidev.com

                                                                                                       original code:
                                                                                                       $od_amount = round($amount*10)/10*$c_deduct/100;
                                                                                                       $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
                                                                                                       $pod_amount = round($pr_c*10)/10*$c_deduct/100;
                                                                                                       */
                                                                                                       //$od_amount = round($amount*10)/10*$c_deduct/100;
                                                                                                       //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
                                                                                                       $pr_c = $this->product_price(tep_get_prid($order->products[$i]['id'])); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!
                                                                                                       $pod_amount = round($pr_c*10)/10*$c_deduct/100;
                                                                                                       $od_amount = $od_amount + $pod_amount;
                                                   continue 3;      // v5.13a Tanaka 2005-4-30: to prevent double counting of a product discount
                                               } else {
                                                   $od_amount = $c_deduct;
                                                   continue 3;      // Tanaka 2005-4-30: to prevent double counting of a product discount
                                                                                               }
                                                                                       }
                                                                               }
                                                                       }
                                                               }
                                                       }
                                               }
                                       } else {
                                               if ($get_result['coupon_type'] !='P') {
                                                       $od_amount = $c_deduct;
                                               } else {
                                                       $od_amount = $amount * $get_result['coupon_amount'] / 100;
                                               }
                                       }
                               }
                       }
               if ($od_amount>$amount) $od_amount = $amount;
               }
       return tep_round($od_amount,2);
}

function calculate_tax_deduction($amount, $od_amount, $method) {
global $customer_id, $order, $cc_id, $cart;
//$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
       $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");
       if (tep_db_num_rows($coupon_query) !=0 ) {
               $coupon_result = tep_db_fetch_array($coupon_query);
               $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code = '". $coupon_result['coupon_code'] . "'");
               $get_result = tep_db_fetch_array($coupon_get);
               if ($get_result['coupon_type'] != 'S') {

                       //RESTRICTION--------------------------------
                       if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {
                               // What to do here.
                               // Loop through all products and build a list of all product_ids, price, tax class
                               // at the same time create total net amount.
                               // then
                               // for percentage discounts. simply reduce tax group per product by discount percentage
                               // or
                               // for fixed payment amount
                               // calculate ratio based on total net
                               // for each product reduce tax group per product by ratio amount.
                               $products = $cart->get_products();
                               $valid_product = false;
                               for ($i=0; $i<sizeof($products); $i++) {
                               $valid_product = false;
                                       $t_prid = tep_get_prid($products[$i]['id']);
                                       $cc_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
                                       $cc_result = tep_db_fetch_array($cc_query);
                                       if ($get_result['restrict_to_products']) {
                                               $pr_ids = split("[,]", $get_result['restrict_to_products']);
                                               for ($p = 0; $p < sizeof($pr_ids); $p++) {
                                                       if ($pr_ids[$p] == $t_prid) $valid_product = true;
                                               }
                                       }
                                       if ($get_result['restrict_to_categories']) {
                       // Tanaka 2005-4-30:  Original Code
                       /*$cat_ids = split("[,]", $get_result['restrict_to_categories']);
                       for ($c = 0; $c < sizeof($cat_ids); $c++) {
                           // Tanaka 2005-4-30:  changed $products_id to $t_prid and changed $i to $c
                           $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $t_prid . "' and categories_id = '" . $cat_ids[$c] . "'");
                           if (tep_db_num_rows($cat_query) !=0 ) $valid_product = true;
                       }*/
                       // v5.13a Tanaka 2005-4-30:  New code, this correctly identifies valid products in subcategories
                       $cat_ids = split("[,]", $get_result['restrict_to_categories']);
                       $my_path = tep_get_product_path($t_prid);
                       $sub_cat_ids = split("[_]", $my_path);
                       for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {
                           for ($ii = 0; $ii < count($cat_ids); $ii++) {
                               if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {
                                   $valid_product = true;
                                   continue 2;
                               }
                           }
                       }
                                       }
                                       if ($valid_product) {
                                               $price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity']; //Fred - added
                                               $price_incl_vat = $this->product_price($t_prid); //Fred - added
                                               $valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']); //jason //Fred - changed from $products[$i]['final_price'] 'products_tax_class' => $cc_result['products_tax_class_id']);
//                                                $total_price += $price_incl_vat; //Fred - changed
                                               $total_price += $price_excl_vat; // changed
                                       }
                               }
                               if (sizeof($valid_array) > 0) { // if ($valid_product) {
                                       if ($get_result['coupon_type'] == 'P') {
                                               $ratio = $get_result['coupon_amount']/100;
                                       } else {
                                               $ratio = $od_amount / $total_price;
                                       }
                                       if ($get_result['coupon_type'] == 'S') $ratio = 1;
                                       if ($method=='Credit Note') {
                                               $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                                               $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                                               if ($get_result['coupon_type'] == 'P') {
                                                       $tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate;
                                               } else {
                                                       $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100;
                                               }
                                               $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                                               $order->info['total'] -= $tod_amount; //  need to modify total ...OLD
                                               $order->info['tax'] -= $tod_amount; //Fred - added
                                       } else {
                                               for ($p=0; $p<sizeof($valid_array); $p++) {
                                                       $tax_rate = tep_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
                                                       $tax_desc = tep_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
                                                       if ($tax_rate > 0) {
                                                               //Fred $tod_amount[$tax_desc] += ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; //OLD
                                                               $tod_amount = ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // calc total tax Fred - added
                                                               $order->info['tax_groups'][$tax_desc] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio;
                                                               $order->info['total'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust total
                                                               $order->info['tax'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust tax -- Fred - added
                                                       }
                                               }
                                       }
                               }
                               //NO RESTRICTION--------------------------------
                       } else {
                               if ($get_result['coupon_type'] =='F') {
                                       $tod_amount = 0;
                                       if ($method=='Credit Note') {
                                               $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                                               $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                                               $tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate;
                                               $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                                       } else {
//                                                $ratio1 = $od_amount/$amount;   // this produces the wrong ratipo on fixed amounts
                                               reset($order->info['tax_groups']);
                                               while (list($key, $value) = each($order->info['tax_groups'])) {
                                                       $ratio1 = $od_amount/($amount-$order->info['tax_groups'][$key]); ////debug
                                                       $tax_rate = tep_get_tax_rate_from_desc($key);
                                                       $net = $tax_rate * $order->info['tax_groups'][$key];
                                                       if ($net>0) {
                                                               $god_amount = $order->info['tax_groups'][$key] * $ratio1;
                                                               $tod_amount += $god_amount;
                                                               $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                                                       }
                                               }
                                       }
                                       $order->info['total'] -= $tod_amount; //OLD
                                       $order->info['tax'] -= $tod_amount; //Fred - added
                       }
                       if ($get_result['coupon_type'] =='P') {
                               $tod_amount=0;
                               if ($method=='Credit Note') {
                                       $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                                       $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100;
                                       $order->info['tax_groups'][$tax_desc] -= $tod_amount;
                               } else {
                                       reset($order->info['tax_groups']);
                                       while (list($key, $value) = each($order->info['tax_groups'])) {
                                               $god_amount=0;
                                               $tax_rate = tep_get_tax_rate_from_desc($key);
                                               $net = $tax_rate * $order->info['tax_groups'][$key];
                                               if ($net>0) {
                                                       $god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount']/100;
                                                       $tod_amount += $god_amount;
                                                       $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
                                               }
                                       }
                               }
                               $order->info['total'] -= $tod_amount; // have to modify total also
                               $order->info['tax'] -= $tod_amount;
                       }
               }
       }
}
return $tod_amount;
}

function update_credit_account($i) {
       return false;
}

function apply_credit() {
global $insert_id, $customer_id, $REMOTE_ADDR, $cc_id;
       //$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
       if ($this->deduction !=0) {
               tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, redeem_date, redeem_ip, customer_id, order_id) values ('" . $cc_id . "', now(), '" . $REMOTE_ADDR . "', '" . $customer_id . "', '" . $insert_id . "')");
       }
       tep_session_unregister('cc_id');
}

function get_order_total() {
global $order, $cart, $customer_id, $cc_id;
       //$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
       $order_total = $order->info['total'];
       // Check if gift voucher is in cart and adjust total
       $products = $cart->get_products();
       for ($i=0; $i<sizeof($products); $i++) {
               $t_prid = tep_get_prid($products[$i]['id']);
               $gv_query = tep_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
               $gv_result = tep_db_fetch_array($gv_query);
               if (ereg('^GIFT', addslashes($gv_result['products_model']))) {
                       $qty = $cart->get_quantity($t_prid);
                       $products_tax = tep_get_tax_rate($gv_result['products_tax_class_id']);
                       if ($this->include_tax =='false') {
                               $gv_amount = $gv_result['products_price'] * $qty;
                       } else {
                               $gv_amount = ($gv_result['products_price'] + tep_calculate_tax($gv_result['products_price'],$products_tax)) * $qty;
                       }
                       $order_total=$order_total - $gv_amount;
               }
       }
       if ($this->include_tax == 'false') $order_total=$order_total-$order->info['tax'];
       if ($this->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];
       // OK thats fine for global coupons but what about restricted coupons
       // where you can only redeem against certain products/categories.
       // and I though this was going to be easy !!!
       $coupon_query=tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id='".$cc_id."'");
       if (tep_db_num_rows($coupon_query) !=0) {
               $coupon_result=tep_db_fetch_array($coupon_query);
               $coupon_get=tep_db_query("select coupon_amount, coupon_minimum_order,restrict_to_products,restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code='".$coupon_result['coupon_code']."'");
               $get_result=tep_db_fetch_array($coupon_get);
               $in_cat = true;
               if ($get_result['restrict_to_categories']) {
                       $cat_ids = split("[,]", $get_result['restrict_to_categories']);
                       $in_cat=false;
                       for ($i = 0; $i < count($cat_ids); $i++) {
                               if (is_array($this->contents)) {
                                       reset($this->contents);
                                       while (list($products_id, ) = each($this->contents)) {
                                               $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $products_id . "' and categories_id = '" . $cat_ids[$i] . "'");
                                               if (tep_db_num_rows($cat_query) !=0 ) {
                                                       $in_cat = true;
                                                       $total_price += $this->get_product_price($products_id);
                                               }
                                       }
                               }
                       }
               }
               $in_cart = true;
               if ($get_result['restrict_to_products']) {

                       $pr_ids = split("[,]", $get_result['restrict_to_products']);

                       $in_cart=false;
                       $products_array = $cart->get_products();

                       for ($i = 0; $i < sizeof($pr_ids); $i++) {
                               for ($ii = 1; $ii<=sizeof($products_array); $ii++) {
                                       if (tep_get_prid($products_array[$ii-1]['id']) == $pr_ids[$i]) {
                                               $in_cart=true;
                                               $total_price += $this->get_product_price($products_array[$ii-1]['id']);
                                       }
                               }
                       }
                       $order_total = $total_price;
               }
       }
return $order_total;
}

function get_product_price($product_id) {
global $cart, $order;
       $products_id = tep_get_prid($product_id);
       // products price
       $qty = $cart->contents[$product_id]['qty'];
       $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");
       if ($product = tep_db_fetch_array($product_query)) {
               $prid = $product['products_id'];
               $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
               $products_price = $product['products_price'];
               $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
               if (tep_db_num_rows ($specials_query)) {
                       $specials = tep_db_fetch_array($specials_query);
                       $products_price = $specials['specials_new_products_price'];
               }
               if ($this->include_tax == 'true') {
                       $total_price += ($products_price + tep_calculate_tax($products_price, $products_tax)) * $qty;
//                        echo("total price = " . $total_price . " products_price = " . $products_price . " products_tax = " . $products_tax . "<br>");

               } else {
                       $total_price += $products_price * $qty;
               }

               // attributes price
               if (isset($cart->contents[$product_id]['attributes'])) {
                       reset($cart->contents[$product_id]['attributes']);
                       while (list($option, $value) = each($cart->contents[$product_id]['attributes'])) {
                               $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'");
                               $attribute_price = tep_db_fetch_array($attribute_price_query);
                               if ($attribute_price['price_prefix'] == '+') {
                                       if ($this->include_tax == 'true') {
                                               $total_price += $qty * ($attribute_price['options_values_price'] + tep_calculate_tax($attribute_price['options_values_price'], $products_tax));
                                       } else {
                                               $total_price += $qty * ($attribute_price['options_values_price']);
                                       }
                               } else {
                                       if ($this->include_tax == 'true') {
                                               $total_price -= $qty * ($attribute_price['options_values_price'] + tep_calculate_tax($attribute_price['options_values_price'], $products_tax));
                                       } else {
                                               $total_price -= $qty * ($attribute_price['options_values_price']);
                                       }
                               }
                       }
               }
       }
       if ($this->include_shipping == 'true') {

               $total_price += $order->info['shipping_cost'];
       }
       return $total_price;
}

//Added by Fred -- BOF -----------------------------------------------------
//JUST RETURN THE PRODUCT PRICE (INCL ATTRIBUTE PRICES) WITH OR WITHOUT TAX
function product_price($product_id) {
       $total_price = $this->get_product_price($product_id);
       if ($this->include_shipping == 'true') $total_price -= $order->info['shipping_cost'];
       return $total_price;
}
//Added by Fred -- EOF -----------------------------------------------------

// START added by Rigadin in v5.13, needed to show module errors on checkout_payment page
   function get_error() {
     global $HTTP_GET_VARS;

     $error = array('title' => MODULE_ORDER_TOTAL_COUPON_TEXT_ERROR,
                    'error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));

     return $error;
   }
// END added by Rigadin        

function check() {
       if (!isset($this->check)) {
               $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_COUPON_STATUS'");
               $this->check = tep_db_num_rows($check_query);
       }

       return $this->check;
}

function keys() {
       return array('MODULE_ORDER_TOTAL_COUPON_STATUS', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS');
}

function install() {
       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Total', 'MODULE_ORDER_TOTAL_COUPON_STATUS', 'true', 'Do you want to display the Discount Coupon value?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', '9', 'Sort order of display.', '6', '2', now())");
       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'true', 'Include Shipping in calculation', '6', '5', 'tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'true', 'Include Tax in calculation.', '6', '6','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Re-calculate Tax', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'None', 'Re-Calculate Tax', '6', '7','tep_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())");
       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS', '0', 'Use the following tax class when treating Discount Coupon as Credit Note.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
}

function remove() {
       $keys = '';
       $keys_array = $this->keys();
       for ($i=0; $i<sizeof($keys_array); $i++) {
               $keys .= "'" . $keys_array[$i] . "',";
       }
       $keys = substr($keys, 0, -1);

       tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
       }
}
?>

Share this post


Link to post
Share on other sites

I have a big problem with the code for a few of the files that need to be modified

 

My main problem is:

 

include/boxes/shopping_cart.php

 

This is ALL the code i have in it,

<?php
/*
 $Id: shopping_cart.php,v 1.18 2003/02/10 22:31:06 hpdl Exp $

E-Commerce Solutions


 Released under the GNU General Public License
*/
?>
<!-- shopping_cart //-->
	 <b>Shopping cart:</b> Now in your cart <?php  echo sizeof($products = $cart->get_products()).' items'; ?>
<!-- shopping_cart_eof //-->

 

And the install instruction there is a lot of changing in the shopping_cart.php and you can't really skip all this code becouse than i get planty of erorrs

My site is http://www.c-square-d.com

 

Thanks in advance for the help!

yossi

Share this post


Link to post
Share on other sites
Guest

Yossi,

 

Did you modify the shopping_cart.php file with another contribution already? It looks like it. The one that comes right out of the standard osCommerce download has much more code than this.

 

What errors are you getting? I believe the shopping_cart.php file you currently have implemented just puts a caption at the top of your the page that says "Shopping cart: Now in your cart X items". I checked your site and it appears to be working just fine.

 

If you are trying to modify the file and get errors, it could be because the new "shopping_cart.php" file once you implement CCGV also shows gift voucher balances on the account. You should consider grabbing the current shopping_cart.php from the osCommerce download page, then upgrading it with this contribution, and trying that out.

 

Let me know if that works.

 

Cheers,

-Earl

 

I have a big problem with the code for a few of the files that need to be modified

 

My main problem is:

 

include/boxes/shopping_cart.php

 

This is ALL the code i have in it,

<?php
/*
 $Id: shopping_cart.php,v 1.18 2003/02/10 22:31:06 hpdl Exp $

E-Commerce Solutions
 Released under the GNU General Public License
*/
?>
<!-- shopping_cart //-->
	 <b>Shopping cart:</b> Now in your cart <?php  echo sizeof($products = $cart->get_products()).' items'; ?>
<!-- shopping_cart_eof //-->

 

And the install instruction there is a lot of changing in the shopping_cart.php and you can't really skip all this code becouse than i get planty of erorrs

My site is http://www.c-square-d.com

 

Thanks in advance for the help!

yossi

Share this post


Link to post
Share on other sites

I still have the problem. what about you?

 

Best Regards

Kent Larsen

 

Hi.

 

I have have the same problem as you, have you find a soulution yet?

 

/David

Share this post


Link to post
Share on other sites
Yossi,

 

Did you modify the shopping_cart.php file with another contribution already? It looks like it. The one that comes right out of the standard osCommerce download has much more code than this.

 

What errors are you getting? I believe the shopping_cart.php file you currently have implemented just puts a caption at the top of your the page that says "Shopping cart: Now in your cart X items". I checked your site and it appears to be working just fine.

 

If you are trying to modify the file and get errors, it could be because the new "shopping_cart.php" file once you implement CCGV also shows gift voucher balances on the account. You should consider grabbing the current shopping_cart.php from the osCommerce download page, then upgrading it with this contribution, and trying that out.

 

Let me know if that works.

 

Cheers,

-Earl

 

 

Thanks for the advice,

However if i'll put the regular os commerce shopping cart it will mess up my whole site desgin,

and i'm not much of a designer, this is a tamplet with a little changes,

I was wondering if there is a way around it, like cancel out the whole addtion to the shopping cart...

Share this post


Link to post
Share on other sites
Guest
I still have the problem. what about you?

 

Best Regards

Kent Larsen

Hi Kent

 

Are you sure that your configure.php files are correct?

Share this post


Link to post
Share on other sites

I am using this mod and everything was working well except a customer used a gift voucher but it never deducted from the order or their account.

Nor does it show up as payment on the invoice.

 

So it still shows the full credit on their account after the order.

 

This happened 2 times now right in a row.

 

Nothing has been changed or added since this was working correctly.

 

I tried using this option myself and eveything works fine.

 

Does anyone have any suggestion or areas I can check to trouble shoot this?

 

Any help is apprecieted.


_________________________________________________________________________

 

David G Aschenbrener

Tranquil | Sense - Your Stop for Tranquility.

Share this post


Link to post
Share on other sites
Guest

You must make this modification in order to enable your customers to Send gift vouchers to other people, and see their gift voucher balances. So, I think your choices are 1) modify the shopping_cart.php file completely like the contribution requires, or 2) do not implement the contribution at all. :) Or, there might be a 3rd choice, which would be to have a programmer write some code to split your shopping_cart.php code into two parts, one which displays at the top like you have it, and the other piece would display elsewhere on the page.

 

That would be way over my head, though. :)

 

Thanks for the advice,

However if i'll put the regular os commerce shopping cart it will mess up my whole site desgin,

and i'm not much of a designer, this is a tamplet with a little changes,

I was wondering if there is a way around it, like cancel out the whole addtion to the shopping cart...

Share this post


Link to post
Share on other sites

hi, i just installed succesfully the 5.19 on my site expected that i noticed in the ot_coupon file that there is a new form created in the function credit_selection() around line 64 :

==> $selection_string .= tep_draw_form('checkout_payment_gift', tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'), 'post');

==> $selection_string .= '</form></tr>';

 

This implies to have on the checkout_payment page the gift voucher box on top of the payment choice otherwise (if it's below) it doesn't work because then this form get into the other one and bug.

 

Previously there was only one form for this two functions, i tried to just delete the line 64 and delete </form> but it doesn't work.

Does anyone knows how to solve this problem in order two have only one form for the checkout_payment page instead of two ?

 

Thanks

Share this post


Link to post
Share on other sites
Re: the total is not calculated correctly

 

Hello,

 

I have read this entire thread and could not find answers to this problem. I have installed this contribution correctly and have tried various sort orders for the Order Total but it seems that it cannot correctly calculate the order totals. I am using the Canadian Tax contribution but when a flat rate shipping is setup, it messes up the totals.

 

Here is what I get when I try to check out:

 

Item Price: $99.50

Discount Coupons: 15% discount: -$14.93

Sub-Total: $99.50

GST ( 6% ): $5.97

PST ( 7.5% ): $7.91

Flat Rate for Zone 1 (Best Way): $10.00

Total: $109.10

 

Now here are two issues: 1. The taxes are calculated on the original amount not the discounted price and 2. The final total is incorrect with or without taxes being calculated on original or discounted price

 

What we SHOULD ideally get is the following:

1. Taxes are calculated based on Original Price

Item Price: $99.50

Discount Coupons: 15% : -$14.93

Sub-Total: $84.58 <<<< needs to show correct subtotal

GST ( 6% ): $5.97 <<<< even if you leave the taxes as is the final total is incorrect

PST ( 7.5% ): $7.91

Flat Rate for Zone 1 (Best Way): $10.00

Total: $108.46 <<<<< Adding the above figures should equal 108.45 NOT 109.10

 

2.Taxes are calculated on Discounted price

Item Price: $99.50

Discount Coupons: 15% : -$14.93

Sub-Total: $84.58

GST ( 6% ): $5.07

PST ( 7.5% ): $6.72 <<<< PST = 7.5% of the total of GST + subtotal

Flat Rate for Zone 1 (Best Way): $10.00

Total: $106.37

 

In either case, the total is much different from what the osc currently calculates. Any help would be much appreciated.

 

Thanks.

 

Hi Hooman, I'm in BC. We just installed this, too, only are having an even greater problem..... the shopping cart itself has disappeared. Anyway, to your post:

 

With gift certficates, according to CCRA, tax is always calculated on the original price, not the discounted price. The extra few cents that are appearing is because it is charging extra GST on that gift certificate. So your tax zones aren't right, perhaps. You should just have two tax zones, one for your home province that is just for provincial sales tax, and one for GST (not HST!) that is for home province and all other provinces.

 

Hope that helps.

Edited by milo90

Share this post


Link to post
Share on other sites
I have a test site up and running with CCGV(5.19) and I'm almost ready to launch. But, I can not get Gift Vouchers to redeem. I can send them, accept them, transfer them. But, during checkout, I cannot apply them as payment for the cart.

 

I've tried $100 voucher for $15 product, $15 voucher for $100 product, and $15 voucher for $15 product. No matter what I do, the voucher does not apply.

 

No matter what I do, when I get to checkout_payment, the Gift Vouchers & Coupons section displays with the Redeem button, but the Redeem button is DEAD. Can anyone take a look and let me know what would possibly cause such a thing?

 

Site: http://www.partofthemusic.com/ovmc_cart/catalog/

Account: "test1@msn.com" is ID

Password: "test1" is password

 

This is NOT a live store, so it's perfectly okay to put stuff in the cart, attempt checkout, etc.

 

I have installed other major contributions: STS, Multi-Store Multiple Shops.

 

I appreciate your help!

 

Cheers,

-Earl

 

PS - If you want to help and would like some code, let me know what would be helpful. For starters, here is my checkout_payment.php file:

Has this problem been solved yet? I have the same problem.

Anyone know the answer?

Share this post


Link to post
Share on other sites

I could not find Gift Voucher or Discount Coupons options under Admin/Modules/Order Total.

 

Only Shows

Low Order Fee

Shipping 2

Sub-Total 1

Tax 3

Total

 

Am I missing something?

Share this post


Link to post
Share on other sites

Thanks to msasek,

 

after reading his previous post.

 

I didnt upload ot_coupon.php and ot_gv.php on /catalog/includes/modules/order_total.

 

My bad.

Share this post


Link to post
Share on other sites
Guest

I've tried searching this support thread with no luck.

 

I have a virtual mall with osc shop side using phpnuke as a portal to the stores so only 1 database is used and customers need only join 1 store (or just the portal) and their details are carried throughout.

 

My query is this: As the individual store in this virtual mall has a prefix (to determine where the item was purchased from so the payment can go to the correct store and also so that every store has different items) how do I apply this to the sql file?

 

Any help on this would be greatly appreciated as the forums at phpnuke multistores take, on average, 3 months to answer any queries (even though you can tell their forums are searched on a regular basis)!!!!! (w00t)

Share this post


Link to post
Share on other sites

I have this problem in my checkout process:

 

when people click on the redeem button in checkout_payment.php it checks if the visa is valid and it goes through to the next page in the checkout process - checkout_confirmation.php .

how can I have it so when I click on the redeem button it keeps the customer on the checkout_payment.php page, and just applies the coupon?

 

thank you,

asasson

Share this post


Link to post
Share on other sites

Hi,

I am on this stage of post install instructions:

 

Go to ADMIN / module.php option

Select “Payment ”

Install “Credit Class Error”

 

But in payment - credit class error is not there. EVERYTHING else works, just not this, and I have no idea what I have missed for the option to not be there! Any help would be great!

:)

Share this post


Link to post
Share on other sites
Hi,

I am on this stage of post install instructions:

 

Go to ADMIN / module.php option

Select “Payment ”

Install “Credit Class Error”

 

But in payment - credit class error is not there. EVERYTHING else works, just not this, and I have no idea what I have missed for the option to not be there! Any help would be great!

:)

 

okay i fixed that. but how the heck do customers buy gift vouchers? I can't find the link or file anywhere???? :blink:

What option is it under in admin? What code am i missing??

 

Thanks

Share this post


Link to post
Share on other sites

Redeem button going to checkout_confirmation.php

 

how can i have the order-total function in includes/classes/orders.php after checking the coupon code to go back to the payment page?

 

cheers!

Share this post


Link to post
Share on other sites

Hi I just installed the shop seems to work fine but when I try to check out there is a problem, I can't choose continue the link i simply not there and I try to redeem af giftvoucher I get the following error: Parse error: syntax error, unexpected $end in xxxxxxxxxx/catalog/checkout_confirmation.php on line 399 But when I just can't see any sign og the problem since the $end dosn't exist any where in the document and the content og that line is

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

 

The last line here is line 399 in the file så I also tried looking ind the application bottom file and there's no $end anywhere in that either

 

Can someone help me solve this? I have 5 or 6 contributions installed the only one that involved the checkout_confirmation is PWA does anyone know if that is a problem?

 

 

Kennith

Share this post


Link to post
Share on other sites
Guest

I am going crazy with the following problem:

A test customer (me) bought from my store a gift voucher, the product model is called Gift_50, it is located under the Gift Certificate Category. Once the transaction was completed I edited the order status to delivered, however, the Certificate didn't appear anywhere. I read that I have to release it manually. However it doen't show up anywhere so, do I have to do something before if not where do I have to do the releasing?

 

I created, in the Admin section, a Voucher for the same amount and tried to send it to the test customer, it never showed up in his account (it is probably not supposed to), he can, however, redeem it when placing an order but what happens with the balance if it is not entirely used up?.

 

Could someone please take me through the process?

 

What is the purpose of the Gift Voucher Queue?

 

I have searched and read all the posts regarding this issue going back 3 years and I can't find any solution (did I miss something). I can't seem to locate the file how_to_use_GV.zip so I am relying on someone's help.

 

You can check my site here: www.inpregna.com

 

I am running CreLoaded 6.2 and believe CCGV's installation was done properly however I have no idea which version I am running.

I have verified the settings:

Credit Class Erro has been installed in admin/module

Sort orders have been correctly set

Share this post


Link to post
Share on other sites
Guest

I am going crazy with the following problem:

A test customer (me) bought from my store a gift voucher, the product model is called Gift_50, it is located under the Gift Certificate Category. Once the transaction was completed I edited the order status to delivered, however, the Certificate didn't appear anywhere. I read that I have to release it manually. However it doen't show up anywhere so, do I have to do something before if not where do I have to do the releasing?

 

I created, in the Admin section, a Voucher for the same amount and tried to send it to the test customer, it never showed up in his account (it is probably not supposed to), he can, however, redeem it when placing an order but what happens with the balance if it is not entirely used up?.

 

Could someone please take me through the process?

 

What is the purpose of the Gift Voucher Queue?

 

I have searched and read all the posts regarding this issue going back 3 years and I can't find any solution (did I miss something). I can't seem to locate the file how_to_use_GV.zip so I am relying on someone's help.

 

You can check my site here: www.inpregna.com

 

I am running CreLoaded 6.2 and believe CCGV's installation was done properly however I have no idea which version I am running.

I have verified the settings:

Credit Class Erro has been installed in admin/module

Sort orders have been correctly set

Share this post


Link to post
Share on other sites

Hello,

 

I have just installed this mod to my site which also has STS. The problem I am having is that the Send Gift Voucher Page link is not showing up in the shopping cart box. Would this have something to do with STS? Btw, I also have Order Editor installed.

 

Thanks!

Share this post


Link to post
Share on other sites

This is a dumb question, but I can't find a summary of what all this module provides. Even the contrib section only has this small one line about it "The base credit class and the Gift Voucher module in one package."

 

Now, I understand the Gift Vouchers, which I assume allows you to purchase a gift certificate during checkout to give to someone, but can someone explain a few more of the details of the Discount Coupons and the Credit Class?

 

ie: What all does the Discount Coupons allow you to provide discount on? Is it just a code such as "May5off" then it would give 5% or $5 off, by my choosing % or $? Or can I be much more selective and say put in code "May5off" and you get 5% off but have the ability to exempt certain shopping cart items?

 

What about the Credit Class? Does that allow me to offer free shipping on orders over "X" Dollars? Again, would I be able to exempt certain items that may have a heavy weight?

 

Thanks!

Share this post


Link to post
Share on other sites
Has this problem been solved yet? I have the same problem.

Anyone know the answer?

 

i have the same problem now. Anyone know the answer? please tell me

Share this post


Link to post
Share on other sites

Hi all,

 

I'm currently running POINTS AND REWARDS MODULE V2.0d ... and i am wondering if i can run Credit Class & Gift Voucher contribution with POINTS AND REWARDS MODULE V2.0d. Becuase i need a coupon system. Are there any conflict in between the two? Thank You!

Edited by akunamachata

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×