Two varying prices on inherited coding

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

Moderators: Koibito, Stefko, Randy

Two varying prices on inherited coding

Postby bozley_john_bozley » Sat Jun 23, 2012 10:48 am

well, this is a first for me... i've inherited this and need it adjusted so that products are £15.00 for the first 5 items and £10.00 thereafter, i.e >=6... no free postage or other discounts. Sounds basic but i can't get my head around how the coding below has already been adjusted... any ideas would be very much appreciated and greatly received...

//Options for Everyone:
MonetarySymbol = '£';
DisplayNotice = 'true';
DisplayShippingColumn = '';
DisplayShippingRow = 'true';
DisplayTaxRow = '';
TaxRate = 0.00;
TaxByRegion = '';
TaxPrompt = '';
TaxablePrompt = '';
NonTaxablePrompt = '';
MinimumOrder = 0.00;
MinimumOrderPrompt = 'Your order is below our minimum order, please order more before checking out.';
ShippingPrompt = 'Please select a valid postal option.';
strCustDiscountTxt = '';
//PostageArea = "";

//Payment Processor Options:
PaymentProcessor = '';

//Options for Programmers:
OutputItemId = 'ID_';
OutputItemQuantity = 'QUANTITY_';
OutputItemPrice = 'PRICE_';
OutputItemName = 'NAME_';
OutputItemShipping = 'SHIPPING_';
OutputItemAddtlInfo = 'ADDTLINFO_';
OutputOrderSubtotal = 'SUBTOTAL';
OutputOrderShipping = 'SHIPPING';
OutputOrderTax = 'TAX';
OutputOrderTotal = 'TOTAL';
OutputOrderDiscount = 'DISCOUNT';
OutputOrderDiscountTxt = 'DISCOUNT_TEXT';
AppendItemNumToOutput = 'true';
HiddenFieldsToCheckout = 'true';


//=====================================================================||
//---------------------------------------------------------------------||
// YOU DO NOT NEED TO MAKE ANY MODIFICATIONS BELOW THIS LINE ||
//---------------------------------------------------------------------||
//=====================================================================||


//---------------------------------------------------------------------||
// Language Strings ||
// ------------------ ||
// These strings will not be used unless you have not included a ||
// language pack already. You should NOT modify these, but instead ||
// modify the strings in language-**.js where ** is the language pack ||
// you are using. ||
//---------------------------------------------------------------------||
if ( !bLanguageDefined ) {
strSorry = "I'm Sorry, your cart is full, please proceed to checkout.";
strAdded = " added to your shopping cart";
strRemove = "Click 'Ok' to remove this product from your shopping cart.";
strILabel = "Product Id";
strDLabel = "Product Name/Description";
strQLabel = "Quantity";
strPLabel = "Price";
strSLabel = "Postage";
strRLabel = "Remove From Cart";
strRButton= "Remove";
strSUB = "SUBTOTAL";
strSHIP = "Postage";
strTAX = "TAX";
strTOT = "TOTAL";
strErrQty = "Invalid Quantity.";
strNewQty = 'Please enter new quantity:';
bLanguageDefined = true;
}


//---------------------------------------------------------------------||
// FUNCTION: CKquantity ||
// PARAMETERS: Quantity to ||
// RETURNS: Quantity as a number, and possible alert ||
// PURPOSE: Make sure quantity is represented as a number ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
var strNewQuantity = "";

for ( i = 0; i < checkString.length; i++ ) {
ch = checkString.substring(i, i+1);
if ( (ch >= "0" && ch <= "9") || (ch == '.') )
strNewQuantity += ch;
}

if ( strNewQuantity.length < 1 )
strNewQuantity = "1";

return(strNewQuantity);
}


//---------------------------------------------------------------------||
// FUNCTION: AddToCart ||
// PARAMETERS: Form Object ||
// RETURNS: Cookie to user's browser, with prompt ||
// PURPOSE: Adds a product to the user's shopping cart ||
//---------------------------------------------------------------------||
function AddToCart(thisForm) {
var iNumberOrdered = 0;
var bAlreadyInCart = false;
var notice = "";
iNumberOrdered = GetCookie("NumberOrdered");

if ( iNumberOrdered == null )
iNumberOrdered = 0;

if ( thisForm.ID_NUM == null )
strID_NUM = "";
else
strID_NUM = thisForm.ID_NUM.value;

if ( thisForm.QUANTITY == null )
strQUANTITY = "1";
else
strQUANTITY = thisForm.QUANTITY.value;

if ( thisForm.PRICE == null )
strPRICE = "0.00";
else
strPRICE = thisForm.PRICE.value;

if ( thisForm.NAME == null )
strNAME = "";
else
strNAME = thisForm.NAME.value;

if ( thisForm.SHIPPING == null )
strSHIPPING = "0.00";
else
strSHIPPING = thisForm.SHIPPING.value;

if ( thisForm.ADDITIONALINFO == null ) {
strADDTLINFO = "";
} else {
strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
}
if ( thisForm.ADDITIONALINFO2 != null ) {
strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
}
if ( thisForm.ADDITIONALINFO3 != null ) {
strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
}
if ( thisForm.ADDITIONALINFO4 != null ) {
strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
}

//Is this product already in the cart? If so, increment quantity instead of adding another.
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);

