Attempting to adapt Nopcart to custom functionality

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

Moderators: Koibito, Stefko, Randy

Attempting to adapt Nopcart to custom functionality

Postby dsmithhfx » Mon Oct 25, 2010 3:58 pm

Hi,

I am attempting to adapt nopcart.js to a client's desired shopping cart functionality. In a nutshell this functionality is as follows:

1. Client interactions during the ordering portion need to happen on the same page, without going back and forth between popups or shopping cart pages. The client enters desired quantities in a field associated with each product (there are only three), with a running order total (for all products) displayed (no shipping or tax added). See attached screen grab of this form for a better idea of what I'm aiming for:
nopcart-customcart.gif
Inline shopping cart with iframe indicated
(6.77 KiB) Downloaded 64 times


2. When all product quantities are entered, the user submits this data by clicking a "Go to checkout" button. This goes to a separate, checkout page (still on client's site).

3. The user enters billing and shipping address on this page, then submits it to the payment gateway, which is on an external site. Data transferred to the gateway include (only) items, quantities, and user's address(es); users enter credit card numbers etc. on the external payment gateway site.
---

So far I have managed to replicate a limited subset of nopcart functionality, by having AddToCart(); function submitted to an iframe, that is supposed to display the running total and Go to checkout button as described in (2) above.

However I'm having a problem with the cookie. It is not receiving the submitted info and thus not displaying the running total in the frame. When I open the frame in its own window, the url displays the submitted info (e.g., "inlinecart.html?QUANTITY=1&PRICE=65.00&NAME=You+Turn&ID_NUM=FPP1&SHIPPING=0"), however the cookie is only showing contents like, "%7C1%7C0.00%7C%7C0.00%7C", instead of (e.g.) "FPP1%7C1%7C59.95%7CThanksgiving%20Pumpkin%20Pack%7C14.95%7C", in cookies written by the supplied "samplesite". Another problem is that the cookie is not being incremented by order changes, but a new cookie is written each time a quantity field is modified. The per-item form code I've written is as follows:

Code: Select all
                  <form action="inlinecart.html" target="inlinecart" name="brighteyes" onSubmit="AddToCart(this);">
                     <input type=text size=3 maxlength=3 name=QUANTITY onChange='this.value=CKquantity(this.value);AddToCart(this);this.form.submit();' value="0">
                     <input type=hidden name=PRICE value="65.00">
                     <input type=hidden name=NAME value="Bright Eyes">
                     <input type=hidden name=ID_NUM value="FPP2">
                     <input type=hidden name=SHIPPING value="0">
                  </form>


The page "inlinecart.html" calls my custom function, "ManageInlineCart();", which as mentioned is a simplified version of the original ManageCart(); function (e.g., with tax & shipping stuff removed), and drawing elements with CSS rather than tables.

I'm guessing I've gone overboard in my modifications and thus crippled the cookie function. Here's the function in its present state, and I wonder if someone can spot where the problem lies, or can suggest a better way of doing this?

Code: Select all
function ManageInlineCart( ) {
    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)

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
   //original code deleted see 561 - 572 ^^^ 102010

   if ( iNumberOrdered == 0 ) {
   // trying to restore cookie functionality from orig ManageCart() 102510
   // still no need to draw any of this stuff to the page though
   }   

   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[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 ( AppendItemNumToOutput ) { //restored to line 752 102510
         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 ) {
         strOutput += "<div class=\"nowrap totals\" style=\"margin:20px 0 0 0;\">";
         strOutput += "<div style=\"float:left;width:110px;text-align:left;\">Subtotal</div>";
         strOutput += "<div style=\"float:left;width:110px;text-align:right;\">" + strTotal + "</div>";
         strOutput += "</div>";
         strOutput += "<div class=\"nowrap totals\">";
         strOutput += "<div style=\"float:left;width:110px;text-align:left;\">Shipping</div>";
         strOutput += "<div style=\"float:left;width:110px;text-align:right;\">FREE</div>";               
         strOutput += "</div>";
         strOutput += "<div class=\"nowrap totals\" style=\"width:220px;padding:6px 0 30px 0;border-top:1px solid #787878;\">";
         strOutput += "<div style=\"float:left;width:150px;text-align:left;\">Total (excluding taxes)</div>";
         strOutput += "<div style=\"float:left;width:70px;text-align:right;\">" + strTotal + "</div>";               
         strOutput += "</div>";
         // removed update qty, shipping & remove from cart stuff (this function only), see lines 608-618 102010
      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
   g_TotalCost = (fTotal + fShipping + fTax);

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


Thanks for any help!
dsmithhfx
WebMaster
 
Posts: 2
Joined: Mon Oct 25, 2010 3:12 pm

Return to Help: Cart / General

Who is online

Users browsing this forum: No registered users and 3 guests