Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Modifica script estensione dreamweaver carrello elettronico

    Scusate la mia ignoranza, ma purtroppo non ne posso fare a meno.
    Questo script qua sotto è uno script che crea un'estensione di dreamweaver per gestire il carrello dell'ecommerce.
    Lo script funziona perfettamente solo che necessito di modificare il valore chiamato "ShippingCost".
    Attualmente questo valore è 0 e mi rimane sempre tale....
    Ad un certo punto del codice c'è questa scritta "this.ShippingCost = 0.00" ho provato li a mettere un valore per esempio 10.00 ma il risultato è sempre zero.
    Per quel poco che ahimè so e ci capisco dovrebbe leggere i valori da un cookie???
    Sapete aiutarmi e dirmi come posso mettere il valore 10 allo shipping cost?
    Grazie a tutti.....

    <script language="javascript" runat="server">
    function UltraCartVB(Name, xmlPath)
    {
    return new UltraCart(Name, xmlPath);
    }
    // Constructor
    function UltraCart(Name, xmlPath)
    {
    this.Name = Name;
    // Main Cart Column Constants
    this.PRODUCTID = "ProductID";
    this.QUANTITY = "Quantity";
    this.PRICE = "Price";
    this.TOTAL = "Total";

    this.COOKIEBLOCKDEL = "#B#";
    this.COOKIECOLDEL = "#C#"
    this.COOKIEROWDEL = "#R#"
    /*
    // Line Item Discount Constants
    this.DISCOUNTRATE = "DiscountRate";
    this.DISCOUNTTHRESHOLD = "DiscountThreshold";
    this.DISCOUNTVALUE = "DiscountValue";
    this.DISCOUNTTYPE = "DiscountType";

    // Group Discount Constants
    this.GROUPDISCOUNTCATEGORY = "GroupDiscCategory";
    this.GROUPDISCOUNTRATE = "GroupDiscRate";
    this.GROUPDISCOUNTTHRESHOLD = "GroupDiscThreshold";
    this.GROUPDISCOUNTVALUE = "GroupDiscValue";
    this.GROUPDISCOUNTTYPE = "GroupDiscType";
    */
    this.ShippingCost = 0.00;
    this.ShippingMethod = "";

    this.TaxStateProvince = 0.00;
    this.TaxCountry = 0.00;
    this.TaxLocalePostal = 0.00;
    this.SumTax = 0.00;

    this.DiscountGroup = 0.00;
    this.DiscountLineItem = 0.00;
    this.Discount = 0.00;
    this.SumDiscount = 0.00;
    this.Subtotal = 0.00;
    this.GrandTotal = 0.00;

    // Load Cart Definitions
    var objXMLDoc;
    try
    {
    objXMLDoc = Server.CreateObject("Msxml2.DOMDocument"); // Msxml2.DOMDocument.4.0 XML v4 call
    }
    catch(e)
    {
    this.Assert(false , "You need XML services installed on this server...See http:\/\/www.microsoft.com/xml for more information..." );
    }
    objXMLDoc.async = false;
    objXMLDoc.resolveExternals = false;
    objXMLDoc.load(xmlPath);
    this.Assert(!objXMLDoc.parseError.errorCode , "Constructor: " + objXMLDoc.parseError.reason);

    // Load Cart Settings
    var objNodeList = objXMLDoc.documentElement.getElementsByTagName("Ca rt");
    for( var iCol=0; iCol < objNodeList.length; iCol++)
    {
    if(objNodeList[iCol].getAttribute("name") == this.Name)
    {
    var objXMLDocCart = objNodeList[iCol];
    break;
    }
    }

    this.CookieLifeTime = parseInt(objXMLDocCart.getAttribute("CookieLifeTim e"));
    this.useComputeTotalsAdvanced = objXMLDocCart.getAttribute("UseComputeTotalsAdvanc ed");
    Session.LCID = objXMLDocCart.getAttribute("LCID");
    var nodeList = objXMLDocCart.selectSingleNode("CartColumns").chil dNodes;

    this.numCols = nodeList.length;
    this.CartDataTable = new Array(this.numCols);
    this.cartColNames = new Array(this.numCols);
    this.cartColComputed = new Array(this.numCols);
    this.cartColIdentifier = new Array(this.numCols);
    this.cartColType = new Array(this.numCols);

    for (var i=0; i<this.numCols; i++)
    {
    var nodeItem = nodeList.item(i);
    this.cartColNames[i] = nodeItem.getAttribute("name");
    this.cartColComputed[i] = nodeItem.getAttribute("computeby");
    this.cartColIdentifier[i] = nodeItem.getAttribute("identifier");
    this.cartColType[i] = nodeItem.getAttribute("type");

    this.CartDataTable[i] = new Array();
    }
    objXMLDoc = null; // free up

    if (Session(this.Name) != null)
    {
    // load properties with exsiting values
    this.CartDataTable = Session(this.Name).CartDataTable;

    this.ShippingCost = Session(this.Name).ShippingCost;
    this.ShippingMethod = Session(this.Name).ShippingMethod;

    this.TaxStateProvince = Session(this.Name).TaxStateProvince;
    this.TaxCountry = Session(this.Name).TaxCountry;
    this.TaxLocalePostal = Session(this.Name).TaxLocalePostal;

    this.Discount = Session(this.Name).Discount;
    }
    else
    {
    if(this.CookieLifeTime != -1) // can we restore from cookie
    {
    var cookieName = this.GetCookieName();
    var cookieStr = Request.Cookies(cookieName)("DT");
    if (cookieStr != null && String(cookieStr) != "undefined" && cookieStr != "")
    {
    this.ShippingCost = Request.Cookies(cookieName)("ShippingCost");
    this.ShippingMethod = Request.Cookies(cookieName)("ShippingMethod");
    this.TaxStateProvince = Request.Cookies(cookieName)("TaxStateProvince");
    this.TaxCountry = Request.Cookies(cookieName)("TaxCountry");
    this.TaxLocalePostal = Request.Cookies(cookieName)("TaxLocalePostal");
    this.Discount = Request.Cookies(cookieName)("Discount");
    this.DeserializeRows(cookieStr, this.COOKIECOLDEL, this.COOKIEROWDEL);
    }
    }
    }
    this.ComputeTotals();
    }

    UltraCart.prototype.Assert = ultracart_Assert;
    function ultracart_Assert(bool, msg)
    {
    if (!bool)
    {
    Response.Write("

    An error occurred in the UltraCart:
    " + msg + "
    ");
    Response.End();
    }
    }

    UltraCart.prototype.VbToJsArray = ultracart_VbToJsArray;
    function ultracart_VbToJsArray(a)
    {
    if (a!=null && a.length==null)
    {
    a = new VBArray(a);
    a = a.toArray();
    }
    return a;
    }

    UltraCart.prototype.vbCartDataTable = ultracart_vbCartDataTable;
    function ultracart_vbCartDataTable(iCol,iRow,setValue)
    {
    if(String(setValue) != "undefined")
    {
    this.CartDataTable[iCol][iRow] = setValue;
    }
    else
    {
    return this.CartDataTable[iCol][iRow];
    }
    }

    UltraCart.prototype.Persist = ultracart_persist;
    function ultracart_persist()
    {
    var sObj = new Object();

    sObj.CartDataTable = this.CartDataTable;
    sObj.ShippingCost = this.ShippingCost;
    sObj.ShippingMethod = this.ShippingMethod;
    sObj.TaxStateProvince = this.TaxStateProvince;
    sObj.TaxCountry = this.TaxCountry;
    sObj.TaxLocalePostal = this.TaxLocalePostal;
    sObj.Discount = this.Discount;

    Session(this.Name) = sObj;
    var sObj = null;

    if(this.CookieLifeTime != -1)
    {
    this.SetCookie();
    }
    }

    UltraCart.prototype.Destroy = ultracart_destroy;
    function ultracart_destroy()
    {
    Session.Contents.Remove(this.Name)
    if(this.CookieLifeTime != -1)
    {
    this.DestroyCookie();
    }
    }

    UltraCart.prototype.DeleteItemsWithNoQuantity = ultracart_DeleteItemsWithNoQuantity;
    function ultracart_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++)
    {
    // Remove quantities that are zero, not a number or any specific row specified in the Query collection.
    if ( isNaN(this.CartDataTable[indexQuantity][iRow]) != true)
    {
    if ( this.CartDataTable[indexQuantity][iRow] != 0)
    {
    if ( String(Request.QueryString("RemoveCartItem")) != iRow)
    {
    // copy row to temp table
    for (var iCol=0; iCol<this.numCols; iCol++)
    {
    tmpSC[iCol][iDest] = this.CartDataTable[iCol][iRow];
    }
    iDest++;
    }
    }
    } // isNaN
    }
    this.CartDataTable = tmpSC;
    }

    UltraCart.prototype.GetItemCount = ultracart_getitemcount;
    function ultracart_getitemcount()
    {
    return this.CartDataTable[0].length;
    }

    UltraCart.prototype.ComputeItemTotalsAdvanced = ultracart_ComputeItemTotalsAdvanced;
    function ultracart_ComputeItemTotalsAdvanced(iRow)
    {
    var re = /\[(\w*)\]/ig;
    for (var iCol=0; iCol<this.numCols; iCol++)
    {
    var colToCompute = this.cartColComputed[iCol];
    if (colToCompute != "")
    {
    var regArray = colToCompute.match(re);
    for(var i=0; i<regArray.length; i++)
    {
    var colName = regArray[i].replace(/\[|\]/ig,"");
    colToCompute = colToCompute.replace(regArray[i],"this.CartDataTable[" + this.GetIndexOfColName(colName) + "][iRow]")
    }

    this.CartDataTable[iCol][iRow] = eval(colToCompute);
    }
    }
    }

    UltraCart.prototype.ComputeItemTotals = ultracart_ComputeItemTotals;
    function ultracart_ComputeItemTotals(iRow)
    {
    var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
    var qty = parseFloat(this.CartDataTable[indexQuantity][iRow]);
    for (var iCol=0; iCol<this.numCols; iCol++)
    {
    var colToCompute = this.cartColComputed[iCol];
    if (colToCompute != "")
    {
    indexColToCompute = this.GetIndexOfColName(colToCompute);
    this.CartDataTable[indexColToCompute][iRow] = this.CartDataTable[indexColToCompute][iRow] * 1; // do this to display currency correctly for some european users
    this.CartDataTable[iCol][iRow] = parseFloat(this.CartDataTable[indexColToCompute][iRow]) * qty;
    }
    }
    }

    UltraCart.prototype.UpdateTotals = ultracart_UpdateTotals;
    function ultracart_UpdateTotals()
    {
    if(this.useComputeTotalsAdvanced)
    {
    for (var iRow=0; iRow< this.GetItemCount(); iRow++)
    {
    this.ComputeItemTotalsAdvanced(iRow);
    }
    }
    else
    {
    for (var iRow=0; iRow< this.GetItemCount(); iRow++)
    {
    this.ComputeItemTotals(iRow);
    }
    }
    }

  2. #2
    UltraCart.prototype.ComputeTotals = ultracart_ComputeTotals;
    function ultracart_ComputeTotals()
    {
    this.DeleteItemsWithNoQuantity();
    this.UpdateTotals();
    // if(this.isLineItemDiscountValid()) this.UpdateDiscounts();
    // if(this.isLineItemTaxValid()) this.UpdateLineItemTax();
    // this.GroupDiscount()
    this.Subtotal = this.GetColumnTotal("Total");
    this.SumTax = (this.TaxLocalePostal + this.TaxStateProvince + this.TaxCountry);
    this.SumDiscount = (this.DiscountGroup + this.DiscountLineItem + this.Discount);
    this.GrandTotal = this.Subtotal + this.ShippingCost + this.SumTax - this.SumDiscount;
    this.Persist();
    }

    UltraCart.prototype.UpdateQuantities = ultracart_UpdateQuantities;
    function ultracart_UpdateQuantities(formElementName)
    {
    var items = new Enumerator(Request.Form(formElementName));
    var j = 0;
    var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
    while(!items.atEnd())
    {
    var qty = parseFloat(items.item());
    // Remove item if not a number or less than zero or if it was explicitly removed
    if (isNaN(qty) || qty < 0 || String(Request.Form("RemoveCartItem" + j)) != "undefined" )
    {
    this.CartDataTable[indexQuantity][j] = 0;
    }
    else
    {
    this.CartDataTable[indexQuantity][j] = qty;
    }
    j++;
    items.moveNext();
    }

    this.ComputeTotals();
    }

    UltraCart.prototype.GetIndexOfColName = ultracart_GetIndexOfColName;
    function ultracart_GetIndexOfColName(colName)
    {
    var retIndex = -1;
    for (var i=0; i<this.numCols; i++)
    {
    if (this.cartColNames[i] == colName)
    {
    retIndex = i;
    break;
    }
    }
    return retIndex;
    }

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

    UltraCart.prototype.GetColumnTotal = ultracart_GetColumnTotal;
    function ultracart_GetColumnTotal(colName)
    {
    var colTotal = 0.00;
    index = this.GetIndexOfColName(colName);
    this.Assert(index >= 0, "GetColumnValue: Could not find column \"" + colName + "\" in the cart");
    for (var i=0; i<this.CartDataTable[index].length; i++)
    {
    colTotal += parseFloat(this.CartDataTable[index][i]);
    }
    return colTotal;
    }

    UltraCart.prototype.FindItem = ultracart_FindItem;
    function ultracart_FindItem(values)
    {
    var newRow = -1;
    for(var iRow=0; iRow<this.GetItemCount(); iRow++)
    {
    found = true; // assume found
    for (var iCol=0; iCol<this.numCols; iCol++)
    {
    if(this.cartColIdentifier[iCol] != "N")
    {
    if(this.CartDataTable[iCol][iRow] != values[iCol])
    {
    found = false;
    break;
    }
    }
    }
    if(found)
    {
    newRow = iRow;
    break;
    }
    }
    return newRow;
    }

    UltraCart.prototype.CleanRedirect = ultracart_CleanRedirect;
    function ultracart_CleanRedirect(redirectToPage)
    {
    if (redirectToPage == "") redirectToPage = Request.ServerVariables("URL");
    if (String(redirectToPage).indexOf("?") == -1 && Request.QueryString != "")
    {
    var newQS = "?";
    // Remove our unwanted query parameters.
    var re = /AddToCartID|EmptyCart|RemoveCartItem|UC_SaveToTabl e/ig;
    for (var items=new Enumerator(Request.QueryString); !items.atEnd(); items.moveNext())
    {
    if ( !re.test(items.item()) )
    {
    if (newQS.length > 1) newQS += "&";
    newQS += items.item() + "=" + Server.URLencode(Request.QueryString(items.item()) );
    }
    }
    re = null;
    if (newQS.length > 1) redirectToPage += newQS;
    }
    Response.Redirect(redirectToPage);
    }

    UltraCart.prototype.AddItem = ultracart_AddItem;
    function ultracart_AddItem(bindingColumns, bindingValues, incrementDupItems, redirectToPage, redirectOnDup)
    {
    var bindingColumns = this.VbToJsArray(bindingColumns);
    var bindingValues = this.VbToJsArray(bindingValues);

    // sort cart columns
    var b = new Array(this.numCols);
    for(var i=0; i<this.numCols; i++)
    {
    var index = this.GetIndexOfColName(bindingColumns[i]);
    b[index] = bindingValues[i];
    }

    bindingColumns = null;
    bindingValues = null;
    var values = b;

    var newRow = this.FindItem(values);
    if (newRow == -1)
    {
    // add new item
    newRow = this.GetItemCount();
    for (var iCol=0; iCol<this.numCols; iCol++)
    {
    this.CartDataTable[iCol][newRow] = values[iCol];
    }
    }
    else if (incrementDupItems)
    {
    // increment
    var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
    this.CartDataTable[indexQuantity][newRow] = parseFloat(this.CartDataTable[indexQuantity][newRow]) + parseFloat(values[indexQuantity]);
    if (isNaN(this.CartDataTable[indexQuantity][newRow]))
    {
    this.CartDataTable[indexQuantity][newRow] = 1;
    }
    }
    else
    {
    // redirect to dup page
    redirectToPage = redirectOnDup;
    }
    this.ComputeTotals(); // not needed if redirect because reload will recompute
    this.CleanRedirect(redirectToPage);
    }

    UltraCart.prototype.SerializeRows = ultracart_SerializeRows;
    function ultracart_SerializeRows(colDelim, rowDelim)
    {
    var serialCart = "";
    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.CartDataTable[iCol][iRow];
    }
    }
    return serialCart;
    }

    UltraCart.prototype.DeserializeRows = ultracart_DeserializeRows;
    function ultracart_DeserializeRows(serialCart, colDelim, rowDelim)
    {
    var cartRows = String(serialCart).split(rowDelim)
    for (iRow = 0; iRow < Rows.length; iRow++)
    {
    if (cartRows[iRow] != "undefined" && cartRows[iRow] != "")
    {
    var cartCols = cartRows[iRow].split(colDelim);
    for (var iCol = 0; iCol<cartCols.length; iCol++)
    {
    this.CartDataTable[iCol][iRow] = cartCols[iCol];
    }
    }
    }
    }

    UltraCart.prototype.SetCookie = ultracart_SetCookie;
    function ultracart_SetCookie()
    {
    var cookieName = this.GetCookieName();
    Response.Cookies(cookieName)("ShippingCost") = this.ShippingCost;
    Response.Cookies(cookieName)("ShippingMethod") = this.ShippingMethod;
    Response.Cookies(cookieName)("TaxStateProvince") = this.TaxStateProvince;
    Response.Cookies(cookieName)("TaxCountry") = this.TaxCountry;
    Response.Cookies(cookieName)("TaxLocalePostal") = this.TaxLocalePostal;
    Response.Cookies(cookieName)("Discount") = this.Discount;
    Response.Cookies(cookieName)("Other") = this.Other;
    Response.Cookies(cookieName)("DT") = this.SerializeRows(this.COOKIECOLDEL, this.COOKIEROWDEL);
    if( this.CookieLifeTime > 0)
    {
    Response.Cookies(cookieName).Expires = GetCookieExp(this.CookieLifeTime);
    }
    }

    UltraCart.prototype.GetCookieName = ultracart_GetCookieName;
    function ultracart_GetCookieName()
    {
    return (Request.ServerVariables("SERVER_NAME") + this.Name);
    }

    UltraCart.prototype.DestroyCookie = ultracart_DestroyCookie;
    function ultracart_DestroyCookie()
    {
    var CookieName = this.GetCookieName();
    Response.Cookies(CookieName) = "";
    Response.Cookies(CookieName).Expires = "1/1/90";
    }

    UltraCart.prototype.BuildInsertColumnList = ultracart_BuildInsertColumnList;
    function ultracart_BuildInsertColumnList(uniqueCol, destTableCols)
    {
    var colList = "[" + uniqueCol + "]";
    for (var i = 0; i < destTableCols.length; i++)
    {
    if (destTableCols[i] != "")
    {
    colList += ", [" + destTableCols[i] + "]";
    }
    }
    colList = "(" + colList + ")";
    return colList;
    }

    UltraCart.prototype.BuildInsertValueList = ultracart_BuildInsertValueList;
    function ultracart_BuildInsertValueList(isUniqueColNumeric, uniqueColValue, mappedCartCols, iRow)
    {
    var values;
    if(isUniqueColNumeric)
    {
    values = uniqueColValue;
    }
    else
    {
    values = "'" + uniqueColValue.toString().replace(/'/g, "''") + "'";
    }

    var index;
    for (var iCol=0; iCol<mappedCartCols.length; iCol++)
    {
    index = this.GetIndexOfColName(mappedCartCols[iCol]);

    if (this.cartColType[iCol] != "text")
    {
    this.Assert(!isNaN(this.CartDataTable[index][iRow]), "SaveCart: A non-numeric value was found in the column " + this.cartColNames[iCol] + " when the database was only expecting numeric values.");
    values += ", " + this.CartDataTable[index][iRow];
    }
    else
    {
    values += ", '" + (this.CartDataTable[index][iRow]).toString().replace(/'/g, "''") + "'";
    }
    }
    return "(" + values + ")";
    }

    UltraCart.prototype.SaveCart = ultracart_SaveCart;
    function ultracart_SaveCart(adoConn,dbTable,uniqueCol,isUni queColNumeric,uniqueColValue,cartCols,orderDetails ColNames)
    {
    trapError = true; // helps debug errors that maybe caught

    cartCols = this.VbToJsArray(cartCols);
    orderDetailsColNames = this.VbToJsArray(orderDetailsColNames);

    var insertColList = this.BuildInsertColumnList(uniqueCol,orderDetailsC olNames);
    var insertClause = "INSERT INTO " + dbTable + " " + insertColList + " VALUES ";

    var trapSQL = "SQL dump:
    ";
    for (var iRow=0; iRow<this.GetItemCount(); iRow++)
    {
    var valList = this.BuildInsertValueList(isUniqueColNumeric,uniqu eColValue,cartCols,iRow);
    var sqlInsertStatement = insertClause + valList;

    trapSQL += "[" + iRow + "] " + "
    " + sqlInsertStatement + "
    ";

    if(trapError)
    {
    try
    {
    adoConn.Execute(sqlInsertStatement,"", 1);
    }
    catch(e)
    {
    this.SaveError(e, trapSQL);
    return 1;
    }
    }
    else
    {
    adoConn.Execute(sqlInsertStatement,"", 1);
    }
    }
    return 0;
    }

    UltraCart.prototype.SaveError = ultracart_SaveError;
    function ultracart_SaveError(e,sql)
    {
    Session("UC_ErrorNumber") = (e.number & 0xFFFF);
    Session("UC_Description") = e.description;
    Session("UC_SQLStatement") = sql;
    }
    </script>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.