fields = new Array;
fields[0] = database.substring( 0, Token0 );
fields[1] = database.substring( Token0+1, Token1 );
fields[2] = database.substring( Token1+1, Token2 );
fields[3] = database.substring( Token2+1, Token3 );
fields[4] = database.substring( Token3+1, Token4 );
fields[5] = database.substring( Token4+1, database.length );

if ( fields[0] == strID_NUM &&
fields[2] == strPRICE &&
fields[3] == strNAME &&
fields[5] == strADDTLINFO
) {
bAlreadyInCart = true;
dbUpdatedOrder = strID_NUM + "|" +
(parseInt(strQUANTITY)+parseInt(fields[1])) + "|" +
strPRICE + "|" +
strNAME + "|" +
strSHIPPING + "|" +
strADDTLINFO;
strNewOrder = "Order." + i;
DeleteCookie(strNewOrder, "/");
SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
notice = strQUANTITY + " '" + strNAME + "' " + strAdded + " at " + MonetarySymbol + strPRICE + " each.";
break;
}
}


if ( !bAlreadyInCart ) {
iNumberOrdered++;

if ( iNumberOrdered > 15 )
alert( strSorry );
else {
dbUpdatedOrder = strID_NUM + "|" +
strQUANTITY + "|" +
strPRICE + "|" +
strNAME + "|" +
strSHIPPING + "|" +
strADDTLINFO;

strNewOrder = "Order." + iNumberOrdered;
SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
SetCookie("NumberOrdered", iNumberOrdered, null, "/");
notice = strQUANTITY + " " + strNAME + strAdded + " at " + MonetarySymbol + strPRICE + " each.";
}
}

// if ( DisplayNotice )
// alert(notice);
}


//---------------------------------------------------------------------||
// FUNCTION: getCookieVal ||
// PARAMETERS: offset ||
// RETURNS: URL unescaped Cookie Value ||
// PURPOSE: Get a specific value from a cookie ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);

if ( endstr == -1 )
endstr = document.cookie.length;
return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION: FixCookieDate ||
// PARAMETERS: date ||
// RETURNS: date ||
// PURPOSE: Fixes cookie date, stores back in date ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime();

date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION: GetCookie ||
// PARAMETERS: Name ||
// RETURNS: Value in Cookie ||
// PURPOSE: Retrieves cookie from users browser ||
//---------------------------------------------------------------------||
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;

while ( i < clen ) {
var j = i + alen;
if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
i = document.cookie.indexOf(" ", i) + 1;
if ( i == 0 ) break;
}

return(null);
}


//---------------------------------------------------------------------||
// FUNCTION: SetCookie ||
// PARAMETERS: name, value, expiration date, path, domain, security ||
// RETURNS: Null ||
// PURPOSE: Stores a cookie in the users browser ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}


//---------------------------------------------------------------------||
// FUNCTION: DeleteCookie ||
// PARAMETERS: Cookie name, path, domain ||
// RETURNS: null ||
// PURPOSE: Removes a cookie from users browser. ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain) {
if ( GetCookie(name) ) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}


//---------------------------------------------------------------------||
// FUNCTION: MoneyFormat ||
// PARAMETERS: Number to be formatted ||
// RETURNS: Formatted Number ||
// PURPOSE: Reformats Dollar Amount to #.## format ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
var dollars = Math.floor(input);
var tmp = new String(input);

for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
if ( tmp.charAt(decimalAt)=="." )
break;
}

var cents = "" + Math.round(input * 100);
cents = cents.substring(cents.length-2, cents.length)
dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

if ( cents == "0" )
cents = "00";

return(dollars + "." + cents);
}


