Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ultradev shopping cart

Status
Not open for further replies.

09876

Programmer
Nov 29, 2001
10
US
can someone tell me why my records and buttons are been repeated on my shopping cart? Thanks

Here's the cart.asp code:

Code:
<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<SCRIPT LANGUAGE=JavaScript RUNAT=Server NAME=&quot;UC_CART&quot;>
//
// UltraDev UCart include file Version 1.0
//
function UC_ShoppingCart(Name, cookieLifetime, colNames, colComputed)  // Cart constructor
{
	// Name is the name of this cart. This is not really used in this implementation.
	// cookieLifeTime is in days. A value of 0 means do not use cookies.
	// colNames is a list of column names (must contain: ProductID, Quantity, Price, Total)
	// colComputed is a list of computed columns (zero length string means don't compute col.)

  // Public methods or UC_Cart API
  this.AddItem           = UCaddItem;        // Add an item to the cart
  this.GetColumnValue    = GetColumnValue;   // Get a value from the cart
  this.Destroy           = UCDestroy;        // remove all items, delete session, delete client cookie (if any)
	this.SaveToDatabase    = SaveToDatabase;   // persist cart to database.
	this.GetItemCount      = GetItemCount;     // the number of items in the cart.
	this.Update            = Update;           // Update the cart quantities.
	this.GetColumnTotal    = GetColumnTotal;   // Get the sum of a cart column for all items (e.g. price or shipping wt.).
  this.GetContentsSerial = UCGetContentsSerial// Get the contents of the cart as a single delimited string
  this.SetContentsSerial = UCSetContentsSerial// Set the contents of the cart from a serial string (obtained from GetContentsSerial)
  this.GetColNamesSerial = UCGetColNamesSerial// Get the list of column names as a delimited string.
  
	// PROPERTIES
	this.SC				= null;			// Cart data array
	this.numCols		= colNames.length;
	this.colComputed	= colComputed;
	this.colNames		= colNames;
	this.Name			= Name;
	this.cookieLifetime = cookieLifetime;
	this.bStoreCookie	= (cookieLifetime != 0);

	// *CONVENIENCE* PROPERTIES
	// (not used internally, but added to provide a place to store this data)
	this.CustomerID			= null;
	this.OrderID				= null;
	this.Tax						= null;
	this.ShippingCost		= null;

  // CONSTANTS
  this.PRODUCTID	= &quot;ProductID&quot;;  // Required SKU cart column
  this.QUANTITY		= &quot;Quantity&quot;;   // Required Quantity cart column
	this.PRICE			= &quot;Price&quot;;			// Required Price cart column
	this.TOTAL			= &quot;Total&quot;;			// Required Total column
  this.cookieColDel = &quot;#UC_C#&quot;
  this.cookieRowDel = &quot;#UC_R#&quot;

	// METHODS
	this.AssertCartValid = AssertCartValid

  // Private methods - don't call these unless you understand the internals.
  this.GetIndexOfColName = UCgetIndexOfColName;
  this.GetDataFromBindings = UCgetDataFromBindings;
	this.FindItem = UCfindItem;
	this.ComputeItemTotals = ComputeItemTotals;
  this.persist = UCpersist;
  
	this.BuildInsertColumnList = BuildInsertColumnList;
	this.BuildInsertValueList = BuildInsertValueList;
	this.UpdateQuantities = UpdateQuantities;
	this.UpdateTotals = UpdateTotals;
	this.DeleteItemsWithNoQuantity = DeleteItemsWithNoQuantity;
	this.CheckAddItemConfig = CheckAddItemConfig;
	this.ColumnExistsInRS = ColumnExistsInRS;
	this.DeleteLineItem = DeleteLineItem;
	this.GetCookieName = GetCookieName;
	this.SetCookie = SetCookie;
	this.PopulateFromCookie = PopulateFromCookie;
	this.DestroyCookie = UCDestroyCookie;

// Cart &quot;internals&quot; documentation:
// The this.SC datastructure is a single variable of type array.
// Each array element corresponds to a cart column. For example: 
//    Array element 1: ProductID
//    Array element 2: Quantity
//    Array element 3: Price
//    Array elemetn 4: Total
//
// Each of these is an array. Each array index corresponds to a line item.
// As such, each array should always be exactly the same length.
  this.AssertCartValid(colNames, &quot;Cart Initialization: &quot;);
	if (Session(this.Name) != null) {
		this.SC = Session(this.Name).SC;
	} else {
		this.SC = new Array(this.numCols);
		for (var i = 0; i < this.numCols; i++) this.SC[i] = new Array();

		// Since the cart doesn't exist in session, check for cookie from previous session
		if (this.bStoreCookie){
			cookieName = this.GetCookieName();
			cookieStr = Request.Cookies(cookieName);
			if (cookieStr != null && String(cookieStr) != &quot;undefined&quot; && cookieStr != &quot;&quot;)
				this.PopulateFromCookie(cookieStr);
		}
		// Create a reference in the Session, pass the whole object (methods are not copied)
    this.persist();
	}  
}

