PHP - Modeling The Checkout Process
I could use some suggestion on how to model the Checkout Process for my e-commerce site.
As I see it, when a person "checks out" there are 5 steps... 1.) Create an Account/Log-In 2.) Enter Addresses 3.) Choose Shipping Options 4.) Enter Payment Details 5.) Review & Place Order I'm trying to avoid having gigantic "God classes" and struggling to figure out how to abstract things in good OOP terms. My Head First: Design Patterns book talked about the "State Pattern" and I'm wondering if that might be a good approach? Maybe each of the 5 steps above could be a "state" in the Checkout Process? What do you think? TomTees Similar TutorialsThis is part PHP, part MySQL question, but since I'm more interested in the process-flow, I'll ask here. I am ready to start coding the e-commerce module of my website, which features mostly paid subscriptions.
Do the below steps sound like the correct sequence to do things in...
- Anonymous shopper adds subscription to Shopping Cart - Shopper goes to check out - Shopper completes checkout form which includes setting up the account and entering payment details Now for the important stuff... - System takes Shopping Cart details - which include the PHPSessionID - System creates Member record - System takes Shopping Cart details associated with PHPSessionID and links them to the new Member record - System creates Order and Order Details records - System runs the payment - System hopefully gets back a "success" message from Payment Processor - System activates the Member's account
How does that sound at a high-level?
Really what I'm trying to validate is if I should create the Member record 1st, then create the Order records 2nd, and worry about the payment last. (Originally I was going to run the payment first, but I'm thinking it's better to capture the anonymous shopper's details in a Member record and Order records first, because even if the paymnt fails, you want something to work off of - like reaching out to the person and getting another valid payment.)
Thoughts?
Hi, I was wondering if someone can help. I am trying to implement a server to server Google checkout system on my website. I have built my own custom shopping basket which meets my needs however I need to get my data in the correct format to send off for the payment to be taken by Google checkout. At present I have a sql table called basket which stores all of the items that a user adds to thier basket. The google checkout examle requires the data in the below format: Code: [Select] $item_1 = new GoogleItem("product name ", // Item name "With S/N", // Item description $total_count, // Quantity 10.99); // Unit price $item_1->SetURLDigitalContent('http://example.com/download.php?id=15', 'S/N: 123.123123-3213', "Download Item1"); $cart->AddItem($item_1); The above code is obviously for just the one item. Is it best to store the basket in a sql database and if so how would I go about retrieving the information from the database and then sending it to google in the above format bearing in mind there can be multiple items in the cart? Thanks in advance Edd hi, I'm integrating google checkout on my website using php. anyone have any idea if google checkout take payment on website just like paypal payment pro??? Looking forward. Best regards Hi, I have set up a simple shopping cart with a coupon code function. I am having an issue with the Update basket and Checkout buttons, when you click update basket it loads the /checkout/ page but then redirects back to the /cart/ after a couple of seconds when it should just load a new page saying 'Shopping basket successfully updated' - also, when you click the proceed to checkout button it does the same, loads the /checkout/ page (which is correct) but then redirects back to /cart/. Here is the php code I have setup: // View Shopping Basket if (!isset($_GET['action']) || $_GET['action'] == 'products') { // Check if the shopping basket is empty if ($cart->get_num_products(session_id()) <= 0) { output('Your shopping basket contains no products!'); } else { if (!isset($_POST['submit'])) { $tpl->set('body', $body->fetch('index.tpl.php')); } else { $cart->update_contents(session_id()); output('Shopping basket successfully updated!'); redirect('/cart/', 2); } } } // Add Product to Cart if (isset($_GET['action']) && $_GET['action'] == 'add_product') { $product_id = isset($_GET['product_id']) && is_numeric($_GET['product_id']) ? (int) $_GET['product_id'] : 0; $cart->add_product(session_id(), $product_id, 1); output('Product successfully added! Please wait while we redirect you to your shopping basket.'); redirect('/cart/', 2); } if (isset($_SESSION['coupon_code'])){ unset($_SESSION['coupon_code']); } if (isset($_POST['go']) && $_POST['go'] != ''){ $_SESSION['coupon_code'] = $_POST['coupon_code']; header("location:/checkout/"); } Here is the HTML for the form: Code: [Select] <h1>My Basket</h1> <form method="post" action="/cart/"> <input type="hidden" name="submit" value="Update" /> <input type="hidden" name="go" value="true" /> <table class="tableGrid"> <tr> <th width="10%"><strong>Remove:</strong></th> <th width="60%"><strong>Product Name:</strong></th> <th width="10%"><strong>Price:</strong></th> <th width="10%"><strong>Qty:</strong></th> <th width="10%"><strong>Total:</strong></th> </tr> <?php foreach ($GLOBALS['cart']->get_contents(session_id()) as $product) { ?> <tr> <td align="center" width="10%"><input type="checkbox" name="delete<?php echo $product['cart_id']; ?>" value="yes" /></td> <td width="60%"><a href="<?php echo get_url('/products/', $product['category_id'], $product['product_id'], $product['product_name']); ?>"><?php echo $product['product_name']; ?></a> <span class="important">* <?php echo $product['stock'] >= $product['quantity'] ? 'Available' : 'Not Enough In Stock'; ?></span></td> <td width="10%" align="center"><?php echo get_price($product['price']); ?></td> <td width="10%" align="center"><input type="text" name="quantity<?php echo $product['cart_id']; ?>" value="<?php echo $product['quantity']; ?>" maxlength="10" style="width: 30px;" /></td> <td width="10%" align="center"><?php echo get_price($product['price'] * $product['quantity']); ?></td> </tr> <?php } ?> </table><br /> <div class="main_box" style="height: 26px;"> <div style="float: right;">Subtotal: <strong><?php echo get_price($GLOBALS['cart']->get_cart_total(session_id())); ?></strong></div> <div style="float: left;"> <label><strong>If you have a promotion voucher code please enter it he </strong></label> <input type="text" name="coupon_code" id="coupon_code" value="" /> </div> </div><br /> <div align="center"><input type="image" src="<?php echo '/' . $config['image_path']; ?>button_cart_update.gif" border="0" alt="Update Shopping Basket" /> <a href="/shop-11/"><img src="<?php echo '/' . $config['image_path']; ?>button_continue.gif" border="0" alt="Continue Shopping" /></a> <input type="image" name="checkout" src="<?php echo '/' . $config['image_path']; ?>button_checkout.gif" border="0" alt="Proceed to Checkout" /></div> </form> If anybody can spot whats wrong I would really appreciate it. - It is probably something so simple but I am finding ti quite frustrating. Thanks, Paul Hi all, I am looking to integrate Paypal Express checkout on my site and have been working with the API today. I have got the code working in a static state with predefined payment amounts but I am having trouble making this dynamic. When you first submit a request to set up an express checkout you send the payment amount along with it. The paypal server then makes the checkout and the user is redirected to the paypal site to login and authenticate. From here they click to be redirected back to my site where I have a pay button which when clicked submits the final request to confirm the payment. I am sure there must be a simple solution to this because so many people use paypal already but when you submit the final confirmation request, you have to send the payment amount again, but because the page redirects onto the paypal page inbetween, I can't use a session variable to store the amount. How have other people overcome this? Thanks Hey guys! I need your help with some issues. Firstly, I have an own website with a database filled with products, and also a template page(template.php) for each product. Problem is that I don't know how to generate each product from the database in the template.php file using their id from the database. How can I do this? Second problem, I got an own checkout and I don't know how to redirect the customer to a "thank you for buying" page after clicking "Finish Order". It sends the customer to a white page where it says: "Thanks for buying!". Third and last thing, do you guys know where can I find a php checkout template to follow? Thanks in advance for your answers! Cheers! Hi, Firstly, apologies if this is in the wrong place in the forum to post this. I have a website, I use PHP in various places to pull/push info from/to a mySQL database, i'm fairly happy with PHP and its uses. I've recently started to use the Google checkout widget on the site for a proposed webstore (to go live at a later date), this has the ability to 'sell' download URL's or keys. I like the idea of a customer being able to purchase multiple MP3 downloads and them being given a URL that gives them the links for the MP3's selected. This is probably beyond anything i've ever done with PHP though so I need to understand the architecture........I understand that, given a list of items from the store, I can run a query to display a list of stored URL's for those items - and I'm sure I can find code that will give me a random URL that will 'expire' after an amount of time. My question is, how to get the list of items ordered from the google checkout?? I'm sure this has something to do with API's - but I don't know what they are, presumably there is some kind of table in Google that I can tap into to get the product info?? any help would be very much appreciated. ....oh, and i'm sure people are going to ask "why are you using Google checkout", the answer being, for me, it seems simple, effective and free! (but i'm open to suggestions.) Darren Hi, I'm building a webshop and im stuck at the checkout. I'm using this Shopping Cart class http://www.webforcecart.com/manual.html The cart is stored as an object in $_SESSION[cart]. This method Code: [Select] print_r($cart->get_contents());would get this as output: Array ( => Array ( [id] => 7 [qty] => 1 [price] => 11.00 [info] => Test [subtotal] => 11 ) [1] => Array ( [id] => 6 [qty] => 2 [price] => 19.00 [info] => White 0 [subtotal] => 38 ) ) In the table Order I would like to store order-id customer-id total products total quantity total price date In the table Orderrow I would like to sto order-id, product-id, product-name, quantity, price, subtotal I know i can get the order-id with the function mysql_insert_id() but how can i store each product in the array with their info in the table Orderrow? Or is there a better way to do this? please advice me, thank you. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=306254.0 Dear forum, I`m always trying hard, but after 5 hours I really need some help in php coding. My problem deals with my checkout page for woocommerce. At the moment, my legal terms are above the total-order-table where u can find the booked product, order-subtotal, order-total and tex-total. But I need to display the legal terms under my total-order table. I need the terms directly above the "Buy now" button. Do you guys know which file to modify ? I tried everything. Nothing worked for me. You will find a picture in this post. There you can see my problem. Would be pretty nice if you can give me some information. Kind regards,
Hi guys, I want my application to run a triggered process based on time to execute some tasks, what is the best approach? Thanks I have been trying to figure out how this is done? One php file and all that changes is the name of the brand and the logo. This has to be clickable from a menu and also if a user changes the brand name it changes to the appropriate name and logo. Any ideas as to how this is done? If you can guide me in the right direction or give me an example of how this is done would be greatly appreciated. Thanks. http://www.drivermanager.com/en/download-confirmation.php?brand=compaq&logo= i have a form for which the data is sent to a process page via jquery like so: Code: [Select] jQuery.post('<?php echo $this->site_root; ?>/modules/new_post_process.php',{ message:jQuery("#message_contents").val() } ,function(data) {etc... new_post_process checks the contents of message like so: if (empty($message) && empty($error)) { $is_error = true; $error = 'Please Enter A Message'; } the problem is that it always throws this message even when the textarea isnt empty. however after the error has appeared if i submit again it goes through fine. I suppressed the error and tried and the database gets populated with an empty value which means it is indeed empty. so why does it work on the second time around? I am using CKEditor for the textarea. everything else gets submitted normally but this textarea. heres the full code: the textarea: Code: [Select] <textarea cols="80" rows="10" id="message_contents"></textarea> Code: [Select] jQuery("#new_post_form").submit(function() { jQuery.post('<?php echo $this->site_root; ?>/modules/new_post_process.php',{ user_name:jQuery("#user_name").val(), redirect_url:jQuery("#redirect_url").val(), subject:jQuery("#subject_field").val(), forum_id:jQuery("#fid").val(), topic_id:jQuery("#tid").val(), method:jQuery("#method").val(), message:jQuery("#message_contents").val() } ,function(data) { if (data == 1) { jQuery("#process_info").removeClass().addClass("subject_okay").html("<img src=\"<?php echo $this->template_path; ?>icons/small_tick.png\" alt=\"icon\" />Redirecting...").fadeIn("slow"); var URL = jQuery("#redirect_url").val(); document.location = URL; } else { jQuery("#reply_btn").css("visibility", "visible"); jQuery("#draft_btn").css("visibility", "visible"); jQuery("#process_info").removeClass().addClass("subject_error").html('<img src="<?php echo $this->template_path; ?>icons/small_error.png" alt="icon" /> ' + data).fadeIn("slow"); } }); and the process page: if (isset($_POST['subject'])) { $message = $_POST['message']; if (empty($message) && empty($error)) { $is_error = true; $error = 'Please Enter A Message'; } if (empty($error) && $is_error == false) { $query = $link->prepare("INSERT INTO ".TBL_PREFIX."posts (p_fid, p_tid, p_poster, p_name, p_content, p_time_posted) VALUES ('$forum_id', '$topic_id', '$user_name', '$subject', '$message', '".$config['time_now']."') ") or die(print_link_error()); echo "1"; } else { echo $error.'-'.$message; } This may spill over into java, just not quite sure yet! Basically what I am trying to do, is fill a box with text, click a button which runs a function which send the text in the box via a JSON request to an external server. The JSON works fine, I just want a way of submitting the string which hopefully doesnt involve a form, but its the only way I can think of! Any other ideas? hi, is there a way to tell php to do a process again? example: Code: [Select] $draft_number=rand(1, 15); if($draft_number == 5){ START OVER AT TOP } else { $sql1 = "UPDATE names SET draft = '$draft_number' WHERE id = '$uid'"; $result1 = mysql_query($sql1) or die('Error, Check you fields and try again.'); } Hey guys, I've hit a huge obstacle in my coding process of a script I am writing. It is basically an uploading interface script and it works like this. I have files on my server and I want a user to click a button which fires a php script which in turn fires a bash script which IN TURN fires the uploading program (plowshare). So to make it simple: user logs in, sees upload button. Clicks it, file starts uploading. I then want the user to see "upload initiated" and that's it. The problem is that with what I have now, the script just won't finish loading until the file has been uploaded and as a matter of fact I don't even think it is uploading anything :S Here are the scripts: PHP interface to call the bash script: Code: [Select] <?php error_reporting(E_ALL); function run_in_background($Command, $Priority = 0) { if ($Priority) $PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!"); else $PID = shell_exec("nohup $Command 2> /dev/null & echo $!"); return($PID); } function is_process_running($PID) { exec("ps $PID", $ProcessState); return(count($ProcessState) >= 2); } $file = $_GET['file']; // Location of file relative to the index $where = $_GET['where']; // Absolute index location $absolute = '/var/www/vhosts/animekyun.com/httpdocs/icarus/'; $where = $absolute . $where; //$outfile ='log'; echo $where . $file . '<br>'; echo "<h2>The upload has been initiated!</h2>"; $ps = run_in_background("/bin/sh uploadparser.sh $file $where > $outfile"); while(is_process_running($ps)) //echo $output; ?> Bash script to call uploading program: Code: [Select] #!/bin/sh { FILE=$1 WHERE=$2 FILENAME="/var/www/vhosts/animekyun.com/httpdocs/icarus/debug/debug_mu_$FILE" FILENAME2="/var/www/vhosts/animekyun.com/httpdocs/icarus/debug/debug_multi_$FILE" /usr/local/bin/plowup megaupload "$WHERE$FILE" >> "$FILENAME".txt 2>&1 /usr/local/bin/plowup multiupload "$WHERE$FILE" >> "$FILENAME2".txt 2>&1 } & this works fine when I pass the variables as arguments in CLI I hope i have been clear enough, it does seem rather confusing I have this code: $shell = new COM('WScript.Shell'); $shell->Run("C:\WINDOWS\system32\cmd.exe /K ".$ini['indexer']['command'], 0, false); When it runs, it opens the command line, but then when it is done, it leaves the process open. How can I close it when the process is complete? I have a full working order form in PHP. I process it and display it with a process page called "process.php." Whenever this information is displayed on the web page "process.php" I also want it to send me an e-mail with all of the information that it just processed. i.e. Checked checkboxes, text entered, etc. Whenever I try to send the contents of "process.php" to an email $message = include 'process.php'; the process page just goes through an infinite loop displaying itself over and over again instead of sending itself in an email.
Edited by AP_King7, 20 August 2014 - 10:51 AM. |