//---------------------------------------------------------------------||
// FUNCTION: RemoveFromCart ||
// PARAMETERS: Order Number to Remove ||
// RETURNS: Null ||
// PURPOSE: Removes an item from a users shopping cart ||
//---------------------------------------------------------------------||
function RemoveFromCart(RemOrder) {
if ( confirm( strRemove ) ) {
NumberOrdered = GetCookie("NumberOrdered");
for ( i=RemOrder; i < NumberOrdered; i++ ) {
NewOrder1 = "Order." + (i+1);
NewOrder2 = "Order." + (i);
database = GetCookie(NewOrder1);
SetCookie (NewOrder2, database, null, "/");
}
NewOrder = "Order." + NumberOrdered;
SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");
DeleteCookie(NewOrder, "/");
location.href=location.href;
}
}


//---------------------------------------------------------------------||
// FUNCTION: ChangeQuantity ||
// PARAMETERS: Order Number to Change Quantity ||
// RETURNS: Null ||
// PURPOSE: Changes quantity of an item in the shopping cart ||
//---------------------------------------------------------------------||
function ChangeQuantity(OrderItem,NewQuantity) {
if ( isNaN(NewQuantity) ) {
alert( strErrQty );
} else {
NewOrder = "Order." + OrderItem;
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);

fields = new Array;
fields[0] = database.substring( 0, Token0 );
fields[1] = database.substring( Token0+1, Token1 );
fields[2] = database.substring( Token1+1, Token2 );
fields[3] = database.substring( Token2+1, Token3 );
fields[4] = database.substring( Token3+1, Token4 );
fields[5] = database.substring( Token4+1, database.length );

dbUpdatedOrder = fields[0] + "|" +
NewQuantity + "|" +
fields[2] + "|" +
fields[3] + "|" +
fields[4] + "|" +
fields[5];
strNewOrder = "Order." + OrderItem;
DeleteCookie(strNewOrder, "/");
SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
location.href=location.href;
}
}

//---------------------------------------------------------------------||
// FUNCTION: ChangePostage ||
// PARAMETERS: varPostageArea (passed in POSTAGE environment variable)||
// RETURNS: Null ||
// PURPOSE: Changes postage charges in checkout element ||
//---------------------------------------------------------------------||
function ChangePostage(varPostageArea) {
// var PostageArea = ""; // Set Postage Area To Blank
if (varPostageArea == "UK") {
PostageArea = "UK";
} else if (varPostageArea == "EU") {
PostageArea = "EU";
} else if (varPostageArea == "NONEU") {
PostageArea = "NONEU";
} else {
PostageArea = "UK";
}
location.href=location.href;
}



//---------------------------------------------------------------------||
// FUNCTION: GetFromCart ||
// PARAMETERS: Null ||
// RETURNS: Product Table Written to Document ||
// PURPOSE: Draws current cart product table on HTML page ||
// **DEPRECATED FUNCTION, USE ManageCart or Checkout** ||
//---------------------------------------------------------------------||
function GetFromCart( fShipping ) {
ManageCart( );
}


//---------------------------------------------------------------------||
// FUNCTION: RadioChecked ||
// PARAMETERS: Radio button to check ||
// RETURNS: True if a radio has been checked ||
// PURPOSE: Form fillin validation ||
//---------------------------------------------------------------------||
function RadioChecked( radiobutton ) {
var bChecked = false;
var rlen = radiobutton.length;
for ( i=0; i < rlen; i++ ) {
if ( radiobutton[i].checked )
bChecked = true;
}
return bChecked;
}


//---------------------------------------------------------------------||
// FUNCTION: QueryString ||
// PARAMETERS: Key to read ||
// RETURNS: value of key ||
// PURPOSE: Read data passed in via GET mode ||
//---------------------------------------------------------------------||
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString(key) {
var value = null;
for (var i=0;i<QueryString.keys.length;i++) {
if (QueryString.keys[i]==key) {
value = QueryString.values[i];
break;
}
}
return value;
}