// convert vb style arrays to js style arrays.
function UC_VbToJsArray(a) {
	if (a!=null && a.length==null) {
		a = new VBArray(a);
		a = a.toArray();
	}
	return a;
}

function UCpersist() {
  Session(this.Name) = this;
  if (this.bStoreCookie) this.SetCookie();
}

function UCDestroy(){
	this.SC = new Array(this.numCols);  // empty the &quot;in-memory&quot; cart.
	for (var i = 0; i < this.numCols; i++) this.SC[i] = new Array();
  this.persist();
	if (this.bStoreCookie) this.DestroyCookie() // remove the cookie
}

function UCgetDataFromBindings(adoRS, bindingTypes, bindingValues) {
	var values = new Array(bindingTypes.length)
	for (i=0; i<bindingTypes.length; i++) {
		var bindVal = bindingValues[i];
		if (bindingTypes[i] == &quot;RS&quot;){
			values[i] = String(adoRS(bindVal).Value)
			if (values[i] == &quot;undefined&quot;) values[i] = &quot;&quot;;
		}
		else if (bindingTypes[i] == &quot;FORM&quot;){
			values[i] = String(Request(bindVal))
			if (values[i] == &quot;undefined&quot;) values[i] = &quot;&quot;;
		} 
		else if (bindingTypes[i] == &quot;LITERAL&quot;) values[i] = bindVal;
		else if (bindingTypes[i] == &quot;NONE&quot;) values[i] = &quot;&quot;;						// no binding
		else assert(false,&quot;Unrecognized binding type: &quot; + bindingTypes[i]);		// Unrecognized binding type
	}
	return values;
}

function UCfindItem(bindingTypes, values){
  // A product is a duplicate if it has the same unique ID
  // AND all values from form bindings (except quantity) are the same
  var indexProductID = this.GetIndexOfColName(this.PRODUCTID);
  var indexQuantity  = this.GetIndexOfColName(this.QUANTITY);
  assert(indexProductID >=0, &quot;UC_Cart.js: Internal error 143&quot;);
  assert(indexQuantity >=0, &quot;UC_Cart.js: Internal error 144&quot;);
	var newRow = -1
  for (var iRow=0; iRow<this.GetItemCount(); iRow++) {
    found = true;  // assume found
    for (var iCol=0; iCol<this.numCols; iCol++) {
      if (iCol != indexQuantity) {
        if ((iCol==indexProductID) || (bindingTypes[iCol]==&quot;FORM&quot;)) {
          if (this.SC[iCol][iRow] != values[iCol]) {
            found = false;
            break;
        } }
    } }
    if (found) {
      newRow = iRow;
      break;
    }
  }
	return newRow
}

