zencart 购物车页面添加折扣码功能

<script type="text/javascript">

function getXMLRequester() {
	var xmlhttp_request = false;
	try {
		if (window.ActiveXObject) {
			for ( var i = 5; i; i--) {
				try {
					if (i == 2) {
						xmlhttp_request = new ActiveXObject("Microsoft.XMLHTTP");
					} else {
						xmlhttp_request = new ActiveXObject("Msxml2.XMLHTTP."+ i + ".0");
						xmlhttp_request.setRequestHeader("Content-Type","text/xml");
						xmlhttp_request.setRequestHeader("Content-Type", "utf8");
					}
					break;
				} catch (e) {
					xmlhttp_request = false;
				}
			}
		} else if (window.XMLHttpRequest) {
			xmlhttp_request = new XMLHttpRequest();
			if (xmlhttp_request.overrideMimeType) {
				xmlhttp_request.overrideMimeType('text/xml');
			}
		}
	} catch (e) {
		xmlhttp_request = false;
	}
	return xmlhttp_request;
}

function SetCoupon(){
    var xmlhttp=getXMLRequester();
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4) {
            if(xmlhttp.status==200){
                location.href=location.href;
            }
        }   
       
    };
    xmlhttp.open('POST', location.href, true);
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttp.send('dc_redeem_code='+$("#disc-ot_coupon").val());
}

</script>
<input type="text" id="disc-ot_coupon" name="dc_redeem_code">
    <button type="button" title="Apply Coupon" value="Apply Coupon" id="PostCoupon" onclick="SetCoupon()">
	<span><span>Apply Coupon</span></span>
	</button>

<?php
  if (MODULE_ORDER_TOTAL_INSTALLED) {
    $order_totals = $order_total_modules->process();
    if(!empty($GLOBALS['ot_coupon']->output[0]['text'])){
?>
<tr>
<td width="760" height="22" align="right">
<b style="font-size:12px;padding-right:42px;">
<?php 
echo $GLOBALS['ot_coupon']->output[0]['title'].$GLOBALS['ot_coupon']->output[0]['text']?>
</b>
</td></tr>
<tr>
<td width="760" height="22" align="right">
<b style="font-size:12px;padding-right:42px;">
<?php 
echo $GLOBALS['ot_total']->output[0]['title'].$GLOBALS['ot_total']->output[0]['text']?>
</b>
</td>
</tr>
<?php }}?>

  当然,还缺少段代码

在header_php.php 文件中添加如下代码

require(DIR_WS_CLASSES . 'order.php');
$order = new order;
require(DIR_WS_CLASSES . 'order_total.php');
$order_total_modules = new order_total;
$order_total_modules->collect_posts();
$order_total_modules->pre_confirmation_check();

你可能感兴趣的:(zencart,购物车页面添加折扣码功能)