Coupons

Problems installing or using the NOP Design Free Shopping Cart that do not fit into one of the above categories.

Moderators: Koibito, Stefko, Randy

Coupons

Postby nuchie1 » Fri Jun 11, 2010 12:40 pm

I added this simple code to my page and the entire code shows up on the page view. I am using Best Address HTML editor.

//--------------------------------------------------------------------||
// "Simple Coupon Codes" mod by Gene Eilebrecht (Goldentree) ||
//--------------------------------------------------------------------||
// Function: addCoupon ||
// PARAMETERS: Form Object, Text Box ||
// RETURNS: Cookie to user's browser, with prompt ||
// PURPOSE: Tests for valid coupon code. If valid, adds to cart. ||
// EXTRAS ADDED IN: MUST HAVE "LIMIT" MOD TO WORK ||
//--------------------------------------------------------------------||
function addCoupon(form,coupon){

var strTotal = ""; //Total cost formatted as money
var fTotal = 0;
var iNumberOrdered = 0; //Number of products ordered

iNumberOrdered = GetCookie("NumberOrdered");
if ( iNumberOrdered == null )
iNumberOrdered = 0;

for ( i = 1; i <= iNumberOrdered; i++ ) {

NewOrder = "Order." + i;
database = "";
database = GetCookie(NewOrder);

Token0 = database.indexOf("|", 0);
Token1 = database.indexOf("|", Token0+1);
Token2 = database.indexOf("|", Token1+1);
Token3 = database.indexOf("|", Token2+1);
Token4 = database.indexOf("|", Token3+1);
Token5 = database.indexOf("|", Token4+1);

fields = new Array;
fields[0] = database.substring( 0, Token0 ); // Product ID
fields[1] = database.substring( Token0+1, Token1 ); // Quantity
fields[2] = database.substring( Token1+1, Token2 ); // Price
fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description
fields[4] = database.substring( Token3+1, Token4 ); // Weight
fields[5] = database.substring( Token4+1, database.length ); //Additional Information
fields[6] = database.substring( Token5+1, database.length ); // Limit

fTotal += (parseInt(fields[1]) * parseFloat(fields[2]) );

}
//----------Begin Listing of Coupons----------

//-----$5.00 Off Coupon-----
if (coupon=="Test"){
form.PRICE.value=-5.00;
form.ID_NUM.value="Test Coupon 1";
form.NAME.value="$5.00 Off Coupon";
location.href=location.href;
return true;
}



//-----10% Off Coupon-----
if (coupon=="Test2"){
form.PRICE.value=-(moneyFormat(fTotal * .10));
form.ID_NUM.value="Test Coupon 2";
form.NAME.value="10% Off Coupon";
location.href=location.href;
return true;
}

//-----$5.00 off only if total in cart is greater than $20.00-----
if ((coupon=="Test3") && (fTotal >= 20)){
form.PRICE.value=-5.00;
form.ID_NUM.value="Test Coupon 3";
form.NAME.value="$5.00 Off Greater Than $20.00 Purchase";
location.href=location.href;
return true;
}

if((coupon=="Test3") && (fTotal < 20)){
alert("You must have at least $20.00 worth of merchandise in your cart to use this code!");
return false;
}

//----------End of Coupon Listing----------

else{
alert("I'm sorry, that coupon code is invalid. Please try another code.");
return false;
}
nuchie1
WebMaster
 
Posts: 4
Joined: Wed Jun 09, 2010 5:20 pm

Re: Coupons

Postby Stefko » Sat Jun 12, 2010 1:13 am

are you using the script tags before and after your code?
KFL Technologies
Web-Enabled Solutions
e-Commerence Solutions
Stefko
Contributor / Guru
 
Posts: 833
Joined: Wed Sep 18, 2002 1:11 am
Location: Wichita, KS


Return to Help: Cart / General

Who is online

Users browsing this forum: wuhuilin11 and 6 guests