function UCaddItem(adoRS, bindingTypes, bindingValues, alreadyInCart){
  // alreadyInCart can be &quot;increment&quot; or &quot;replace&quot; to handle duplicate items in cart.
	bindingTypes = UC_VbToJsArray(bindingTypes);
	bindingValues = UC_VbToJsArray(bindingValues);

	// Check that length of binding types/values arrays is consistent with cart configuration
	assert(bindingTypes.length  == this.numCols, &quot;UCaddItem: Array length mismatch (internal error 403)&quot;);
	assert(bindingValues.length == this.numCols, &quot;UCaddItem: Array length mismatch (internal error 404)&quot;);

  // debug call
	//this.CheckAddItemConfig(adoRS, bindingTypes, bindingValues);

	var values = this.GetDataFromBindings(adoRS, bindingTypes, bindingValues) // get the actual values based on bindings
  var newRow = this.FindItem(bindingTypes, values);							// Check if this item is already in cart
  if (newRow == -1) {													// append a new item
		newRow = this.GetItemCount();    
    for (var iCol=0; iCol<this.numCols; iCol++) { // add data
      this.SC[iCol][newRow] = values[iCol];
    }
		this.ComputeItemTotals(newRow);						// add computed columns (defined in colsComputed)		
    this.persist();
	} else if (alreadyInCart == &quot;increment&quot;) {
    var indexQuantity  = this.GetIndexOfColName(this.QUANTITY);
    this.SC[indexQuantity][newRow] = parseInt(this.SC[indexQuantity][newRow]) + parseInt(values[indexQuantity])
    if (isNaN(this.SC[indexQuantity][newRow])) this.SC[indexQuantity][newRow] = 1;
		this.ComputeItemTotals(newRow);
    this.persist();
	}
}

function UCgetIndexOfColName(colName) {
  var retIndex = -1;
  for (var i=0; i<this.numCols; i++) {
    if (this.colNames[i] == colName) {
      retIndex = i;
      break;
		} 
	}
  return retIndex;
}

function ComputeItemTotals(row){
	var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
  var qty = parseInt(this.SC[indexQuantity][row])
	for (var iCol=0; iCol<this.numCols; iCol++) {
		var colToCompute = this.colComputed[iCol];
		if (colToCompute != &quot;&quot;) {
		  indexColToCompute = this.GetIndexOfColName(colToCompute);
		  this.SC[iCol][row] = parseFloat(this.SC[indexColToCompute][row]) * qty;
		}
	}
}

function CheckAddItemConfig(adoRS, bindingTypes, bindingValues) {
	var ERR_SOURCE = &quot;CheckAddItemConfig: &quot;
	var ERR_RS_BINDING_VALUE = &quot;Column for Recordset binding does not exist in recordset&quot;;
	// Check that all rs column names exist for rs binding types
	for (var i = 0; i < bindingTypes.length; i++) {
		if (bindingTypes[i] == &quot;RS&quot;){
			assert(this.ColumnExistsInRS(adoRS, bindingValues[i]), ERR_SOURCE + bindingValues[i] + &quot;: &quot; + ERR_RS_BINDING_VALUE);	
		}
	}  
}

function ColumnExistsInRS(adoRS, colName) {
	var bColExists = false;
	var items = new Enumerator(adoRS.Fields);
	while (!items.atEnd()) {
		if (items.item().Name == colName){
			bColExists = true;
			break;
		}
		items.moveNext();
	}
	return bColExists;
}

function GetColumnValue(colName, row){
	var retValue = &quot;&nbsp;&quot;;
  var indexCol = this.GetIndexOfColName(colName);
	assert(!isNaN(row), &quot;cart.GetColumnValue: row is not a number - row = &quot; + row);
  assert(indexCol >=0, &quot;cart.GetColumnValue: Could not find column \&quot;&quot; + colName + &quot;\&quot; in the cart&quot;);
  assert(row>=0, &quot;cart.GetColumnValue: Bad row number input to cart - row = &quot; + row);
  assert(this.GetItemCount()>0, &quot;cart.GetColumnValue: The cart is empty - the requested data is unavailable&quot;);
  assert(row<this.GetItemCount(), &quot;cart.GetColumnValue: The line item number is greater than the number of items in the cart - row = &quot; + row + &quot;; GetItemCount = &quot; + this.GetItemCount());
  if (this.GetItemCount()>0) {
	  retValue = this.SC[indexCol][row];
	}
	return retValue;
}

