Esempio n. 1
0
function homeAction($sPage)
{
    require ROOT . 'inc/site.header.inc.php';
    $aCategories = CategoryManager::getAll();
    $aProducts = ProductManager::getRandom(4, 1);
    require ROOT . 'src/ecommerce/view/home.php';
    require ROOT . 'inc/site.footer.inc.php';
}
 /**
  * Convert a product array into a product object.
  *
  * @param array $aProduct product.
  *
  * @return Product converted product.
  */
 private static function convertToObject($aProduct)
 {
     $oProduct = new Product();
     $oProduct->setId(intval($aProduct['id']));
     $oProduct->setName($aProduct['name']);
     $oProduct->setDescription($aProduct['description']);
     $oProduct->setImage($aProduct['image']);
     $oProduct->setPrice(floatval($aProduct['price']));
     $oProduct->setRating(intval($aProduct['rating']));
     $oProduct->setActive(intval($aProduct['active']));
     $aCategories = CategoryManager::getFromProductId($oProduct->getId());
     foreach ($aCategories as $oCategory) {
         $oProduct->addCategory($oCategory);
     }
     return $oProduct;
 }
 private function editAction()
 {
     // no id => redirect home
     if (!array_key_exists('id', $_GET)) {
         $oProduct = new Product();
     } else {
         $iId = intval($_GET['id']);
         $oProduct = ProductManager::get($iId);
     }
     //  if (array_key_exists('addProduct', $_POST)) {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $oProduct = new Product();
         $oProduct->setName($_POST['name']);
         $oProduct->setPrice($_POST['price']);
         $oProduct->setDescription($_POST['description']);
         if (array_key_exists('categories', $_POST)) {
             foreach ($_POST['categories'] as $iCategoryId) {
                 $oProduct->addCategory(CategoryManager::get($iCategoryId));
             }
         }
         if (array_key_exists('product-id', $_POST)) {
             // retourne Id du nouveau produit. Sinon null
             $iProductId = $_POST['product-id'];
             $oProduct->setId($iProductId);
             ProductManager::update($oProduct);
         } else {
             // retourne Id du nouveau produit créé. Sinon null
             $iProductId = ProductManager::create($oProduct);
             // Compléter l'objet par l'id du produit créé
             $oProduct->setId($iProductId);
         }
         if (!array_key_exists('image', $_POST)) {
             $temp = explode(".", $_FILES["image"]["name"]);
             $ext = $temp[count($temp) - 1];
             $newfilename = "images/product/" . $iProductId . '.' . $ext;
             $uploadfile = ROOT . $newfilename;
             move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile);
             $oProduct->setImage($newfilename);
             ProductManager::update($oProduct);
         }
         $aComments = CommentManager::getAllFromProduct($oProduct);
         $aSimilarProducts = ProductManager::getRandom(5, 1);
         $aCategories = CategoryManager::getAll();
         require ROOT . 'src/ecommerce/view/product/show.php';
     } else {
         if (null === $oProduct) {
             $this->homeAction();
             return;
         }
         $aSimilarProducts = ProductManager::getRandom(5, 1);
         $aCategories = CategoryManager::getAll();
         require ROOT . 'src/ecommerce/view/product/edit.php';
     }
 }
 private function homeAction()
 {
     $aCategories = CategoryManager::getAll();
     $aProducts = ProductManager::getRandom(4, 1);
     require ROOT . 'src/ecommerce/view/home.php';
 }
 private function statsAction()
 {
     $aProducts = CategoryManager::getNumberProducts();
     require ROOT . 'src/ecommerce/view/category/stats.php';
 }
Esempio n. 6
0
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.php">My E-Commerce Website</a>
        </div>

        <div class="collapse navbar-collapse" id="e-commerce">
            <ul class="nav navbar-nav">
                <li><a href="index.php"><span class="glyphicon glyphicon-home"></span>&nbsp;Accueil</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span
                        class="glyphicon glyphicon-tags"></span>&nbsp;&nbsp;Catégories <span
                        class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <?php 
foreach (CategoryManager::getAll() as $oMenuCategory) {
    ?>
                            <?php 
    /* @var $oMenuCategory Category */
    ?>
                            <li><a href="<?php 
    echo $oMenuCategory->getUrl();
    ?>
"><span
                                class="glyphicon glyphicon-tag"></span>&nbsp;<?php 
    echo $oMenuCategory->getName();
    ?>
                            </a>
                            </li>
                            <?php 
}