is possible it to have this script refresh

Completed modifications to the NOP Shopping Cart. Additions, modifications, and more.

Moderators: Koibito, Stefko, Randy, Rosey

is possible it to have this script refresh

Postby kc giftware » Fri Mar 11, 2005 8:15 pm

Add this code to your page to display total number and price of items in the shopping cart:
Code:
<script language="javascript">
if ( Cart_is_empty()) {
document.write('Your cart is empty.');
} else {
document.write('In your cart:<p>');
Print_total_products(true);
document.write(', ');
Print_total(true);
document.write('<p>Applicable shipping and taxes extra.<p>');
document.write('<a href="managecart.html">View Cart</a>');
}
</script>

Add to very bottom of nopcart.js:
Code:
//---------------------------------------------------------------------||
// FUNCTION: Print_total ||
// PARAMETERS: true/false if you want MonetarySymbol added to string ||
// RETURNS: Total cost currently racked up by shopper ||
// PURPOSE: Aesthetics ||
//---------------------------------------------------------------------||
function Print_total(bSymbol) {
var strOutput = ""; //String to be written to page
var strTotal = ""; //Total cost formatted as money
var fTotal = 0;
var iNumberOrdered = 0; //Number of products ordered


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


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

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

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

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

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

}

strTotal = moneyFormat(fTotal);
strOutput+=strTotal;
if ( bSymbol )
strOutput = MonetarySymbol + strOutput
document.write(strOutput);

}

//---------------------------------------------------------------------||
// FUNCTION: Print_total_products ||
// PARAMETERS: true/false if you want "item(s)" added to string ||
// RETURNS: Total cost currently racked up by shopper ||
// PURPOSE: Aesthetics ||
//---------------------------------------------------------------------||
function Print_total_products(bVerbose) {
var strOutput = ""; //String to be written to page
var fTotal = 0;
var iNumberOrdered = 0; //Number of products ordered


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


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

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

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

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

fTotal += (parseInt(fields[1]));

}

strOutput+=fTotal;
if ( bVerbose ) {
if (fTotal == 1) {
strOutput+=" item"
}
else {
strOutput+=" items"
}
}
document.write(strOutput);

}

//---------------------------------------------------------------------||
// FUNCTION: Cart_is_empty ||
// PARAMETERS: none ||
// RETURNS: Total true if cart is empty, false otherwise ||
// PURPOSE: Aesthetics ||
//---------------------------------------------------------------------||
function Cart_is_empty( ) {
iNumInCart = GetCookie("NumberOrdered");

if ( iNumInCart == null ) iNumInCart = 0;

if ( iNumInCart == 0 ) return true;

return false;

}

Note that the text in the "code" box above may appear to wrap at the end of long lines. If you copy and paste the code from the box above into your nopcart.js file the lines should be just fine.



I've used this script and it works fine....there are a few questions....
I modified a copy of the nopcart.js to reflect these changes and renamed the js file as nopcart2.js I have a seperate directory on my web site called /cart and in that directory have added the nopcart.js file and the two files managecart.html and checkout.html on each page that I sell a product I have added the two scripts in the head file nopcart.js and language_en.js. In my viewcart form I simply point the getfrom cart this.form to /cart/nopcart.js file and that seems to work fine. Now after the modifications to the .js script I added nopcart2.js file to the /cart directory and changed the script on each page in the header to
<script="nopcart2.js>. this seems ok and works fine......BUT when I add this to the managecart.html file in /cart directory I get "script errors on this page" when I revert back to nopcart.js it works fine and displays the cart. Now my question is......do I need to have nopcart2.js AND nopcart.js in the /cart directory for this mod to work???? If not what am I doing wrong?
Thanks for all the help... I find this forum very helpful.
Charlie aks (kc giftware)
kc giftware
 
Posts: 10
Joined: Thu Mar 03, 2005 2:28 am

modified script

Postby woudstra » Sat Mar 26, 2005 10:14 pm

When you use a modified version of the Nopcart script, use only THAT version, not both the modified and the unmodifies. You can rename your modification, so you do not get confused later on. You need to know what version you have used. But do not use many versions in 1 shop.

You can put your scripts in the same folder as everything else, but you do not have to. Just use the right path to the scripts, in your HTML pages. How else can they be found by the visitors browser?
woudstra
 
Posts: 32
Joined: Mon Aug 02, 2004 7:14 pm

re: modified nopcart.js

Postby kc giftware » Sun Mar 27, 2005 4:22 am

woudstra,
Thanks for the help, I'll try pointing everything to the new modified .js and check all my html pages. Sometimes the little things can keep things working right!
Thanks again,
Charlie
kc giftware
 
Posts: 10
Joined: Thu Mar 03, 2005 2:28 am

working script version.

Postby woudstra » Sat Apr 09, 2005 7:52 pm

Did this help? If not, I have a working scriptversion that does what you need. I have the code for a working shop in HTML and Javascript, with the totals on all productpages. You may copy it, and add your own page layout.

The shop works fine, but I also would like to have a version using a chekout.PHP form. I cannot get it the example PHP script downloaded from the NOPcart website working: it does nothing.

I have tried several PHP formmailers. They do send name, address and other formfields, but not the CheckoutCard() value.

I have seen you have a PHP form that does function.
Maybe you can help me with that?
woudstra
 
Posts: 32
Joined: Mon Aug 02, 2004 7:14 pm


Return to Modifications

Who is online

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