function UpdateQuantities(formElementName) {
	var items = new Enumerator(Request.Form(formElementName))
	var j = 0;
  indexQuantity = this.GetIndexOfColName(this.QUANTITY);
	while(!items.atEnd()){
		var qty = parseInt(items.item());
		if (isNaN(qty) || qty < 0) {
		  this.SC[indexQuantity][j++] = 0
		} else {
		  this.SC[indexQuantity][j++] = qty;
		}
		items.moveNext();
	}
}

function UpdateTotals() {
  // this would be a little more efficient by making the outer loop over cols rather than rows.
	for (var iRow=0; iRow<this.GetItemCount(); iRow++) {
		this.ComputeItemTotals(iRow);
	}
}

function DeleteItemsWithNoQuantity() {
	var tmpSC= new Array(this.numCols);
  for (var iCol=0; iCol<this.numCols; iCol++) tmpSC[iCol] = new Array();

  var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
  var iDest = 0;
	for (var iRow=0; iRow<this.GetItemCount(); iRow++) {    
    if (this.SC[indexQuantity][iRow] != 0) {
      for (iCol=0; iCol<this.numCols; iCol++) {
        tmpSC[iCol][iDest] = this.SC[iCol][iRow];
      }
      iDest++;
		}
	}
  this.SC = tmpSC;
}

function Update(formElementName){
	// Get new quantity values from Request object.
	// Assume they are all named the same, so you will get 
	// an array. The array length should be the same as the number
	// of line items and in the same order.
	this.UpdateQuantities(formElementName);
	this.DeleteItemsWithNoQuantity();
	this.UpdateTotals();
	this.persist();
}

function BuildInsertColumnList(orderIDCol, mappings){
	var colList = orderIDCol;
	for (var i = 0; i < mappings.length; i++) {
		if (mappings[i] != &quot;&quot;){
			colList += &quot;, &quot; + mappings[i];
		}
	}
	colList = &quot;(&quot; + colList + &quot;)&quot;;
	return colList;
}

function BuildInsertValueList(orderIDColType, orderIDVal, destCols, destColTypes, row){
  var values = &quot;&quot;;
  if (orderIDColType == &quot;num&quot;) {
    values += orderIDVal;
  } else {
    values += &quot;'&quot; + orderIDVal.toString().replace(/'/g, &quot;''&quot;) + &quot;'&quot;;
  }

	for (var iCol=0; iCol<this.numCols; iCol++){
		if (destCols[iCol] != &quot;&quot;) {
			if (destColTypes[iCol] == &quot;num&quot;) {
        assert(this.SC[iCol][row] != &quot;&quot;, &quot;SaveToDatabase: A numeric value is missing in the SQL statement in column &quot; + this.colNames[iCol]);
			  values += &quot;, &quot; + this.SC[iCol][row];
			} else {
			  values += &quot;, '&quot; + (this.SC[iCol][row]).toString().replace(/'/g, &quot;''&quot;) + &quot;'&quot;;  
			} 
		}	
	}
	values = &quot;(&quot; + values + &quot;)&quot;;
	return values;
}

function SaveToDatabase(adoConn, dbTable, orderIDCol, orderIDColType, orderIDVal, destCols, destColTypes){
	// we are going to build SQL INSERT statements and 
	// throw it at the connection / table
	// Similar to existing UD insert to database behavior
	var ERR_MAPPINGS_LENGTH = &quot;Array length must match the number of cart columns<BR>&quot;;
	var ERR_TRANS = &quot;An error occured when inserting cart items in the database.  The transaction was rolled back<BR>&quot;;
	destCols = UC_VbToJsArray(destCols);
	destColTypes = UC_VbToJsArray(destColTypes);
	assert (destCols.length == this.numCols, &quot;SaveToDatabase: &quot; + &quot;destCols - &quot; + ERR_MAPPINGS_LENGTH);
	assert (destColTypes.length == this.numCols, &quot;SaveToDatabase: &quot; + &quot;destColTypes - &quot; + ERR_MAPPINGS_LENGTH);

	var insertColList = this.BuildInsertColumnList(orderIDCol, destCols);

	if (insertColList != &quot;&quot;) { //proceed only if we have a column list
		var insertClause = &quot;INSERT INTO &quot; + dbTable + &quot; &quot; + insertColList + &quot; VALUES &quot;;
		var recs;
		adoConn.BeginTrans();
		for (var iRow=0; iRow<this.GetItemCount(); iRow++){
			var valList = this.BuildInsertValueList(orderIDColType, orderIDVal, destCols, destColTypes, iRow);
			var sql = insertClause + valList;
			adoConn.Execute(sql, recs, 1 /*adCmdText*/); 
		}
		if (adoConn.Errors.Count == 0){ 
			adoConn.CommitTrans();
			this.Destroy();	// All items saved to database, we can trash the cart
		}	else {
			adoConn.RollbackTrans();
			//assert(false, &quot;SaveToDatabase: &quot; + ERR_TRANS); Don't assert here - let ASP display the database error.
		}
	}
}

