Example #1
0
 public static function getProductsByCategory($category_id)
 {
     $db = Database::getDB();
     $category = CategoryDB::getCategory($category_id);
     $query = "SELECT * FROM products\n                  WHERE categoryID = '{$category_id}'\n                  ORDER BY productID";
     $result = $db->query($query);
     $products = array();
     foreach ($result as $row) {
         $product = new Product($category, $row['productCode'], $row['productName'], $row['listPrice']);
         $product->setId($row['productID']);
         $products[] = $product;
     }
     return $products;
 }
Example #2
0
 public function getProduct($product_id)
 {
     $db = Database::getDB();
     $query = "SELECT * FROM products\n                  WHERE productID = '{$product_id}'";
     $result = $db->query($query);
     $row = $result->fetch();
     $category = CategoryDB::getCategory($row['categoryID']);
     $product = new Product();
     $product->setCategory($category);
     $product->setId($row['productID']);
     $product->setCode($row['productCode']);
     $product->setName($row['productName']);
     $product->setPrice($row['listPrice']);
     return $product;
 }
Example #3
0
 private function createProducts()
 {
     $ipad = new Product();
     $ipad->setId(1);
     $ipad->setDescription('A brand new 16 GIGA iPad');
     $ipad->setPrice('499.00');
     $this->allProducts[] = $ipad;
     $iphone = new Product();
     $iphone->setId(2);
     $iphone->setDescription('A brand new 32 GIGA iPhone');
     $iphone->setPrice(599.0);
     $this->allProducts[] = $iphone;
     $ipod = new Product();
     $ipod->setId(3);
     $ipod->setDescription('A brand new 8 GIGA iPod');
     $ipod->setPrice(299.0);
     $this->allProducts[] = $ipod;
 }
Example #4
0
 public static function getProductsByCategory($category_id)
 {
     $db = Database::getDB();
     $category = CategoryDB::getCategory($category_id);
     $query = 'SELECT * FROM products
               WHERE products.categoryID = :category_id
               ORDER BY productID';
     $statement = $db->prepare($query);
     $statement->bindValue(":category_id", $category_id);
     $statement->execute();
     $rows = $statement->fetchAll();
     $statement->closeCursor();
     foreach ($rows as $row) {
         $product = new Product($category, $row['productCode'], $row['productName'], $row['listPrice']);
         $product->setId($row['productID']);
         $products[] = $product;
     }
     return $products;
 }
Example #5
0
<?php

require_once __DIR__ . '/../common/autoload_cms.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $entity = new Product();
    $entity->setId($_GET['id'])->setUserId($_POST['user_id'])->setName($_POST['name'])->setPrice($_POST['price'])->setQuantity($_POST['quantity'])->setDateAdded(date('Y-m-d H:i:s'))->saveImage($_FILES['image']);
    $productCollection = new ProductCollection();
    $productCollection->save($entity);
    header('Location: product_list.php');
    exit;
}
$productCollection = new ProductCollection();
$product = $productCollection->one(array('id' => $_GET['id']));
$userCollection = new UserCollection();
$users = $userCollection->all();
require_once 'include/header.php';
?>

    <div class="container">
        <a href="product_image_list.php?product_id=<?php 
echo $product->getId();
?>
" class="btn btn-success">Gallery</a>
        <br><br>

        <form method="post" action="" enctype="multipart/form-data">
            <div class="form-group">
                <label for="user">User:</label>
                <select name="user_id" id="user" class="form-control">
                    <?php 
foreach ($users as $user) {