Shopping cart for Core Computers, Western Digital external HDD skins promotion Programming by Barney Desmond Started: 2008-11-20 Finished: 2008-11-30 Description ----------- Existing static site content required ability to present and process an order form for customers wishing to purchase products. Requirements ------------ * PHP5, PHP4 may work * MySQL database * PHP-PEAR MDB2 extension Notes ----- * Considered to be a temporary solution. Can be extended, but messy Files ----- * db.inc.php Defines connection parameters and creates the initial connection to DB * buynow.php Primary cart-management page, products are added from here * cart_action.php Updates the cart data (stored in the PHP session) * abandon_cart.php Linked from buynow.php, customer can visit this page to clear their cart by wiping their PHP session * mootools-1.2.1-core-jm.js Provides useful cross-browser javascript methods, used to manipulate the browser DOM for aesthetic reasons. * util.php Provides many useful convenience functions and constants * debug.php Provides a global debug flag that can be toggled in one place. Also provides a convenience function, debug(), for easy inspection of variables * show_orders.php Trivial read-only script that presents database information of all orders * checkout.php buynow.php submits to checkout.php, which does the backend work of inserting into the database and sending emails to merchant and customer * thankyou.php Customer is bounced here after checkout.php and shown a thank-you message, along with payment instructions * README This awesome file * old/ Files created and used during development to try out different tools and UI Database -------- One table, used for storing customers' orders mysql> DESCRIBE orders; +----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+-------+ | transaction_id | varchar(6) | NO | PRI | NULL | | | name | varchar(100) | YES | | NULL | | | company | varchar(100) | YES | | NULL | | | email | varchar(200) | YES | | NULL | | | ip | varchar(15) | YES | | NULL | | | timestamp | varchar(32) | YES | | NULL | | | message | text | YES | | NULL | | +----------------+--------------+------+-----+---------+-------+ 7 rows in set (0.00 sec) mysql> SHOW CREATE TABLE orders; Create Table: CREATE TABLE `orders` ( `transaction_id` varchar(6) NOT NULL, `name` varchar(100) default NULL, `company` varchar(100) default NULL, `email` varchar(200) default NULL, `ip` varchar(15) default NULL, `timestamp` varchar(32) default NULL, `message` text, PRIMARY KEY (`transaction_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; General assumptions/limitations ------------------------------- * Customer may wish to purchase >1 product at a time * Must take order, present total-payable to customer, send email to customer and merchant advising details of order * Site does not need to accept payments, customer to pay via EFT themselves * No need for customer to register or create an account on the site Customer flow ------------- * Customer enters site via external linkage/recommendation * Customer browses pages, checking out product offerings * Customer goes to "buy now" page * Customer chooses specifics of desired product from drop-down menus and adds an item to their (initially empty) cart * Customer may continue adding items to cart * When satisfied, customer enters personal details into HTML form * Form is submitted * An Order ID is generated so the customer can track and identify their purchase with the merchant * Email is sent to merchant to tell them about the new order * Email is sent to customer confirming receipt of their order, and providing payment instructions. * Details of order are inserted into database * Customer transfers money to specified account via EFT * Merchant confirms receipt of payment and sends order to customer Page flow --------- * Customer enters static site content * Customer visits buynow.php, a new PHP session is initialised * An item is added by submitting the form to cart_action.php * cart_action.php adjusts the order details stored in the session, then bounces the customer to buynow.php (prevents double-submit problem) * buynow.php shows the contents of the cart, also ready to add another item * When ready, customer fills in personal details and submits to checkout.php * checkout.php adds details to session, performs the backend work, then bounces to thankyou.php (prevents double-submit problem) * thankyou.php shows details of the order and elaborate payment instructions How to add another field (payment details) ------------------------------------------ = buynow.php = * add to html in buynow.php, pick a unique field name, id="customer_foo", name="foo", tweak PHP shard * add a session_get near the top of buynow.php: $customer_foo = session_get('foo'); * add a fixture below that, in case it's not set: if ($customer_comments === False) { $customer_comments = ''; } * if it's mandatory, add a check to validateCustomerDetails() = checkout.php = * add a request_get near the top of checkout.php: $foo = request_get('foo'); * add a fixture below that, in case it's not set: if ($foo === False) { $foo = ''; } * add a pre-fill by putting the data into the session: $_SESSION['foo'] = $foo; * add a field to the DB insertion if it's important enough to have its own field (otherwise it can be seen in the message body): * update the prepared statement by adding another placeholder * fix up the `orders` table to take the new field: ALTER TABLE orders ADD COLUMN foo SOMETYPE AFTER bar; * update the commented section that describes the table * add $foo to the insertion_data array for the DB, either as a new field, or tacked on to the $text_table string * add a field to the debug section "you gave me the details": Foo: * add the field to the admin email: Foo: ${foo} * add the field to the customer email, if appropriate: Your foo: ${foo} = thankyou.php = * add a session_get() call * add a fixup below that * fix admin email? * fix customer email? = show_orders.php = * update the comment showing `DESCRIBE orders` if you modified the database earlier Dumping the database -------------------- mysqldump --complete-insert --no-create-db --quick furinkan_core > core2.sql Updating prices --------------- These are all hard-coded in util.php, and buynow.php for drop-down presentation. Be very careful when editing them, though it's really self- explanatory.