function GetItemCount(){
	return this.SC[0].length
}

function GetColumnTotal(colName){
	// Generic column Total function
	var colTotal = 0.0;
	index = this.GetIndexOfColName(colName);
	for (var i=0; i<this.SC[index].length; i++)
		colTotal += parseFloat(this.SC[index][i]);
    
	return colTotal
}


function DeleteLineItem(row){
	assert(!isNaN(row), &quot;Failure in call to DeleteLineItem - row is not a number&quot;);
  assert(row>=0 && row <this.GetItemCount(), &quot;failure in call to DeleteLineItem (internal error 121)&quot;);

	var tmpSC= new Array(this.numCols);
  var iDest = 0;
  for (var iCol=0; iCol<this.numCols; iCol++) tmpSC[iCol] = new Array();
  for (var iRow=0; iRow<this.GetItemCount(); iRow++) {
    if (iRow != row) {
      for (iCol=0; iCol<this.numCols; iCol++) {
        tmpSC[iCol][iDest] = this.SC[iCol][iRow];
      }
      iDest++;
		}
	}
  this.SC = tmpSC;
  this.persist();
}

function UCGetColNamesSerial(colDelim) {
  var serialCols = &quot;&quot;;
  for (var iCol=0; iCol<this.numCols; iCol++) {
    if (iCol != 0) serialCols += colDelim;
    serialCols += this.colNames[iCol];
  }
  return serialCols;
}

function UCGetContentsSerial(colDelim, rowDelim) {
  var serialCart = &quot;&quot;;
  for (var iRow=0; iRow<this.GetItemCount(); iRow++) {
    if (iRow != 0) serialCart += rowDelim
    for (var iCol=0; iCol<this.numCols; iCol++) {
      if (iCol != 0) serialCart += colDelim;
      serialCart += this.SC[iCol][iRow];
    }
  }
  return serialCart;
}

function UCSetContentsSerial(serialCart, colDelim, rowDelim) {
	var Rows = String(serialCart).split(rowDelim)
	for (iRow = 0; iRow < Rows.length; iRow++) {
		if (Rows[iRow] != &quot;undefined&quot; && Rows[iRow] != &quot;&quot;) {
			Cols = Rows[iRow].split(colDelim)
			iCol = 0
			for (iCol = 0; iCol<Cols.length; iCol++) {
				this.SC[iCol][iRow] = Cols[iCol]
			}
		}
	}
	this.persist();
}

function SetCookie(){
	var cookieName = this.GetCookieName()
	var cookieStr = this.GetContentsSerial(this.cookieColDel, this.cookieRowDel)
	var cookieExp = GetCookieExp(this.cookieLifetime)
	Response.Cookies(cookieName) = cookieStr
	Response.Cookies(cookieName).expires = cookieExp
}

function GetCookieName(){
	var server = Request.ServerVariables(&quot;SERVER_NAME&quot;);
	return  server + this.Name;
}

function UCDestroyCookie(){
	cookieName = this.GetCookieName();
	Response.Cookies(cookieName) = &quot;&quot;
	Response.Cookies(cookieName).expires = &quot;1/1/90&quot;
}

