Пример #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 Comment array into a Comment object.
  *
  * @param array $aComment Comment.
  *
  * @return Comment converted object.
  */
 private static function convertToObject($aComment)
 {
     $oComment = new Comment();
     $oComment->setComment($aComment['comment']);
     $oComment->setMark(intval($aComment['mark']));
     $oComment->setDate($aComment['date']);
     $oComment->setName($aComment['name']);
     $oUser = new User();
     $oUser->setEmail($aComment['user_email']);
     $oComment->setUser(UserManager::get($oUser));
     $oComment->setProduct(ProductManager::get($aComment['product_id']));
     return $oComment;
 }
 public static function addProduct($id)
 {
     if (!isset($_SESSION["cart"])) {
         $_SESSION["cart"] = [];
     }
     $product = ProductManager::getProduct($id);
     $cartProduct = new CartProduct($product, 1);
     if (array_key_exists($cartProduct->getId(), $_SESSION["cart"])) {
         $quantity = $_SESSION["cart"][$cartProduct->getId()]->getQuantity();
         $_SESSION["cart"][$cartProduct->getId()]->setQuantity($quantity + 1);
     } else {
         $_SESSION["cart"][$cartProduct->getId()] = $cartProduct;
     }
 }
 public function updateProductAction()
 {
     if (isset($_GET["id"])) {
         $product = ProductManager::getProduct($_GET["id"]);
     }
     require "src/Ecommerce/view/back/updateproduct.php";
     if (isset($_POST["update"])) {
         if (!empty($_POST["name"]) && !empty($_POST["description"]) && !empty($_POST["price"])) {
             ProductManager::updateProduct($_POST["id"], $_POST["name"], $_POST["description"], $_POST["price"]);
             header("Location: index.php?controller=Back&method=management");
         } else {
             echo "champs incomplets";
         }
     }
 }
 private function showAction()
 {
     // no id => redirect home
     if (!array_key_exists('id', $_GET)) {
         $this->homeAction();
         return;
     }
     $iId = intval($_GET['id']);
     $oCategory = CategoryManager::get($iId);
     // product not found => redirect home
     if (null === $oCategory) {
         $this->homeAction();
         return;
     } else {
         $aProducts = ProductManager::getAllFromCategory($oCategory);
         require ROOT . 'src/ecommerce/view/category/show.php';
         //}
     }
 }
 public static function getAll()
 {
     $aAll = array();
     if (array_key_exists('cart', $_SESSION)) {
         foreach ($_SESSION['cart'] as $iProductId => $iQuantity) {
             $oProduct = ProductManager::get($iProductId);
             if ($oProduct) {
                 // product should exists !
                 if (false === $oProduct) {
                     continue;
                 }
                 // convert to CartProduct
                 $oProduct = CartProduct::create($oProduct);
                 $oProduct->setQuantity($iQuantity);
                 $aAll[] = $oProduct;
             }
         }
     }
     return $aAll;
 }
 private function archiveAction()
 {
     $iId = intval($_GET['id']);
     $oProduct = ProductManager::get($iId);
     if ($oProduct->getActive() == 1) {
         $result = ProductManager::archive($iId);
     }
     if ($oProduct->getActive() == 0) {
         $result = ProductManager::display($iId);
     }
     $aProducts = ProductManager::getAll();
     require ROOT . 'src/ecommerce/view/product/list.php';
 }
 private function homeAction()
 {
     $aCategories = CategoryManager::getAll();
     $aProducts = ProductManager::getRandom(4, 1);
     require ROOT . 'src/ecommerce/view/home.php';
 }
 public function addToCartAction()
 {
     if (isset($_GET['id']) && ProductManager::getProduct($_GET['id'])) {
         CartProductManager::addProduct($_GET['id']);
     } else {
         header('Location: index.php');
     }
     header('Location: index.php?controller=Front&method=cart');
 }
 private function detailorderAction()
 {
     $id = intval($_GET['id']);
     $oOrder = ProductManager::getAllFromOrder($id);
     require ROOT . 'src/ecommerce/view/detailorder.php';
 }
 private function validateAction()
 {
     $iId = intval($_GET['id']);
     $email = $_GET['email'];
     $oProduct = ProductManager::get($iId);
     $oUser = UserManager::getFromEmail($email);
     $oComment = CommentManager::get($oProduct, $oUser);
     $oComment = CommentManager::validate($oProduct, $oUser);
 }