Giter Club home page Giter Club logo

simplecart-js's Introduction

#simpleCart(js)

No databases, no programming, no headaches. A simple javascript shopping cart that you can setup in minutes. It's lightweight, fast, simple to use, and completely customizable. All you need to know is basic HTML.

Copyright (c) 2012 Brett Wejrowski Dual licensed under the MIT or GPL licenses.

##This is version 3

If you would like to use an older version, you can use a different branch or see them in the downloads area

v3.0.5 changelog

  • moved beforeCheckout event and form sending inside of .checkout() to keep dry
  • added price, shipping, tax formatting for paypal checkout
  • added .submit method to ELEMENT
  • fixed mootools .get and .live bugs

Quick Start

To get started, just add the simpleCart javascript file to your page, and set your PayPal checkout:

<script src="simpleCart.js"></script>
<script>
	simpleCart({
		checkout: { 
			type: "PayPal" , 
			email: "[email protected]" 
		}
	});	
</script>

If you want to change options, like the tax or currency, you can do that as well:

simpleCart({
	checkout: { 
		type: "PayPal" , 
		email: "[email protected]" 
	},
	tax: 		0.075,
	currency: 	"EUR"
});

To sell items, you add them to your "Shelf" by simply adding a few classes to your html:

<div class="simpleCart_shelfItem">
    <h2 class="item_name"> Awesome T-shirt </h2>
    <input type="text" value="1" class="item_Quantity">
    <span class="item_price">$35.99</span>
	<a class="item_add" href="javascript:;"> Add to Cart </a>
</div>

You can use almost any type of html tag, and set any values for the item you want by adding a class of "item_[attrname]". Here is a more complex item with options and images:

<div class="simpleCart_shelfItem">
    <img src="/images/item_thumb.jpg" class="item_thumb" />
    <h2 class="item_name"> Awesome T-shirt </h2>
 	<select class="item_size">
        <option value="Small"> Small </option>
        <option value="Medium"> Medium </option>
        <option value="Large"> Large </option>
    </select>
    <input type="text" value="1" class="item_Quantity">
    <span class="item_price">$35.99</span>
	<a class="item_add" href="javascript:;"> Add to Cart </a>
</div>

Please check out our documentation to see all of the options simpleCart has available!

Version 3 Documentation

A work in progress..... I'm putting it here until we have the new site up so I can put it...well.. there.

##simpleCart(js) Setup/Initialization

simpleCart(js) requires using jQuery, Prototype, or Mootools. No extra configuration is needed as long as one of those libraries is included on the page

You can set/change simpleCart options at any time:

simpleCart({
	option1: "value" ,
	option2: "value2" 
});

Here are the possible options and their default values:

simpleCart({
	
	// array representing the format and columns of the cart, see 
	// the cart columns documentation
	cartColumns: [
		{ attr: "name" , label: "Name" },
		{ attr: "price" , label: "Price", view: 'currency' },
		{ view: "decrement" , label: false },
		{ attr: "quantity" , label: "Qty" },
		{ view: "increment" , label: false },
		{ attr: "total" , label: "SubTotal", view: 'currency' },
		{ view: "remove" , text: "Remove" , label: false }
	],
	
	// "div" or "table" - builds the cart as a table or collection of divs
	cartStyle: "div", 
	
	// how simpleCart should checkout, see the checkout reference for more info 
	checkout: { 
		type: "PayPal" , 
		email: "[email protected]" 
	},
	
	// set the currency, see the currency reference for more info
	currency: "USD",
	
	// collection of arbitrary data you may want to store with the cart, 
	// such as customer info
	data: {},
	
	// set the cart langauge (may be used for checkout)
	language: "english-us",
	
	// array of item fields that will not be sent to checkout
	excludeFromCheckout: [],
	
	// custom function to add shipping cost
	shippingCustom: null,
	
	// flat rate shipping option
	shippingFlatRate: 0,
	
	// added shipping based on this value multiplied by the cart quantity
	shippingQuantityRate: 0,
	
	// added shipping based on this value multiplied by the cart subtotal
	shippingTotalRate: 0,
	
	// tax rate applied to cart subtotal
	taxRate: 0,
	
	// true if tax should be applied to shipping
	taxShipping: false,
	
	// event callbacks 
	beforeAdd				: null,
	afterAdd				: null,
	load					: null,
	beforeSave				: null,
	afterSave				: null,
	update					: null,
	ready					: null,
	checkoutSuccess				: null,
	checkoutFail				: null,
	beforeCheckout				: null
});

##The Shelf

You can make items be available to your users by simple using class names in your html. For any Item you want to be available to be added to the cart, you make a container with a class name of simpleCart_shelfItem. Then add classes to tags inside of that container that have the general form item_[name of field] and simpleCart will use the value or innerHTML of that tag for the cart. For example, if you wanted to sell a T-shirt with 3 different sizes, you can do this:

<div class="simpleCart_shelfItem">
	<h2 class="item_name"> Awesome T-shirt </h2>
	<select class="item_size">
    	<option value="Small"> Small </option>
    	<option value="Medium"> Medium </option>
    	<option value="Large"> Large </option>
	</select>
	<input type="text" value="1" class="item_Quantity">
	<span class="item_price">$35.99</span>
	<a class="item_add" href="javascript:;"> Add to Cart </a>
</div>

Notice here that you can use a select to change options for the item when you add it to the cart. You can also use a text input to change the quantity (or any other field!). These classes will work with any tag, so feel free to use what works best for you. Finally, notice that a tag with the class item_add will have an event listener on its click. So when the contents of that tag are clicked, an item will be added to the cart with the values of each of the tags in the container with the item_something class.

####Some notes: *You will want to always supply a quantity and price. Although the cart won't break if you don't, all the quantities and totals are created from it, so the cart will assign a price of $0 if there is none, and a quantity of 1 if no quantity is provided. *If you are planning on checking out to googleCheckout or paypal, it is a good idea to use a name field *If you use a link for the add to cart button, its a good idea to set the href to "javascript:;"

##Cart Columns

The Cart Columns allow the user to specify how the cart will be formatted and displayed. There is a lot of flexibility here, take a look at the default setup:

simpleCart({
	cartColumns: [
		{ attr: "name" , label: "Name" } ,
		{ attr: "price" , label: "Price", view: 'currency' } ,
		{ view: "decrement" , label: false , text: "-" } ,
		{ attr: "quantity" , label: "Qty" } ,
		{ view: "increment" , label: false , text: "+" } ,
		{ attr: "total" , label: "SubTotal", view: 'currency' } ,
		{ view: "remove" , text: "Remove" , label: false }
	]
});

Each column is represented by an object, the most basic setup simple specifies which attribute to display and how to label the column:

{ attr: "name" , label: "Name" }

There are also some built in 'views' that will create a special column. For example, an 'increment' view:

{ view: "increment" , label: false , text: "+" }

will have a link that increments the quantity. Setting the label:false will hide the label for the view. You can specify the text of the link with that text: attribute.

You can add view: "currency" to format the column as currency (see the currency section on more information on currency formatting).

For more information, please go to simplecartjs.com

simplecart-js's People

Contributors

alex-kovac avatar andrewkvalheim avatar brettwejrowski avatar cybershadow avatar darkchaz avatar dasrecht avatar desmondhume avatar genuino2 avatar napernik avatar patrickchappuis avatar plainlystated avatar ricpersi avatar robrainfall avatar stiucsib86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplecart-js's Issues

Free Shipping Over a Certain Dollar Amount

Hey y'all, I LOVE this shopping cart, and pretty much have it all set in place except for one thing:

I want to offer my customers free shipping if they spend $25 or more on my site (http://lpcustomcreations.com).

I can't figure out how to make the "view cart" page show this. So if the cart total is $25 or more, I want the shipping field to show $0.00. If the cart total is $24.99 or less, I want the shipping field to show $2.99.

Knowing very little about Javascript, I thought one of you awesome ninjas could help me out. Oh, and I have paypal set to work all of this out, I just want the view cart page on my site to reflect what they will see in paypal.

Thanks so much,

Mike

Up/Down Arrows Next to Quantity

Hi,

I'm trying to figure out how you've created the up/down arrows next to quantity in the shopping cart in the demo. I would like to add similar graphics on my own website to replace plus/minus but I don't know how to do it. Could you please help me? Thank you very much for such a great product.

Ovi

Two fixed options on shipping

Hi,

I need a simple cart with the option for US/worldwide fixed shipping cost, does this cart can do that? how to do this?

Best regards

Free Shipping Issue

I set the Flat Rate to 0.00 and that doesn't seem to do anything. By default it seems to add a $1.00 for shipping for each item added to the cart.

If I put this code in for each item it sort of works.

However if they add more than one item it still adds a dollar shipping for each additional item. Where is my error or how do I correct this for free shipping.

Thank you for any help.

size options where each size is a different price

Hello, if anyone's listening out there I'd be glad to know if it's possible to configure simplecart so that each option (like, for example, the "Awesome T-Shirt" small, medium, large) can have a different price returned to the cart. I'm not a javascript coder though I've spent some time looking at all the configuration possibilities and cannot see if what I need is possible with the packaged code. TIA

[Wordpress] Displaying items in cart using onclick method

I'm having an issue using Wordpress 3.0 and the onclick method to add items to the cart. The store items are inside the wordpress loop, and the cart is outside the loop. When I click "add to cart" (for one item) I get two items. One that displays everything perfectly. Along with the first item I get a duplicate item that displays NaN for the price, and doesn't update the total for that item when I increment and decrement the quantity. Here is the console output:

No quantity for item. simpleCart.js:1048
No price for item or price not properly formatted. simpleCart.js:1048

When I don't use the onclick parameter simplecart adds the item with the NaN value only.

Cookie size too large

Need to create more cookies to handle more information when the cart has several items and the data is too large for one cookie

Using Norwegian kroners doesn't change the symbol

Norway doesn't use currency symbol, but it can be shortened these ways, ie. 250 Norwegian kroners:

250 NOK
250 kr
250,-

But using simpleCart.currency = NOK I only get the dollar sign.

Also, how can I translate the labels for the simpleCart_items div?

Only display one cart at one page

I encouter a problem when i try to place multiple < div class="simpleCart_items" > < /div > in a page, it always displays items on the last div. The other divs will show nothing except the last div. When I look at the script, I found out that cartDivs uses appendChild method to add item rows. Look like only last cartDiv will be able to display items. Thus, I come up with a quick fix with codes below:

me.updateView = function() {
me.updateViewTotals();
if( me.cartDivs && me.cartDivs.length > 0 ){
for(current in me.cartDivs) {
me.updateCartView(me.cartDivs[current]);
}
}
};

This will ensure every

in a page will be able to show items. But Im not sure whether this is a good way to fix it, maybe you can do it in a better way, like deep cloning object? Just my 2 cents.

Cheers

Language of Paypal page

I have set up payment pages in the past using Paypal generated code and I've found that it's possible to control which language page in Paypal the user is sent to, but I can't see a way to do that using Simplecart. Can it be done?
I too tried the same code editing that 'romulopimentel' asked about this some weeks ago but had no joy. Nobody's had a response for about 3 months so I guess nobody's home.

Email not sending all up total

Great script . Not a big coder so still trying to get my head around it. I grabbed the email version from http://github.com/thewojogroup/simplecart-js/tree/email and set up my email etc . When I receive my test order there are totals for the items but not a final total of all items . How would i go about just getting :- Item | amount | total For all the items then just a FINAL TOTAL ( all up )
sent to my email?
I am trying to use this for a restaurant who just want to take online orders with no payment
(They either pay on pick up or delivery)
I really like the way this works as every other one I find makes you leave the page .
I like how this is all stays in one place but unless I can work out a few things i'm going to have to keep looking .
Has anyone mastered this as there still is no instructions in the wiki under the Email section .
And another thing ...How would i go about styling the email as at the moment it comes through as one downward line . Do I add the css inline in the email.php?? So confused
This is what i see :-
Thumb
Name
Size
Price
decrement
Quantity
increment
remove
Total

Zebra

$187.95

2
+
Remove
$375.90

Cow

$18.00

2
+
Remove
$36.00


So alls I need is someone to point me in the right direction on receiving the Final total as well ( And possibly telling me how to get rid of the -+ and remove) and just some tips on styling the Email . ( Unless someone out their has written a verbose Manual for dummies lol - ie : i'd take it )
Cheers
Kevin Messer

No quantity in shelf gives an obtrusive alert

It gives you an alert saying No Quantity, but it also assumes the quantity added is 1. Is the alert necessary, what if i don't want quantity and i just want an add to cart button?

Paypal Error: Shopping Cart is Empty

Paypal keep giving me an error that my shopping cart is empty. Here's the URL with all of the Query String parameters that generated this error:

https://www.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1&[email protected]&currency_code=USD&item_name_1=The%20Message%20Remix:%20The%20Bible%20In%20contemporary%20Language%20-%20ISBN:%201600060021%20#2&item_number_1=1&quantity_1=1&amount_1=$8.67&on0_1=Options&os0_1=thumb=http://ecx.images-amazon.com/images/I/51e4j6n9tmL._SL160_.jpg

Any ideas on why this might be happening?

I should note that I'm using SimpleCart 2.0.1

Cart Input field onchange function bug

Line 443:

outputValue = this.valueToTextInput( outputValue , "onchange=\"simpleCart.items[\'" + item.id + "\'].set(\'" + outputValue + "\' , this.value);\""  );

I believe this should be:

outputValue = this.valueToTextInput( outputValue , "onchange=\"simpleCart.items[\'" + item.id + "\'].set(\'" + info[0].toLowerCase() + "\' , this.value);\""  );

With the way it currently is, the cart item's set function is being passed the old value of the input field instead of the property name it needs to change the value of.

parseFloat & parseInt problem

Another little bug.
If the price tag is $ 0.00 parseFloat return NaN instead of zero.
I suggest to check every parseInt and parseFloat if they return NaN, and convert to zero.

Regards

Custom item to return [object HMTL Element]

I've had to edit line 193:

[code]
if( typeof(item[field]) != "function" && field != "id" && field != "price" && field != "quantity" && field != "name" && field != 'custom' /&& field != "shipping"/) {
optionsString = optionsString + "&" + field + "=" + item[field] ;
}

[/code]

..to suppress this.

Custom fields are not allowed on a per item basis, is only part of the transaction.

Change checkout language

Since there is no option for it on the documentation, I've tried to edit the code.
I've e-mailed PayPal about this issue, and they sent me the answer that I shoud add the following variables on my button:
or LC=BR
Then, I found this funcion on the code:

var me = this,
winpar = "scrollbars,location,resizable,status",
strn = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart" +
"&upload=1" +
"&business=" + me.email +
"&currency_code=" + me.currency,
counter = 1,
itemsString = "";

I thought on putting something like this on the code, but it didn't work:

"&LC=BR" +

Any ideas about this? It's really important, so any help is welcome.
Thank you very very much!

Bugfix on shelf css

Hi everybody.
I found a bug on the css parsing code.
If, for instance, the "Add to cart" link on the shelf has another class with an underscore, it doesn't work correctly.

This won't work

I suggest replacing line 808 with this:

var data = /item_([^ ]+)/.exec(node.className);

Regards

stock levels?

I really do enjoy this shopping cart system which I've integrated into my site. I know that this script lacks separate shipping costs and tax rates. I added this into the script myself and it is working fine, although it would be lovely if a better version of this was integrated.

My other problem which I thiink would be extremely beneficial which I'm trying to personally integrate -- but will be irritating to do so... -- is to add some sort of jquery code to call my mysql database and get stock levels. I think it would be amazing if you guys maybe did a flat file version of this? It would be quite painstaking to continuously keep up with what's sold and what's not, and the stock levels of each product, even with just 10 or so products.

Suggestion for an easy peasy code that i can start to integrate myself into this?

Google checkout only sending one item

When using Google Checkout I have added 4 items to the cart and click check out it only displays 1 on the google page (and only 1 items cost).

When i try this again using my paypal it displays all 4 items plus the flat rate shipping.

For...in statement issue

I'm running on several javascript error on every loops that use that statement.
As suggested by JSLint this statement:
for( header in me.cartHeaders ){
Problem at line 431 character 9: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.

as an example.
Seems that, in my environement, there is an additional "$family" property in the array that breaks the javascript execution.
I resolved by changing all for..in loops in simple for loops, like:
for(var x=0, xlen=me.cartHeaders.length;x<xlen;x++){}

hope this help.

flickering and few other issues

this script provides absolutely the easiest way to fill my exact needs on the outside, but getting this thing run properly has brought my attention to a few issues I can't seem to fix myself neither found some information on them:

when I load the script the first loading causes flickering ie the html elements with classes "simpleCart_quantity" and "simpleCart_total" will take 2-3 seconds to load the inline content. the demo within the download package works fine nonetheless.

another issue that I can't figure out is that when I swich from default currency (USD) to my native one, I still get the dollar sign iń front of the total amount which needs to be absent leaving only the numeral data to be output.

thanks in advance, psssh

data capture

I know everyone likes this simple cart because of its simplicity of not needing a database to run off.

I use simple cart with a database bringing up the products and it work amazingly. My questing is that I need to capture the data of an order that has gone through the process of paypal/google checkout.

Usually I would have the database that creates a table of information that has been collected before it goes to paypal/google checkout but once the order has been finished I would have a file that changes the information from not processed to processed.

Hope that makes sense.

Rounding errors

price of 9.99 gets rounded down to 9.00 when added to the cart.

Email Checkout

Would be great to be able to post the form to email rather than Google/Paypal

Items stay in cart after checkout?

The minimalist documentation for Simplecart says nothing about what happens to contents of the cart after you traipse off to PayPal to pay for the stuff. There doesn't seem to be any callback mechanism, so is that what really is supposed to happen? Stuff just sits there with no feedback?

I can't even find a clear-the-cart setting for when checking out....

Any suggestions?

18% instead of 17.5%

I've set the tax rate to 17.5% however the class simpleCart_taxRate displays 18% instead although when the class simpleCart_taxCost calculates the total tax it does it correctly. What can I do to display the 17. 5% tax rate?

Decrement Case Sensitivity

Using Decrement instead of decrement in the cart headers will give you

function () { if (parseInt(this.quanity) < 2) { this.remove(); } else { this.quantity = parseInt(this.quantity) - 1; simpleCart.update(); } }

instead of the decrement link

IE limit on querystring with paypal checkout

I see that when you press "checkout" button the cart is converted in a querystring and it open a new window with a long url.
If a user buy a lot of items this url can be extremely long. Does this can be a problem for IE?
As far as I know there is a limit on the query string on IE, about 2Kb or 4000 chars. No?

Email option issue

Hi Guys,
First of all, great script. I will be using it in my site for online Sushi orders.
Since I need to check my orders on email and clients pay when they pick their order up at the restaurant.
Is there a way I can put 2 more options on the email.php file, like YOUR NAME and YOUR PHONE, so I can phone clients back confirming the order?

Thanks

TOZE

Items in cart displayed horizontally?

At the moment when users add items to the cart, the cart contents is built up as a vertical list, with all of the headers in a vertical list at the top, and the elements of each item underneath that - as in:

Name
Price
Quantity
Total
Red t-shirt
$6.00
2
$12.00
Blue t-shirt
$8.00
2
$16.00

What I need is to have the headers running horizontally (in a table ideally) like this:

Name Price Quantity Total
Red t-shirt $6.00 2 $12.00
Blue t-shirt $8.00 2 $16.00

Can anyone help me - please?

Simplecartjs - Paypal Problem

Hi - If I run the demo from the http://simplecartjs.com website when I use the 'Checkout' button the PayPal screen loads but option details do not display properly in internet explorer. It just looks like text - ie no images or descriptions show correctly.
EG
Options:image=http://demo.simplecartjs.com/images/attack-release.png displays not the image. Is there a bug or do I need to do something? The same occurs running the cart from my own PC.
Thank you in advance

Regards Graham

Only first option recognized?

Hello and thanks for the shopping cart.

I have set up the cart and it's working fine but I have an issue regarding multiple options.
When I set up multiple item_Something (I use one select and 3 checkbox for a total of 4 different item_something) only the first one is passed to paypal, all the others are ignored. Is there a way to make them appear?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.