function PopulateFromCookie(cookieStr){
  this.SetContentsSerial(cookieStr, this.cookieColDel, this.cookieRowDel)
}

// ***************** debug code ********************
function assert(bool, msg) {
	if (!bool) {
		Response.Write(&quot;<BR><BR>An error occured in the UltraDev shopping cart:<BR>&quot; + msg + &quot;<BR>&quot;);
		//Response.End();
	}
}

function AssertCartValid(colNames, msg) {
	// go through all cart data structures and insure consistency.
	// For example all column arrays should be the same length.
	// this function should be called often, especially just after
	// makeing changes to the data structures (adding, deleting, etc.)
	// also verify we always have the required columns:
	// ProductID, Quantity, Price, Total

	// the input arg is some I add as I code this package like
	// &quot;Prior to return from AddToCart&quot;
	//
	var ERR_COOKIE_SETTINGS = &quot;Cookie settings on this page are inconsistent with those stored in the session cart<BR>&quot;; 
	var ERR_BAD_NAME = &quot;Cart name defined on this page is inconsistent with the cart name stored in the session<BR>&quot;;
	var ERR_COLUMN_COUNT = &quot;The number of cart columns defined on this page is inconsistent with the cart stored in the session<BR>&quot;;
	var ERR_REQUIRED_COLUMNS = &quot;Too few columns; minimum number of columns is 4<BR>&quot;;
	var ERR_REQUIRED_COLUMN_NAME = &quot;Required Column is missing or at the wrong offset: &quot;;
	var ERR_COLUMN_NAMES = &quot;Cart column names defined on this page are inconsistent with the cart stored in the session&quot;;
	var ERR_INCONSISTENT_ARRAY_LENGTH = &quot;Length of the arrays passed to cart constructor are inconsistent<BR>&quot;
	var errMsg = &quot;&quot;;
	var sessCart = Session(this.Name);

	if (sessCart != null) { // Validate inputs against session cart if it exists
		if (sessCart.Name != this.Name) errMsg += ERR_BAD_NAME;
		if (this.numCols < 4) errMsg += ERR_REQUIRED_COLUMNS;
		if (sessCart.numCols != this.numCols) errMsg += &quot;Column Name Array: &quot; + ERR_COLUMN_COUNT;
		if (sessCart.numCols != this.colComputed.length) errMsg += &quot;Computed Column Array: &quot; + ERR_COLUMN_COUNT;
		if (sessCart.bStoreCookie != this.bStoreCookie) errMsg += &quot;Using Cookies: &quot; + ERR_COOKIE_SETTINGS;
		if (sessCart.cookieLifetime != this.cookieLifetime) errMsg += &quot;Cookie Lifetime: &quot; + ERR_COOKIE_SETTINGS;

		// check that required columns are in the same place
		var productIndex = this.GetIndexOfColName(this.PRODUCTID);
		var quantityIndex = this.GetIndexOfColName(this.QUANTITY);
		var priceIndex = this.GetIndexOfColName(this.PRICE);
		var totalIndex = this.GetIndexOfColName(this.TOTAL);

		if (colNames[productIndex] != &quot;ProductID&quot;) errMsg += ERR_REQUIRED_COLUMN_NAME + &quot;ProductID<BR>&quot;;
		if (colNames[quantityIndex] != &quot;Quantity&quot;) errMsg += ERR_REQUIRED_COLUMN_NAME + &quot;Quantity<BR>&quot;;
		if (colNames[priceIndex] != &quot;Price&quot;) errMsg += ERR_REQUIRED_COLUMN_NAME + &quot;Price<BR>&quot;;
		if (colNames[totalIndex] != &quot;Total&quot;) errMsg += ERR_REQUIRED_COLUMN_NAME + &quot;Total<BR>&quot;;
	}
	else { // if cart doesn't exist in session, validate input array lengths and presence of reqiured columns
		if (this.numCols != this.colComputed.length) errMsg += ERR_INCONSISTENT_ARRAY_LENGTH;
		
		var bProductID = false, bQuantity = false, bPrice = false, bTotal = false;

		for (var j = 0; j < colNames.length; j++) {
			if (colNames[j] == &quot;ProductID&quot;) bProductID = true;
			if (colNames[j] == &quot;Quantity&quot;) bQuantity= true;
			if (colNames[j] == &quot;Price&quot;) bPrice = true;
			if (colNames[j] == &quot;Total&quot;) bTotal = true;
		}
		if (!bProductID) errMsg += ERR_REQUIRED_COLUMN_NAME + &quot;ProductID<BR>&quot;;
		if (!bQuantity) errMsg += ERR_REQUIRED_COLUMN_NAME + &quot;Quantity<BR>&quot;;
		if (!bPrice) errMsg += ERR_REQUIRED_COLUMN_NAME + &quot;Price<BR>&quot;;
		if (!bTotal) errMsg += ERR_REQUIRED_COLUMN_NAME + &quot;Total<BR>&quot;;
	}
	
	if (errMsg != &quot;&quot;) {
		Response.Write(msg + &quot;<BR>&quot;);
		Response.Write(errMsg + &quot;<BR>&quot;);
		Response.End();
	}
}

