/**
  * @admin
  */
 public function productEdit($id)
 {
     $productModel = new ProductsModel();
     if (isset($_POST['editProductButton'])) {
         $name = $_POST['productName'];
         $desc = $_POST['desc'];
         $condition = $_POST['condition'];
         $quantity = $_POST['quantity'];
         $pic = $_POST['pic'];
         $category = $_POST['category'];
         $productId = $_POST['productId'];
         $oldCategory = $_POST['oldCategory'];
         $productModel->adminEditProduct($name, $desc, $condition, $quantity, $pic, $category, $productId, $oldCategory);
     }
     try {
         $product = $productModel->getProductById($id);
         $model["product"] = $product;
     } catch (\Exception $e) {
         header("Location: " . __MAIN_URL__ . __HOME_DIRECTORY__);
         exit;
     }
     $categoriesModel = new CategoriesModel();
     $categories = $categoriesModel->getAllCategories();
     $model["categories"] = $categories;
     return new View($model);
 }
Exemplo n.º 2
0
 public function edit($productId)
 {
     Functions::EditorAuthorization();
     $productModel = new ProductsModel();
     try {
         $product = $productModel->getProductById($productId);
         $model["product"] = $product;
     } catch (\Exception $e) {
         header("Location: " . __MAIN_URL__ . __HOME_DIRECTORY__);
         exit;
     }
     if (isset($_POST['editProductButton'])) {
         $quantity = (int) $_POST['quantity'];
         $category = (int) $_POST['category'];
         $oldCategory = (int) $_POST['oldCategory'];
         $productId = (int) $_POST['productId'];
         $errors = [];
         if ($quantity <= 0) {
             $errors[] = "Invalid quantity";
         }
         if ($category == 0) {
             $errors[] = "Invalid category";
         }
         if (count($errors) == 0) {
             $productModel = new ProductsModel();
             try {
                 $productModel->editProduct($productId, $quantity, $category, $oldCategory);
             } catch (\Exception $e) {
                 View::$viewBag['errors'] = $e->getMessage();
             }
         } else {
             View::$viewBag['errors'] = $errors;
         }
     }
     $categoriesModel = new CategoriesModel();
     $categories = $categoriesModel->getAllCategories();
     $model["categories"] = $categories;
     return new View($model);
 }