//---------------------------------------------------------------------||
// FUNCTION: QueryString_Parse ||
// PARAMETERS: (URL string) ||
// RETURNS: null ||
// PURPOSE: Parses query string data, must be called before Q.S. ||
//---------------------------------------------------------------------||
function QueryString_Parse() {
var query = window.location.search.substring(1);
var pairs = query.split("&"); for (var i=0;i<pairs.length;i++) {
var pos = pairs[i].indexOf('=');
if (pos >= 0) {
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}


//---------------------------------------------------------------------||
// FUNCTION: ManageCart ||
// PARAMETERS: Null ||
// RETURNS: Product Table Written to Document ||
// PURPOSE: Draws current cart product table on HTML page ||
//---------------------------------------------------------------------||
function ManageCart( ) {
var iNumberOrdered = 0; //Number of products ordered
var fTotal = 0; //Total cost of order
var fTax = 0; //Tax amount
var fShipping = 0; //Shipping amount
var strTotal = ""; //Total cost formatted as money
var strTax = ""; //Total tax formatted as money
var strShipping = ""; //Total shipping formatted as money
var strOutput = ""; //String to be written to page
var bDisplay = true; //Whether to write string to the page (here for programmers)
var varFreeDVD = 0; //Number of free DVD's entitled to
var strFreeDVDTxt = "DVD's"; //Text to use for free DVD's (either DVD or DVD's)
var varTotDVD = 0; //Total number of DVD's in order
var strDVDTxt = "DVD"; //Text to use for DVD's (either DVD or DVD's)
var varDVDDiscount = 0; //Discount based on number of DVD's ordered
var varTotExShip = 0; //Total excluding shipping

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

if ( bDisplay )
strOutput = "<TABLE CLASS=\"nopcart\" width=\"100%\" border=0><TR>" +
"<TD CLASS=\"nopheader\" width=\"10%\"><div align=\"center\"><B><u>"+strILabel+"</u></B></div></TD>" +
"<TD CLASS=\"nopheader\" width=\"52%\"><div align=\"left\"><B><u>"+strDLabel+"</u></B></div></TD>" +
"<TD CLASS=\"nopheader\" width=\"12%\"><div align=\"center\"><B><u>"+strQLabel+"</u></B></div></TD>" +
"<TD CLASS=\"nopheader\" width=\"12%\"><div align=\"center\"><B><u>"+strPLabel+"</u></B></div></TD>" +
// (DisplayShippingColumn?"<TD CLASS=\"nopheader\" width=\"15%\"><div align=\"center\"><B><u>"+strSLabel+"</u></B></div></TD>":"") +
"<TD CLASS=\"nopheader\" width=\"14%\"><div align=\"center\"><B><u>"+strRLabel+"</u></B></div></TD></TR>";

if ( iNumberOrdered == 0 ) {
varTotExShip = 0.00;
// varTotExShip = moneyFormat(parseFloat(strTotal) - parseFloat(varDVDDiscount) );
strOutput += "<TR><TD COLSPAN=6 CLASS=\"nopentry\"><CENTER><BR><B>Your cart is empty</B><BR><BR></CENTER></TD></TR>";
}

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);

fields = new Array;
fields[0] = database.substring( 0, Token0 ); // Product ID
fields[1] = database.substring( Token0+1, Token1 ); // Quantity
// fields[2] = varDVDPrice; // Price
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 ); // Shipping Cost
fields[5] = database.substring( Token4+1, database.length ); //Additional Information

fTotal += (parseInt(fields[1]) * parseFloat(fields[2]) );
fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) );
fTax = (fTotal * TaxRate);
strTotal = moneyFormat(fTotal);
strTax = moneyFormat(fTax);
strShipping = moneyFormat(fShipping);

if ( bDisplay ) {
strOutput += "<TR><TD CLASS=\"nopentrylarger\"><div align=\"center\">" + fields[0] + "</div></TD>";

if ( fields[5] == "" )
strOutput += "<TD CLASS=\"nopentrylarger\">" + fields[3] + "</TD>";
else
strOutput += "<TD CLASS=\"nopentrylarger\">" + fields[3] + " - <I>"+ fields[5] + "</I></TD>";

varTotDVD = (parseInt(varTotDVD) ) + (parseInt(fields[1]) );
strOutput += "<TD CLASS=\"nopentry\"><div align=\"center\"><INPUT TYPE=TEXT NAME=Q SIZE=2 MAXLENGTH=\"2\" VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></div></TD>";
strOutput += "<TD CLASS=\"nopentrylarger\"><div align=\"right\">"+ MonetarySymbol + moneyFormat(fields[2]) + "</TD>";

if ( DisplayShippingColumn ) {
if ( parseFloat(fields[4]) > 0 )
strOutput += "<TD CLASS=\"nopentry\"><div align=\"center\">" + MonetarySymbol + moneyFormat(fields[4]) + "</div></TD>";
else
strOutput += "<TD CLASS=\"nopentry\"><div align=\"center\">" + MonetarySymbol + calcPostageUK + " (UK)<br>" + MonetarySymbol + calcPostageEU + " (EU)<br>" + MonetarySymbol + calcPostageNONEU + " (non-EU)</div></TD>";
}

strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\" class=\"nopbutton\" title=\"Click to Remove " + fields[3] + " From Cart.\"></TD></TR>";
}