function VBConstuctCart(Name, cookieLifetime, vbArrColNames, vbArrColComputed){
	var myObj;
	var a = new VBArray(vbArrColNames);
	var b = new VBArray(vbArrColComputed);
	eval(&quot;myObj = new UC_ShoppingCart(Name, cookieLifetime, a.toArray(), b.toArray())&quot;);
	return myObj;
}
</SCRIPT>
<SCRIPT LANGUAGE=vbscript runat=server NAME=&quot;UC_CART&quot;>
Function GetCookieExp(expDays) 
 	vDate = DateAdd(&quot;d&quot;, CInt(expDays), Now())
 	GetCookieExp = CStr(vDate)
End Function
</SCRIPT>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT NAME=&quot;UC_CART&quot;>
function DoNumber(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
	DoNumber = FormatNumber(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
End Function

function DoCurrency(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
	DoCurrency = FormatCurrency(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
End Function

function DoDateTime(str, nNamedFormat, nLCID)
	dim strRet
	dim nOldLCID

	strRet = str
	If (nLCID > -1) Then
		oldLCID = Session.LCID
	End If

	On Error Resume Next

	If (nLCID > -1) Then
		Session.LCID = nLCID
	End If

	If ((nLCID < 0) Or (Session.LCID = nLCID)) Then
		strRet = FormatDateTime(str, nNamedFormat)
	End If
										
	If (nLCID > -1) Then
		Session.LCID = oldLCID
	End If			
										
	DoDateTime = strRet
End Function

function DoPercent(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
	DoPercent = FormatPercent(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
End Function							

function DoTrim(str, side)
	dim strRet
	strRet = str

	If (side = &quot;left&quot;) Then
		strRet = LTrim(str)
	ElseIf (side = &quot;right&quot;) Then
		strRet = RTrim(str)
	Else
		strRet = Trim(str)
	End If
	DoTrim = strRet
End Function
</SCRIPT>
<%
UC_CartColNames=Array(&quot;ProductID&quot;,&quot;Quantity&quot;,&quot;Name&quot;,&quot;Description&quot;,&quot;Price&quot;,&quot;Total&quot;)
UC_ComputedCols=Array(&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;Price&quot;)
set UCCart1=VBConstuctCart(&quot;UCCart&quot;,30,UC_CartColNames,UC_ComputedCols)
UCCart1__i=0
%>
<%
UC_updateAction = CStr(Request(&quot;URL&quot;))
If (Request.QueryString <> &quot;&quot;) Then
  UC_updateAction = UC_updateAction & &quot;?&quot; & Request.QueryString
End If
If (Request.Form(&quot;text_quantity&quot;).Count > 0) Then
  UCCart1.Update(&quot;text_quantity&quot;)
  If (&quot;&quot; <> &quot;&quot;) Then
    Response.Redirect(&quot;&quot;)
  End If
End If
%>
<%
UC_EmptyCart = CStr(Request.ServerVariables(&quot;URL&quot;)) & &quot;?UC_EmptyCart=1&quot;
If (CStr(Request(&quot;UC_EmptyCart&quot;)) = &quot;1&quot;) Then
  UCCart1.Destroy()
  UC_redirectPage = &quot;products.asp&quot;
  ' redirect with URL parameters (remove the &quot;UC_EmptyCart&quot; query param).
  if (UC_redirectPage = &quot;&quot;) Then UC_redirectPage = CStr(Request.ServerVariables(&quot;URL&quot;))
  If (InStr(1, UC_redirectPage, &quot;?&quot;, vbTextCompare) = 0 And Request.QueryString <> &quot;&quot;) Then
    newQS = &quot;?&quot;
    For Each Item In Request.QueryString
      If (Item <> &quot;UC_EmptyCart&quot;) Then
        If (Len(newQS) > 1) Then newQS = newQS & &quot;&&quot;
        newQS = newQS & Item & &quot;=&quot; & Server.URLencode(Request.QueryString(Item))
      End If
    Next
    if (Len(newQS) > 1) Then UC_redirectPage = UC_redirectPage & newQS
  End If
  Response.Redirect(UC_redirectPage)
End If
%>
<% If UCCart1.GetItemCount() <= 0 Then Response.Redirect(&quot;products.asp&quot;) %>
<% ' Set totals and number of items to Cookies Robert Paddock 22/02/2001

Response.Cookies(&quot;cart_totals&quot;)(&quot;Num_items&quot;) = (UCCart1.GetItemCount())
Response.Cookies(&quot;cart_totals&quot;)(&quot;total&quot;) = (UCCart1.GetColumnTotal(&quot;Total&quot;))

%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<% For UCCart1__i=0 To UCCart1.GetItemCount()-1 %>
<FORM name=&quot;cart_form&quot; method=&quot;post&quot; action=&quot;<%=UC_updateAction%>&quot;>
  <table width=&quot;75%&quot; align=&quot;center&quot;>
    <tr> 
      <td><b>Item</b></td>
      <td><b>Description</b></td>
      <td><b>Price</b></td>
      <td><b>Quantity</b></td>
      <td><b>Total</b></td>
    </tr>
    <tr> 
      <td><%=(UCCart1.GetColumnValue(&quot;ProductID&quot;,UCCart1__i))%></td>
      <td><%=(UCCart1.GetColumnValue(&quot;Description&quot;,UCCart1__i))%></td>
      <td><%= FormatCurrency((UCCart1.GetColumnValue(&quot;Price&quot;,UCCart1__i)), 2, -2, -2, -2) %></td>
      <td> 
        <input type=&quot;text&quot; name=&quot;text_quantity&quot; value=&quot;<%=(UCCart1.GetColumnValue(&quot;Quantity&quot;,UCCart1__i))%>&quot; size=&quot;5&quot; maxlength=&quot;5&quot;>
      </td>
      <td><%= FormatCurrency((UCCart1.GetColumnValue(&quot;Total&quot;,UCCart1__i)), 2, -2, -2, -2) %></td>
    </tr>
    <tr> 
      <td>&nbsp; 
        <input type=&quot;checkbox&quot; name=&quot;remove&quot; value=&quot;1&quot;
 onClick=&quot;document.cart_form.quantity<%If UCCart1.GetItemCount() > 1 then Response.Write(&quot;[&quot; & UCCart1__i & &quot;]&quot;)%>.value='0',submit()&quot;>
      </td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td> 
        <input type=&quot;submit&quot; name=&quot;Update Cart&quot; value=&quot;Update Cart&quot;>
      </td>
      <td><A HREF=&quot;<%=UC_EmptyCart%>&quot;>Empty 
        Cart</A></td>
      <td><a href=&quot;products.asp&quot;>Shop More</a></td>
      <td colspan=&quot;2&quot;><b>Grand Total:<%= FormatCurrency((UCCart1.GetColumnTotal(&quot;Total&quot;)), 2, -2, -2, -2) %></b></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan=&quot;2&quot;>&nbsp;</td>
    </tr>
  </table>
</FORM>
<% Next 'UCCart1__i %>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top