OM2 Posted August 11, 2008 Share Posted August 11, 2008 I've been thinking, what's all the fuss about shopping cart code? Maybe I'm missing something but it seems to be very easy and we don't need and code connecting pages. Shopping cart code: - add session code to keep track of what's in the basket - on any page where you want to have a product, add code that simply adds the item on the page to the basket - add code to show the basket page - add code to transfer all of the details to a payment gateway All of the above seems very simple to me! Something that could be handled by any CMS: just have something to add a buy it now button with code behind it to add an item to the basket whenever you want to add something. What am I missing? It seems very very simple to me! As far as I can see, maybe I'm missing the need to have tax calculations or something, but everything else is straight forward? Or maybe the need to specify sizes, coloours or something else - but surely it can't be that hard to add this with a a little javascript? Another thing: how hard can it be to have a shopping cart that is SEO friendly? With the above approach, surely it must be easy? I haven't found any credible opensoruce HTML shopping cart software. (There was one that looks promising that is well known, that I can't remember the name of, but that has problems with working in the UK!) It seems so simple that I'm contemplating coding a shopping cart myself! (Erm... I'm a newbie to PHP!) Any feedback to the above would be great! Thanks. OM Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/ Share on other sites More sharing options...
toivo Posted August 11, 2008 Share Posted August 11, 2008 The shopping cart application in a CMS can be 100 000 lines of code. I would not re-invent a wheel, but it is up to you :-) Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613403 Share on other sites More sharing options...
leony Posted August 11, 2008 Share Posted August 11, 2008 I store all cart info in the database, as it seems a better option for my application. The difficultness depends on how experience you are. If you are not, believe me you will have to spend some time for the bugs, failures so forth. If you have a website which is straighforward, the cart applciation should not be that difficult. Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613407 Share on other sites More sharing options...
OM2 Posted August 11, 2008 Author Share Posted August 11, 2008 guys thanks for the replies. i still don't see what i'm missing here! (i dont want to waste my time either chasing a fruitless task!) here's my spec: add item to shopping basket code: function add2basket($itemName, $value) { $_SESSION['shoppingBasket'][$itemName] = £value; } display shopping basket: function displayBasket() { // write code to display the $_SESSION['shoppingBasket'] array } add customer details: just write a form to collect the customer data. shipping: can't be that hard to add? pass details onto payment gateway: easy to do as well? and erm, not much else. what got me thinking about all of this: the paypal shopping basket. it's soooo simple! then i thought, hold on, it can't be that hard to code something similar? Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613416 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Yeah, good luck writing a concise shopping cart that's extensible and won't just break when someone does something unexpected. Also, good luck writing it procedurally. Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613440 Share on other sites More sharing options...
OM2 Posted August 11, 2008 Author Share Posted August 11, 2008 Yeah, good luck writing a concise shopping cart that's extensible and won't just break when someone does something unexpected. Also, good luck writing it procedurally. hey, how about being construtive and telling me what i'm missing. if the above is a bad idea, then paypal shopping cart is equally bad? Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613465 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Never looked at it, but probably. xD First of all, coding a shopping cart in a procedural-type fashion will cause tons of headaches and repeated code. You'd really be best off coding it using OOP. But good OOP, not "this is a replacement for some function and actually does nothing useful" kind of OOP. And you need to make it easily (easily being the keyword) extensible so you don't need to rip apart perfectly functional code to make it work how you want. The way that you're describing in the first post would surely work, but it's rather amateur and will be hard to manage. Sure, you could make "a shopping cart" in like that, but you can't make "the shopping cart". Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613473 Share on other sites More sharing options...
Fadion Posted August 11, 2008 Share Posted August 11, 2008 The shopping cart application in a CMS can be 100 000 lines of code. I would not re-invent a wheel, but it is up to you :-) That should be tons of code. The guy here is not talking about a modular, templatable (is that a word?), unbreakable and where OO is unreachable system. He's talking about a simple shopping cart where u can add products by filling some fields and let the user buy them. I recently finished a simple shopping cart (togather with a not so simple cms) for a client. It involved an admin panel where he can add/edit/delete products, each product has title, price, photos, etc, and is categorized in categories and styles (like lodge, baroque, whatever). In the front end i put up some nice features like ajax cart update and sorting from categories, styles, prices, etc. That is a quite simple system, but which does the job greatly. Appart from testing bugs and security, i didnt take me more then a couple of days to build it. So what are u guys talking about? We aren't discussing about builing a drupal clone, but a rather simple shopping cart which does what its meant to do. Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613477 Share on other sites More sharing options...
OM2 Posted August 11, 2008 Author Share Posted August 11, 2008 The shopping cart application in a CMS can be 100 000 lines of code. I would not re-invent a wheel, but it is up to you :-) That should be tons of code. The guy here is not talking about a modular, templatable (is that a word?), unbreakable and where OO is unreachable system. He's talking about a simple shopping cart where u can add products by filling some fields and let the user buy them. I recently finished a simple shopping cart (togather with a not so simple cms) for a client. It involved an admin panel where he can add/edit/delete products, each product has title, price, photos, etc, and is categorized in categories and styles (like lodge, baroque, whatever). In the front end i put up some nice features like ajax cart update and sorting from categories, styles, prices, etc. That is a quite simple system, but which does the job greatly. Appart from testing bugs and security, i didnt take me more then a couple of days to build it. So what are u guys talking about? We aren't discussing about builing a drupal clone, but a rather simple shopping cart which does what its meant to do. hey: at last someone on the same wavelenght as me! look at the paypal shopping cart: amazingly simple. ok: not as sophisticated as most other shopping cart software: but does the job. i'm still sticking to my guns: i can't see what all the fuss is about shopping carts! as far as oo: yes, sure, spend a little more time and make the code robust. but my point still stands. Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613483 Share on other sites More sharing options...
Fadion Posted August 11, 2008 Share Posted August 11, 2008 Never looked at it, but probably. xD First of all, coding a shopping cart in a procedural-type fashion will cause tons of headaches and repeated code. You'd really be best off coding it using OOP. But good OOP, not "this is a replacement for some function and actually does nothing useful" kind of OOP. And you need to make it easily (easily being the keyword) extensible so you don't need to rip apart perfectly functional code to make it work how you want. The way that you're describing in the first post would surely work, but it's rather amateur and will be hard to manage. Sure, you could make "a shopping cart" in like that, but you can't make "the shopping cart". DarkWater, with all the respect, do u usually take time to design your applications? Do u analyze who will use it and optimize it for that general audience? Do u implement any Design Patterns? Do u really write "good" OO code? Those are questions to which you and me cant think of replying. That would need lots of experience as a coder (but not alone). So while we're not at that level, lets stick to the less complicated Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613484 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Never looked at it, but probably. xD First of all, coding a shopping cart in a procedural-type fashion will cause tons of headaches and repeated code. You'd really be best off coding it using OOP. But good OOP, not "this is a replacement for some function and actually does nothing useful" kind of OOP. And you need to make it easily (easily being the keyword) extensible so you don't need to rip apart perfectly functional code to make it work how you want. The way that you're describing in the first post would surely work, but it's rather amateur and will be hard to manage. Sure, you could make "a shopping cart" in like that, but you can't make "the shopping cart". DarkWater, with all the respect, do u usually take time to design your applications? Do u analyze who will use it and optimize it for that general audience? Do u implement any Design Patterns? Do u really write "good" OO code? Those are questions to which you and me cant think of replying. That would need lots of experience as a coder (but not alone). So while we're not at that level, lets stick to the less complicated Honestly, although I doubt you'll want to hear it, I do code like that when I'm writing big, serious applications. I also code Java so I kind of HAD to learn how to work with design patterns and "good OO code". =P I do analyze it, write out UML, and plan intensively for big projects. Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613486 Share on other sites More sharing options...
PFMaBiSmAd Posted August 11, 2008 Share Posted August 11, 2008 Your example code is missing error checking (validate data and check if a function worked or not), error reporting (display a meaningful user message when data is not valid or a something does not work), error logging (log all possible information about an error), and error recovery (what does your program do when there is invalid data or an error.) Writing a real life, bullet proof, secure application requires at least 5 to 10 times the amount of logic (and effort) than what you see posted in answers in a forum like this (which is just the minimum logic necessary to address the question that was asked.) Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613488 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Your example code is missing error checking (validate data and check if a function worked or not), error reporting (display a meaningful user message when data is not valid or a something does not work), error logging (log all possible information about an error), and error recovery (what does your program do when there is invalid data or an error.) Writing a real life, bullet proof, secure application requires at least 5 to 10 times the amount of logic (and effort) than what you see posted in answers in a forum like this (which is just the minimum logic necessary to address the question that was asked.) Exactly. You can write a basic shopping cart with the lines of logic you provided, but it would probably be broken by someone and it wouldn't be too great if you needed to add something. Just my $0.02. Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613489 Share on other sites More sharing options...
Fadion Posted August 11, 2008 Share Posted August 11, 2008 Honestly, although I doubt you'll want to hear it, I do code like that when I'm writing big, serious applications. I also code Java so I kind of HAD to learn how to work with design patterns and "good OO code". =P I do analyze it, write out UML, and plan intensively for big projects. That was the point: "serious applications". I usually work on a team for big and serious applications, so myself have to take care of the design (not photoshop related ). But thats as far as the project needs it, while for simple projects i trim the design proccesses a lot. On the other side, asking a guy who has been writing php for less then 4 months to write a procedural, object oriented application is a bit overwhelming. Thats my opinion though. Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613493 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Honestly, although I doubt you'll want to hear it, I do code like that when I'm writing big, serious applications. I also code Java so I kind of HAD to learn how to work with design patterns and "good OO code". =P I do analyze it, write out UML, and plan intensively for big projects. That was the point: "serious applications". I usually work on a team for big and serious applications, so myself have to take care of the design (not photoshop related ). But thats as far as the project needs it, while for simple projects i trim the design proccesses a lot. On the other side, asking a guy who has been writing php for less then 4 months to write a procedural, object oriented application is a bit overwhelming. Thats my opinion though. Well, if he wants to have a secure shopping cart that'll be good, he has to learn eventually. >_> Sure, he can piece something together, but whatever. P.S: "procedural, object oriented application" is an oxymoron. xD (I've always wanted to use that word on a forum) Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613505 Share on other sites More sharing options...
Fadion Posted August 11, 2008 Share Posted August 11, 2008 P.S: "procedural, object oriented application" is an oxymoron. xD (I've always wanted to use that word on a forum) F*.. hell, i didnt mean procedural. I wanted to mention modular. Anyway, if i didnt make the mistake, you wouldnt have the chance of writting "oxymoron". lol what a word! Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613514 Share on other sites More sharing options...
DarkWater Posted August 11, 2008 Share Posted August 11, 2008 Ha, what a fun word. Quote Link to comment https://forums.phpfreaks.com/topic/119129-shopping-cart-not-so-hard-to-code/#findComment-613516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.