if ( AppendItemNumToOutput ) {
strFooter = i;
} else {
strFooter = "";
}
if ( HiddenFieldsToCheckout ) {
strOutput += "<input type=hidden name=\"" + OutputItemId + strFooter + "\" value=\"" + fields[0] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemQuantity + strFooter + "\" value=\"" + fields[1] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemPrice + strFooter + "\" value=\"" + fields[2] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemName + strFooter + "\" value=\"" + fields[3] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemShipping + strFooter + "\" value=\"" + fields[4] + "\">";
strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
}

}

if ( bDisplay ) {
if ( varTotDVD == "1" )
strDVDTxt = "DVD";
else
strDVDTxt = "DVD's";
if ( varTotDVD == "10" )
strTotal = 120;
strCustDiscountTxt += "Customer entitled to " + strTenFixed + ".\n";
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4><hr></TD>";
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=2><B>"+strSUB+"</B></TD>";
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><div align=\"center\"><B>" + varTotDVD + " " + strDVDTxt + "</B></div></TD>";
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><B><div align=\"right\">" + MonetarySymbol + moneyFormat(strTotal) + "</div></B></TD>";
strOutput += "</TR>";
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4><hr></TD>";

if ( varTotDVD == "10" ) {
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>" + strTenFixed + "</B><BR>You have qualified for the <b>Ten DVD's for £120.00</b> deal with <b>FREE</b> postage.</TD>";
} else {
varFreeDVD = parseInt( varTotDVD / 4);
if ( varFreeDVD == "1" ) {
strFreeDVDTxt = "DVD";
} else {
strFreeDVDTxt = "DVD's";
}
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>" + strFreeDVD + "</B><BR>For every four DVD's ordered, get one of them for <b>FREE</b>.<br>Your current order entitles you to <b>" + varFreeDVD + "</b> free " + strFreeDVDTxt + ".</TD>";
strCustDiscountTxt += "Customer entitled to " + varFreeDVD + " free DVD's.\n";
if ( varFreeDVD == "0" ) {
} else {
varDVDDiscount = moneyFormat(parseInt(varFreeDVD) * parseFloat(fields[2]) );
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><div align=\"right\"><B>-" + MonetarySymbol + varDVDDiscount + "</B></div></TD>";
}
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4><hr></TD>";
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>Postage charges will be shown on the Checkout page.</B><br>Please select a postage option from the following;<div align=\"left\" class=\"nopentry\"><input type=\"radio\" name=\"postageArea\" value=\"UK\" checked>&nbsp;-&nbsp; Postage To The UK (" + MonetarySymbol + calcPostageUK + " per DVD)<br>";
strOutput += "<div align=\"left\" class=\"nopentry\"><input type=\"radio\" name=\"postageArea\" value=\"EU\">&nbsp;-&nbsp; Postage To Europe (" + MonetarySymbol + calcPostageEU + " per DVD)<br>";
strOutput += "<div align=\"left\" class=\"nopentry\"><input type=\"radio\" name=\"postageArea\" value=\"NONEU\">&nbsp;-&nbsp; Postage To The Rest Of The World (" " not available)</div></TD>";
}
if ( varTotDVD == "10" ) {
}
if ( varTotDVD == "0" ) {
varTotExShip = moneyFormat(0.00);
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4><hr></TD>";
strOutput += "<TR><TD CLASS=\"noptotallarger\" COLSPAN=3><B>" + strSUB + " (excluding postage)</B></TD>";
strOutput += "<TD CLASS=\"noptotallarger\" COLSPAN=1><div align=\"right\"><B>" + MonetarySymbol + varTotExShip + "</div></B></TD>";
} else {
varTotExShip = moneyFormat(parseFloat(strTotal) - parseFloat(varDVDDiscount) );
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4><hr></TD>";
strOutput += "<TR><TD CLASS=\"noptotallarger\" COLSPAN=3><B>" + strSUB + " (excluding postage)</B></TD>";
strOutput += "<TD CLASS=\"noptotallarger\" COLSPAN=1><div align=\"right\"><B>" + MonetarySymbol + varTotExShip + "</div></B></TD>";
}

strOutput += "</TR>";

// if ( !TaxByRegion ) {
// strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strTOT+"</B></TD>";
// strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><B><div align=\"right\">" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</div></B></TD>";
// strOutput += "</TR>";
// }

strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 valign=\"top\"><div align=\"center\"><br><input type=\"button\" border=0 value=\"Continue Shopping\" onClick=\"javascript:history.go(-2)\"></div></td>";
if ( iNumberOrdered == 0 ) {
} else {
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 valign=\"top\"><br><FORM ACTION=\"checkout.html\" NAME=\"form\" METHOD=\"GET\" onsubmit=\"return ValidateCart(this)\"><input type=\"submit\" border=0 value=\"Checkout\" align=\"center\"></FORM>";
}
strOutput += "</TABLE>";

// if ( HiddenFieldsToCheckout ) {
// strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
// strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
// strOutput += "<input type=hidden name=\""+OutputOrderTax+"\" value=\""+ MonetarySymbol + strTax + "\">";
// strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\" value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\">";
// }
}
g_TotalCost = (fTotal + fShipping + fTax);

