Click to See Complete Forum and Search --> : Yet another shopping cart


Shrike
12-12-2004, 10:44 AM
I have been asked to look at creating an online shop for a friend. So rather than go and download a freebie shop, I decided to write my own. Why? Because I've never tried before, and I like writing my own stuff. In reality I will probably use a commercial shop, but writing it was fun :)

It's only the front-end of a shop. For real use it would need an admin area and some prettying up, with Item graphics added and so forth. It is, hopefully, elegant OO code using some pattern-based ideas. It has an MVC-like structure and uses a few other standard patterns. Hopefully some help to someone before it goes into the dusty old projects cupboard.

Code is running here (http://shrike.dotgeek.org/cart/) and ZIP file is attached.

Shrike
12-13-2004, 10:12 AM
Just noticed that the SQl query class has a PHP 5 constructor, it should be renamed to the class name for PHP 4 :)

Shrike
12-17-2004, 06:23 AM
Cart version 2 (http://shrike.dotgeek.org?view=cart)

Encapsulated the display for ease of use
Made better use of Iterator for display
Added a display builder class for use with Iterator and Renderer
Integrated as a module to my MVC framework :)

Shrike
02-14-2005, 07:49 PM
A bump to the top since theres been 25 downloads. Still no comments though :evilgrin:

bubblenut
02-22-2005, 01:48 PM
The only thing I can notice is that a do loop on the iterator and adding a return in front of your call to next in the method would reduce the number of calls to current() and valid() by n-1.

if($iterator->valid()) {
$item =& $iterator->current();
do {
//stuff
} while($item =& $iterator->next());
}

I don't really like do while loops though.

One other thing (you can tell I'm scrapping the barrell on things to pick up on but I've got to find something), in terms of looking through mysql's show full processlist output and query logs it's much easier to look at queries that were input on one line. For that reason I tend to do query string like this

$item = $this->sql->sqlGetSet(
"SELECT i.ID, i.ITEM_NAME, ".
"i.ITEM_DESC, i.ITEM_PRICE ".
"FROM items AS i ".
"WHERE i.ID = '".$id."'"
);


but to be honest these are pinickety points.

Oh, one other thing, what made you go off PHP5? :confused:

Shrike
02-22-2005, 02:00 PM
Hooray comments! :)

I've never used do/while, just one of those things. Nice tip on the SQL front too.

As for PHP 4 - there was a possibility that it would get used and the liklihood is that any host would not support 5. It would however benefit a bit from destructors and the SPL Iterator (theres some comments to that effect I think :))