Skip to content

Instantly share code, notes, and snippets.

@Geczy
Created Apr 30, 2012
Embed
What would you like to do?

Introduction

Luna will be an eComerce platform to sell video games to customers.

Project Objectives

  • Offer a multitude of video game retail options.
  • Categorize all products.
<?php
$result = isset($_GET['cat']) && $_GET['cat'] != "all" ? mysql_query("SELECT * FROM login_products WHERE cid = ".$_GET['cat']." ORDER BY timestamp DESC LIMIT 6")
			: mysql_query("SELECT * FROM login_products ORDER BY timestamp DESC LIMIT 6");
		$i=0;
		while($row = mysql_fetch_array($result)){}
  • Show the customer their cart at all times.

Design / Organization

  • The site layout shows the home page and categories as a widget.
<?php
include_once('classes/class.shop.php');
include_once('header.php');
?>

    <div id="content" class="row-fluid span9">
        <div id="hotitem" class="row">
            <span class="span2">
                <h1>HOT ITEM!</h1>
                <p class="description">You'll love this product for this reason and that.</p>
                <b>$9.99</b><br/>
                <button class="btn btn-primary"><i class="icon-shopping-cart icon-white"></i>Add to cart</button>
            </span>
            <ul class="thumbnails span8">
                <li>
                <a href="#" class="thumbnail">
                    <img src="http://placehold.it/650x250" alt="" />
                </a>
                </li>
            </ul>
        </div>
        <!-- hotitem -->
        <hr class="span9" />

        <!-- hotdeals -->
        <ul class="thumbnails">

            <?php new Shop(); ?>

        </ul>

    </div>
    <!-- content -->
<?php include_once('footer.php'); ?>
  • A cart widget is also displayed on all pages. The objective is reached because the customer can see the cart at all times.

Features

  • Programming done in OOP.
<?php
class Generic {}
class Connect extends Generic {}
class Check extends Connect {}
class SignUp extends Connect {}
class Cart extends Connect {}
class Checkout extends Cart {}
  • Generic functions available for site-wide use.
<?php
function in_level() {

	if(!empty($_GET['lid'])) :

		$lid = $_GET['lid'];
		$page = isset($_GET['page'])?(int)$_GET['page']:1;
		$limit = 10;
		$StartIndex = $limit*($page-1);

		$sql = "SELECT * FROM login_users";
		$result = mysql_query($sql);

		$count = 0;
		while($row = mysql_fetch_array($result))
			if( array_intersect(array($lid),unserialize($row['user_level'])) ) $count++;

		if ($count > 0) {

			echo "<table class='table'>";
			echo "<thead><tr><th>Username</th><th>Real Name</th><th>E-Mail Address</th><th>Registered Date</th></tr></thead><tbody>";

			$sql = "SELECT * FROM login_users WHERE user_level LIKE '%:\"$lid\";%' ORDER BY timestamp DESC LIMIT $StartIndex,$limit";
			$result = mysql_query($sql);
			$i = 0;
			while ($row = mysql_fetch_array($result)) {

						if(in_array(1, unserialize($row['user_level']))) { $admin = " <span class='label label-important'>admin</span>"; } else $admin = '';
						if($row['restricted'] == 1) { $restrict = " <span class='label label-warning'>restricted</span>"; } else $restrict = '';

						$timestamp = strtotime($row['timestamp']);
						$reg_date = date('d M y @ H:i' ,$timestamp);

						$email = $row['email'];
						echo '<tr><td><a href="users.php?uid='.$row['user_id'].'">'. $row['username'].'</a>' . $admin . $restrict .'</td><td>'.$row['name'].'</td><td>'.$email.'</td><td>'.$reg_date.'</td></tr>';
				}

			echo "</tbody></table>";
			echo pagination('login_users','ORDER BY timestamp DESC',"$count");
		} else {
			echo "<p>No users found!</p>";
		}

	endif;

}
  • Design shows a featured product on the front end.
  • All products are categorized into video game genres.
<?php
private function addcategory() {

		if(isset($_POST['add_category']) && empty($this->error)) {

			$sql = "SELECT * FROM categories WHERE name = '$this->category'";
			$count = parent::numRows($sql);
  • Comprehensive admin panel to alter the site
  • Cart items can be edited on the fly using AJAX
  • Dynamically update total price information using AJAX
  • Integrated Paypal into checkout

Implementation

  • PHP
    • Object oriented PHP
    • Password verification
    • Session hijack prevention
    • Shop product updates
    • Comprehensive settings panel
  • MySQL
    • SQL injection prevention
<?php
	public function secure($var) {

		// This really is deprecated but some servers still use magic quotes
		if (get_magic_quotes_gpc()) {
			$var = stripslashes(trim($var));
		}

		if ( ! is_array($var) )
			$var = mysql_real_escape_string(trim($var));

		return $var;

	}
* Efficient SQL queries
* Effective use of loops for data display
<?php
	while($row = mysql_fetch_array($result)){ $i++;
			$image = $this->imageUrl($row['image']);
	?>

		<div class="span3">
        <div class="thumbnail">
            <img width="150" height="150" src="<?php echo $image; ?>" alt="<?php echo $row['name']; ?>" />
            <h5><?php echo $row['name']; ?></h5>
            <p><?php echo $row['description']; ?></p>
            <p><?php echo $this->displayPrice($row['price']); ?></p>
            <p>
            <form action="cart.php" class="form-horizontal" method="POST">
                <input class="span1" type="text" name="quantity" value="1"/>
                <input type="hidden" name="productId" value="<?php echo $row['id']; ?>"/>
                <input type="hidden" name="action" value="add"/>
                <i class="icon-shopping-cart icon-white"></i>
                <input type="submit" name="addItem" class="btn btn-success" value="Add to cart" />
            </form>
            </p>
        </div>
        </div>

   <?php if($i%3 == 0) echo "<p><br clear='all'/><br/></p>"; }
  • Visual photos

    • Product design
  • CSS

    • Beautiful Tables
    • Pretty Buttons
    • Smashing Font
  • Security

    • Session hijack fixed
    • MySQL SQL injection fixed
    • XSS vulnerabilities fixed
  • AJAX

    • Used a separate script ajax.php to handle all AJAX requests

Website management

  • Maintenance a breeze with commented and OOP style code
  • Separated account levels
  • Update products on the fly
  • Update categories on the fly
  • Update account levels on the fly

Member Roles

  • Designer

    • Joseph - Will draw up a design of the website
  • Programmers

    • Matt - Team leader, PHP base developer
    • Adam - Team member, PHP developer and settings fractor
    • Ryan - Team member, PHP cart and product implementation

Activity log

Conclusion

By doing this project, we didn't only learn many techniques and methods to build an working eComerce website, but also how to collaborate within a team, track change history using git and keep a unified design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment