C# Shopping Cart Articles
The last segment of my C# Shopping Cart series has just been published over at ASPFree, here are all three:
- Creating an Online Shopping Cart and PayPal System
- Data Handling with a Shopping Cart/PayPal System
- Formatting an Online Shopping Cart/PayPal System
For now I’m working on other ideas but I might add some more to the series later on. I’ve developed several online shopping systems so I’m just using things I’ve been through in the past. Some things I probably wouldn’t actually do in any of the systems now such as storing the shop in a session like the articles do. That was just an easy way to hold the data for the example shop. Another article could be how to setup and use a database for your shop which is definitely something I would do personally.
An other article could cover things such as handling the payments yourself. I steered away from that for now as it leads into what I dub “The iffy grey area”. The easiest way to handle the payments yourself, such as if you have a POS system at your end that you manually tap details into is to simply store the customers credit card details in your database and then when you sit down to process the orders you read that info and manually type it in. The iffy part is where you store the credit card details. In some places this is against the law and since I cant find a list of those places to put in the article I just skipped it all. The best solution would be to have the orders placed instantly by linking your system directly to the POS. Then you could take the details, verify them and then pass them to the POS straight away. Then there would be no need to store the details. If you went down this route even though it was perfectly legal to store the details in your country/region then you can always store them anyway for customer ease of use i.e. letting them store cards so they can easily use them for future orders “Please pick a card you’ve used in the past for this new order”. You see this feature in most of the big shops like amazon.
The other great method is to just let paypal or worldpay deal with it all. I just sent the user straight over to paypal and let that handle everything but this isn’t the only option. You can head over to paypal and look up the other options yourself, there’s no point in me regurgitating what they say, well at least not until I cover it in an article 😛
Comments: 7
Hi David – Thanks for the cart article. I’ve applied the code to my brithers web app and ts works well. There isone issue that I hope you can explain to me…
When the cart is posted to paypal, it use the “HttpWebRequest” class. The form is submitted and the response is rendered back into my page…
Trouble is, my page is not https so the user is presented a paypal page and asked to complete credit card details on an insecure form.
2 questions :-
1. I know form is from paypal, so is it actually encrypted and this is just not visible because the url has not changed?
2. How could I get the shopBasketCheckout_OnServerClick method to submit the basket directly to paypal (i.e URL change when clicking “PAY”)?
Hi, this is the drawback of using the HttpWebRequest method. It’s a quite common issue that alot of people have brought up. One way to get around it is to use the Paypal SDK for .net:
https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/software_dev_kit_asp_net-outside
When I first conceived the article which was before submitting the idea to Dev Articles this SDK didn’t exist. If it did then I probably would of used that instead of the method that I did. It’s one of those “If I could go back in time and change something …” things 🙂
Hi David,
thanks for the great articles. I’m curious if anyone’s noticed this glitch(posted this in the ASPfree comments as well).
When there are for example three items in the cart, and if the user for example puts a two in the third field and hits enter on the keyboard (windows XP), the cart adds an item to the first item in the cart. I don’t really think it matters what number is placed in the field, hitting enter adds one to the item at the top of the table. Any ideas about this one, or what to change to fix this.
This is going to be a great chance to play around with some dotNET 2.0 code and use Microsoft’s new web editor Expression Web.
Ty
Hi, I hadn’t noticed that behaviour until you pointed it out. It’s due to the first button on the page being treated as the default button that gets pressed when enter is pressed. It’s a quite common issue that you normally hear people with two or more forms on a page discussing.
I wrote a simple fix for it that you can expand upon. It’s included in this zip:
http://www.davidmillington.net/trials/devshed-articles/3-gridview-shop/enter_key_fix.zip
The zip just contains a new .cs file. I marked all the changed areas with a comment like this:
21.02.2007 – Fix for defaulting enter key
but I’ll cover the changes here as well. The first change is in the shopBuy_OnServerClick function. I made it check a new boolean function to see if it should proceed with adding a new item. The next change was that I moved all the contents of the shopUpdateBasketQuantities_OnServerClick function into the new boolean function and then just made it make a call to that. The final change was making the new boolean returning function. The guts of that came from the shopUpdateBasketQuantities_OnServerClick function. I added a new boolean “updated” at the top and then an extra if statement in the loop to check if the quantities had been changed for any item. If they have the function returns true else false.
The idea here is that we know it’s going to see the AddToBasket button first as it’s the first button on the page so instead of actually adding an item to the basket we make it check the textfields in the gridview to see if any of the quanitities have changed. If they have then we just update the basket, if they haven’t then we add the item to the basket.
What you’ll see with the updated code is that if the quanities in the basket haven’t changed then it will work as it did before i.e. it will add the top most item in the products list to the basket again. If the quantities have changed then it will just update the basket. This is what I meant when I said you can change it to suit youre needs.
Thanks for having another look at it then David.
Super timely too! I wish I had programming skills to make alterations and the like. I’ll be lucky to figure out the application, enough to change the look of it.
If you have developed this cart commercially for any clients, maybe you could share the link, so we could see some of your handy work of what is possible?
If you don’t wish to post a link for them shoot me a line, my email was in the comment form. I’ve been looking for a cart solution for a designer like me, stuck at a place that doesn’t run PHP on it’s servers, and is less clunky than the straight payPal service.
Once there are some tutorials for using Expression Web, I might find something to run with, such as your solution here.
thanks once again.
I did make a few shops using a similar system along time ago at a company I was working at. Later on we developed an absolute behemoth of a shopping system that we replaced all the sites with. The only two sites I can think of off the top of my head that didn’t use that system had their own payment option instead of paypal i.e. you entered you’re card details on their site and they themselves received them.
I developed all the systems to be very customisable so that the designers could easily alter the look n feel either by just replacing image files or by using a bespoke GUI to make tweaks.
I found out quite early in my career that I’m not very good at graphical design. I’d just spend waaaay to long fidgeting around with the look of things. After I’d worked with a few proper designers I saw how quickly they could churn out stunning graphics and how I was definately not on the same level with them. On the brightside none of them could code for shit so I wasn’t redundant 🙂
You should check out other full solution shops, there’s quite a few opensource solutions out there. Just google “opensource shop” to find a few.
Well you did a nice job on this page layout.
I’ll google on “opensource shop” I’m not to sure how many dotNet solutions it will find though. Most likely a slew of PHP derivatives, thanks again friend.