document.write(strOutput);
document.close();
}

//---------------------------------------------------------------------||
// FUNCTION: ValidateCart ||
// PARAMETERS: Form to validate ||
// RETURNS: true/false ||
// PURPOSE: Validates the managecart form ||
//---------------------------------------------------------------------||
var g_TotalCost = 0;
function ValidateCart( theForm ) {
if ( TaxByRegion ) {
if ( !RadioChecked(eval("theForm."+OutputOrderTax)) ) {
alert( TaxPrompt );
return false;
}
}

if ( MinimumOrder >= 0.01 ) {
if ( g_TotalCost < MinimumOrder ) {
alert( MinimumOrderPrompt );
return false;
}
}

return true;
}

//---------------------------------------------------------------------||
// FUNCTION: CleanCart ||
// PARAMETERS: ||
// RETURNS: ||
// PURPOSE: Deletes the cookie after checkout ||
//---------------------------------------------------------------------||
function cleanCart(){
var iNumberOrdered = GetCookie("NumberOrdered");
if ( iNumberOrdered == null ){
iNumberOrdered = 0;
}
for ( i = 1; i <= iNumberOrdered; i++ ) {
NewOrder = "Order." + i;
DeleteCookie(NewOrder, "/");
}
DeleteCookie("NumberOrdered", "/");
}


//---------------------------------------------------------------------||
// FUNCTION: CheckoutCart ||
// PARAMETERS: Null ||
// RETURNS: Product Table Written to Document ||
// PURPOSE: Draws current cart product table on HTML page for ||
// checkout. ||
//---------------------------------------------------------------------||
function CheckoutCart( ) {
var iNumberOrdered = 0; //Number of products ordered
var fTotal = 0; //Total cost of order
var fTax = 0; //Tax amount
var fShipping = 0; //Shipping amount
var strTotal = ""; //Total cost formatted as money
var fLineTotal = 0; //Line Total formatted as money
var strTax = ""; //Total tax formatted as money
var strShipping = ""; //Total shipping formatted as money
var strOutput = ""; //String to be written to page
var bDisplay = true; //Whether to write string to the page (here for programmers)
var strPP = ""; //Payment Processor Description Field
var varFreeDVD = 0; //Number of free DVD's entitled to
var strFreeDVDTxt = "DVD's"; //Text to use for free DVD's (either DVD or DVD's)
var varTotDVD = 0; //Total number of DVD's in order
var strDVDTxt = "DVD"; //Text to use for DVD's (either DVD or DVD's)
var varDVDDiscount = 0; //Discount based on number of DVD's ordered
var varTotExShip = 0; //Total excluding shipping
var PostageAreaUK = "";
var PostageAreaEU = "";
var PostageAreaNONEU = "";

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

if ( TaxByRegion ) {
QueryString_Parse();
fTax = parseFloat( QueryString( OutputOrderTax ) );
strTax = moneyFormat(fTax);
}

if ( bDisplay )
strOutput = "<TABLE CLASS=\"nopcart\" width=\"100%\" border=0><TR>" +
"<TD CLASS=\"nopheader\" width=\"10%\"><div align=\"center\"><B><u>"+strILabel+"</u></B></div></TD>" +
"<TD CLASS=\"nopheader\" width=\"52%\"><div align=\"left\"><B><u>"+strDLabel+"</u></B></div></TD>" +
"<TD CLASS=\"nopheader\" width=\"12%\"><div align=\"center\"><B><u>"+strQLabel+"</u></B></div></TD>" +
"<TD CLASS=\"nopheader\" width=\"12%\"><div align=\"center\"><B><u>"+strPLabel+"</u></B></div></TD>" +
"<TD CLASS=\"nopheader\" width=\"14%\"><div align=\"center\"><B><u>"+strLineTotal+"</u></B></div></TD>";

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);

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[2] = varDVDPrice; // Price -->
fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description
fields[4] = database.substring( Token3+1, Token4 ); // Shipping Cost
fields[5] = database.substring( Token4+1, database.length ); //Additional Information

