Example #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';
}
 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 removeAction()
 {
     $iId = intval($_GET['id']);
     $oCategory = CategoryManager::get($iId);
     try {
         $result = CategoryManager::remove($iId);
         $aCategories = CategoryManager::getAll();
         require ROOT . 'src/ecommerce/view/category/list.php';
     } catch (\Exception $e) {
         $result = $e->getMessage();
         echo "La catégorie ne peux pas être supprimée car elle contient des produits";
     }
 }
Example #5
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 
}