On Thu, April 20, 2006 7:14 pm, Steve wrote: > I'm creating my own Object Oriented PHP Shopping Cart. Okaaaaaaay. You're doing this just for fun and education, right? Cuz, seriously, it's about 100 X harder than you think to get a bunch of details you've never even thought about correct. And there are about 100 shopping carts already out there. > I'm confused about the best way to call the functions of the class > given > the "static" nature of the web. I think you mean "stateless"...? > For example, if I have a function addItem($code), how will this be > called from the catalog or product description pages where the BUY > buttons are? > > On the product description page (say for product ABC213), there will > be > a BUY button, but when the button is clicked, obviously I cannot > immediately call $cart->addItem('ABC213'). So how is this done? The BUY button should have HTML elements which will pass in 'ABC213' via POST or GET data. Your script, at a minimum, would then do: <?php session_start(); //this is how you make HTTP sort of stateful. $item = $_REQUEST['item']; //assuming your HTML BUY button has name="item" require 'Cart.php'; //Load in the OO class you are writing. $cart = new Cart(); //Make an instance of your Cart. $cart->addItem($item); ?> So, actually, if you get all the OTHER details right, there isn't much more to it than what you typed... > I thought of making the BUY button link to the cart itself, like so, > but > doesn't this mitigate the whole point of designing with classes: > > <a href="Cart.php?action=add&code=ABC123&goto=viewcart">BUY</a> > The Cart.php would then redirect the user to view the contents of the > shopping cart. There is no reason why you need to go directly to Cart.php -- Just require the Cart.php script into the product/catalog pages. Do that at the tip-top, and you can include all kinds of nifty info on the product/catalog pages like: "You have 10 items in your cart totaling $192.37" > Do you have any tips, or are there any resources that may help me > think > more clearly about this? You should read the source to several other shopping carts. Yes, there is a TON of source code, and Yes, most of it is very very very badly-written, and Yes, that's because they started typing just like you are now instead of actually figuring all this [bleep] out in advance. :-) > My aim is to build a Cart that is very flexible that I can use in many > situations in the future. I'm pretty sure that was everybody's aim for every shopping cart ever built. Nobody wants to build the damn thing a second time. :-) -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php