fLineTotal = 0;
fTotal += (parseInt(fields[1]) * parseFloat(fields[2]) );
fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) );
fLineTotal = (parseInt(fields[1]) * parseFloat(fields[2]) );
if ( !TaxByRegion ) fTax = (fTotal * TaxRate);
strTotal = moneyFormat(fTotal);
if ( !TaxByRegion ) strTax = moneyFormat(fTax);
strShipping = moneyFormat(fShipping);
if ( bDisplay ) {
strOutput += "<TR><TD CLASS=\"nopentrylarger\"><div align=\"center\">" + fields[0] + "</div></TD>";
if ( fields[5] == "" )
strOutput += "<TD CLASS=\"nopentrylarger\"><div align=\"left\">" + fields[3] + "</div></TD>";
else
strOutput += "<TD CLASS=\"nopentrylarger\"><div align=\"left\">" + fields[3] + " - <I>"+ fields[5] + "</I></div></TD>";
varTotDVD = (parseInt(varTotDVD) ) + (parseInt(fields[1]) );
strOutput += "<TD CLASS=\"nopentrylarger\"><div align=\"center\">" + fields[1] + "</div></TD>";
strOutput += "<TD CLASS=\"nopentrylarger\"><div align=\"right\">"+ MonetarySymbol + moneyFormat(fields[2]) + "</div></TD>";
strOutput += "<TD CLASS=\"nopentrylarger\"><div align=\"right\">"+ MonetarySymbol + moneyFormat(fLineTotal) + "</div></TD>";
if ( DisplayShippingColumn ) {
if ( parseFloat(fields[4]) > 0 )
strOutput += "<TD CLASS=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</TD>";
else
strOutput += "<TD CLASS=\"nopentry\">N/A</TD>";
}
strOutput += "</TR>";
}
if ( AppendItemNumToOutput ) {
strFooter = i;
} else {
strFooter = "";
}
if ( PaymentProcessor != '' ) {
//Process description field for payment processors instead of hidden values.
//Format Description of product as:
// ID, Name, Qty X
strPP += fields[0] + ", " + fields[3];
if ( fields[5] != "" )
strPP += " - " + fields[5];
strPP += ", Qty. " + fields[1] + "\n";
} else {
strOutput += "<input type=hidden name=\"" + strFooter + "\" value=\"" + fields[0] + " - " + fields[3] + " (x " + fields[1] +")\">";
// strOutput += "<input type=hidden name=\"" + OutputItemId + strFooter + "\" value=\"" + fields[0] + "\">";
// strOutput += "<input type=hidden name=\"" + OutputItemQuantity + strFooter + "\" value=\"" + fields[1] + "\">";
// strOutput += "<input type=hidden name=\"" + OutputItemPrice + strFooter + "\" value=\"" + fields[2] + "\">";
// strOutput += "<input type=hidden name=\"" + OutputItemName + strFooter + "\" value=\"" + fields[3] + "\">";
// strOutput += "<input type=hidden name=\"" + OutputItemShipping + strFooter + "\" value=\"" + fields[4] + "\">";
// strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
}
}
if ( bDisplay ) {
if ( varTotDVD == "1" )
strDVDTxt = "DVD";
else
strDVDTxt = "DVD's";
if ( varTotDVD == "10" ) {
strTotal = "120.00";
strCustDiscountTxt += "Customer entitled to " + strTenFixed + ".\n";
}
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><hr></TD>";
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=2><B>"+strSUB+"</B></TD>";
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><div align=\"center\"><B>" + varTotDVD + " " + strDVDTxt + "</B></div></TD>";
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1>&nbsp;</TD>";
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + strTotal + "</B></TD>";
strOutput += "</TR>";
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><hr></TD>";

if ( varTotDVD == "10" ) {
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>" + strTenFixed + "</B><BR>You have qualified for the <b>Ten DVD's for £120.00</b> deal with <b>FREE</b> postage.</TD>";
fTotal = "120.00";
} else {
varFreeDVD = parseInt( varTotDVD / 4);
if ( varFreeDVD == "1" ) {
strFreeDVDTxt = "DVD";
} else {
strFreeDVDTxt = "DVD's";
}
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4><B>" + strFreeDVD + "</B><BR>For every four DVD's ordered, get one of them for <b>FREE</b>.<br>Your current order entitles you to <b>" + varFreeDVD + "</b> free " + strFreeDVDTxt + " (discount applied here).</TD>";
strCustDiscountTxt += "Customer entitled to " + varFreeDVD + " free DVD's.\n";
if ( varFreeDVD == "0" ) {
} else {
varDVDDiscount = moneyFormat(parseInt(varFreeDVD) * parseFloat(fields[2]) );
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1><div align=\"right\"><B>-" + MonetarySymbol + varDVDDiscount + "</B></div></TD>";
}
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><hr></TD>";
QueryString_Parse();
var postageLocation = QueryString( 'postageArea' );
if ( postageLocation == "UK") {
postageText = "UK";
fShipping = (calcPostageUK) * parseFloat(varTotDVD);
} else if ( postageLocation == "EU") {
postageText = "Europe";
fShipping = (calcPostageEU) * parseFloat(varTotDVD);
} else if ( postageLocation == "NONEU") {
postageText = "Rest of the World";
fShipping = (calcPostageNONEU) * parseFloat(varTotDVD);
} else {
postageText = "None Selected. Rest of the World charged.";
fShipping = (calcPostageNONEU) * parseFloat(varTotDVD);
}
if (varTotDVD == "10") {
fShipping = "0.00";
strCustDiscountTxt += "Customer entitled to free shipping with 10 DVD's.\n";
}
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=4><B>Postage Charges (" + postageText + " selected)</B><div align=\"left\" class=\"nopentry\">To change your Postal Location, please click 'Back To Cart' to go back to your cart<br>and select a Postage Area.";
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat(fShipping) + "</B></TD>";
strOutput += "</TR>";
}
if ( DisplayTaxRow || TaxByRegion ) {
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strTAX+"</B></TD>";
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + strTax + "</B></TD>";
strOutput += "</TR>";
}
strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=5><hr></TD>";
strOutput += "<TR><TD CLASS=\"noptotallarger\" COLSPAN=4><B>"+strTOT+" (to be debited to your credit card)</B></TD>";
strOutput += "<TD CLASS=\"noptotallarger\" COLSPAN=1 ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax - varDVDDiscount )) + "</B></TD>";
strOutput += "</TR>";
strOutput += "<TD CLASS=\"noptotal\" COLSPAN=5 valign=\"top\"><div align=\"center\"><br><input type=\"button\" border=0 value=\"Back To Cart\" onClick=\"javascript:history.go(-1)\"></div>";
strOutput += "</TABLE>";
if ( PaymentProcessor == 'an') {
//Process this for Authorize.net WebConnect
strOutput += "<input type=hidden name=\"x_Version\" value=\"3.0\">";
strOutput += "<input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\">";
strOutput += "<input type=hidden name=\"x_Description\" value=\""+ strPP + "\">";
strOutput += "<input type=hidden name=\"x_Amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
} else if ( PaymentProcessor == 'wp') {
//Process this for WorldPay
strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
strOutput += "<input type=hidden name=\"amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
} else if ( PaymentProcessor == 'lp') {
//Process this for LinkPoint
strOutput += "<input type=hidden name=\"mode\" value=\"fullpay\">";
strOutput += "<input type=hidden name=\"chargetotal\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
strOutput += "<input type=hidden name=\"tax\" value=\""+ MonetarySymbol + strTax + "\">";
strOutput += "<input type=hidden name=\"subtotal\" value=\""+ MonetarySymbol + strTotal + "\">";
strOutput += "<input type=hidden name=\"shipping\" value=\""+ MonetarySymbol + strShipping + "\">";
strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
} else {
strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + moneyFormat(fShipping) + "\">";
// strOutput += "<input type=hidden name=\""+OutputOrderTax+"\" value=\""+ MonetarySymbol + strTax + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderDiscount+"\" value=\""+ MonetarySymbol + varDVDDiscount + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\" value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax - varDVDDiscount)) + "\">";
strOutput += "<input type=hidden name=\""+OutputOrderDiscountTxt+"\" value=\""+ strCustDiscountTxt + "\">";
}
}
document.write(strOutput);
document.close();
}

//=====================================================================||
// END NOP Design SmartPost Shopping Cart ||
//=====================================================================||

yours hopefully,
b_j_b
bozley_john_bozley
WebMaster
 
Posts: 2
Joined: Sat Jun 23, 2012 10:34 am

Return to Help: Cart / General

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron