Shop - Checkout

 

There are three steps to complete the checkout

  1. Fill out the shipping and payment info
  2. Confirm the ordered items, shipping and payment info and enter the payment method.
  3. Save the order information to the database. If the payment method is COD ( cash on delivery ) go straight to the thank you page. If the customer choose to pay with paypal submit the payment info to paypal server.

Below is the code for checkout.php

Source code : checkout.php

<?php
require_once 'library/config.php';
require_once 'library/cart-functions.php';
require_once 'library/checkout-functions.php';

if (isCartEmpty()) {
   // the shopping cart is still empty
   // so checkout is not allowed
   header('Location: cart.php');
} else if (isset($_GET['step'])
           && (int)$_GET['step'] > 0
           && (int)$_GET['step'] <= 3) {
   $step = (int)$_GET['step'];

   $includeFile = '';
   if ($step == 1) {
      $includeFile = 'shippingAndPaymentInfo.php';
      $pageTitle = 'Checkout - Step 1 of 2';
   } else if ($step == 2) {
      $includeFile = 'checkoutConfirmation.php';
      $pageTitle = 'Checkout - Step 2 of 2';
   } else if ($step == 3) {
      $orderId = saveOrder();
      $orderAmount = getOrderAmount($orderId);

      $_SESSION['orderId'] = $orderId;

      // our next action depends on the payment method
      // if the payment method is COD then show the
      // success page but when paypal is selected
      // send the order details to paypal
      if ($_POST['hidPaymentMethod'] == 'cod') {
         header('Location: success.php');
         exit;
      } else {
         $includeFile = 'paypal/payment.php';
      }
   }
} else {
   // missing or invalid step number, just redirect
   header('Location: index.php');
}

require_once 'include/header.php';
?>
<script language="JavaScript" type="text/javascript" src="library/checkout.js"></script>
<?php
require_once "include/$includeFile";
require_once 'include/footer.php';
?>

On top of this file we check if the shoppping cart is empty. If it is empty the customer is redirected to the cart page. Just to let her know that her shopping cart is still empty and so she cannot checkout.

Just like the main page ( index.php ) the checkout page "out sourced" almost everything to other pages. The main part of this file is the switch to load appropriate file depending on which checkout step the customer is on.

And now, let's take a better look at these checkout processes one step at a time.

 

Get custom programming done at ScriptLance.com!

 

 

 

Online Shop - View Shopping Cart PHP MySQL Shopping Cart Tutorial : Online Shop - Checkout Online Shop - Shipping And Payment Info
Google
 
Web www.phpwebcommerce.com
 

At long last i'm finally able to update this site. Now the shopping cart can handle payment through paypal. As always you have any critiques, questions, comments or problems about this tutorial please tell me. Click here to send your feedback. And if you like this tutorial please link to this site. It will really help a lot :-)

 

 

My Experimental Lenses



PHP MySQL Shopping Cart Tutorial
Copyright © 2005 - 2008 www.phpwebcommerce.com