Ejemplo n.º 1
0
 function viewAction()
 {
     $fc = FrontController::getInstance();
     $model = new FrontModel();
     $id = filter_var($fc->getParams()['id'], FILTER_SANITIZE_NUMBER_INT);
     if (!$id) {
         header('Location: /admin/notFound');
         exit;
     }
     $productModel = new ProductTableModel();
     $productModel->setId($id);
     $productModel->setTable('product');
     $ImageModel = new ImageTableModel();
     $ImageModel->setId($id);
     $ImageModel->setTable('image');
     $images = $ImageModel->readRecordsById('product_id', '*', 'ORDER BY main');
     $product = $productModel->readRecordsById()[0];
     $categoryModel = new CategoryTableModel();
     $product['category'] = $categoryModel->getCategoryById($product['category_id'])['category_name'];
     $product['subCategory'] = $categoryModel->getSubCategoryById($product['subcategory_id'])['subcategory_name'];
     if (!$product) {
         header('Location: /admin/notFound');
         exit;
     }
     $recProducts = (new IndexWidgets())->recAndPopProductsWidget('recommended');
     $model->setData(['product' => $product, 'images' => $images, 'recommendedProducts' => Generator::recommendedProducts($recProducts)]);
     $output = $model->render('../views/product/product.php', 'withoutSlider');
     $fc->setPage($output);
 }
Ejemplo n.º 2
0
 public function getAllProductsWidget($fields = '*', $condition = '')
 {
     $model = new ProductTableModel();
     return $model->getAllProducts($fields, $condition);
 }
Ejemplo n.º 3
0
 static function getProductsList($serializedList)
 {
     $list = unserialize($serializedList);
     $result = [];
     foreach ($list as $key => $item) {
         if ($key !== 'id') {
             $model = new ProductTableModel();
             $model->setTable('product');
             $model->setId($key);
             $result[$key] = ['title' => $model->readRecordsById()[0]['title'], 'quantity' => $item];
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 public function SearchProductAction()
 {
     header('Content-type: application/json; charset=utf-8');
     header('Cache-Control: no-store, no-cache');
     header('Expires: ' . date('r'));
     $text = Validate::validateInputVar('text', 'INPUT_GET', 'str');
     $model = new ProductTableModel();
     $model->setTable('product');
     $model->readAllRecords('id, title', "WHERE title LIKE '%{$text}%'");
     echo json_encode($model->getAllRecords());
 }
Ejemplo n.º 5
0
 public function editProductAction()
 {
     $fc = FrontController::getInstance();
     $model = new AdminModel('Редактирование товара');
     $id = filter_var($fc->getParams()['product'], FILTER_SANITIZE_STRING);
     $productModel = new ProductTableModel();
     $productModel->setId($id);
     $productModel->setTable('product');
     $imageModel = new ImageTableModel();
     $imageModel->setTable('image');
     $imageModel->setId($id);
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $productModel->setData();
         $productModel->updateProduct();
         $imageModel = new ImageTableModel($productModel->getId());
         $imageModel->setTable('image');
         $imageModel->setId($productModel->getId());
         $imageModel->setData();
         $imageModel->addAllImages();
         Session::setMsg('Товар успешно обновлен', 'success');
         header('Location: /admin/view/product/' . $productModel->getId());
         exit;
     } else {
         if (!$id) {
             header('Location: /admin/notFound');
             exit;
         }
         $product = $productModel->getAllProducts('*', "WHERE product.id = {$id} GROUP BY product.id");
         $imageModel->readRecordsById('product_id');
         if (empty($product)) {
             header('Location: /admin/NotFound');
             exit;
         } else {
             $model->setData(['products' => $productModel->getAllProducts('*', "WHERE product.id = {$id} GROUP BY product.id"), 'images' => $imageModel->getRecordsById()]);
         }
         $catsAndSub = IndexWidgets::getCatsAndSubCats();
         $model->categoryList = $catsAndSub['cats'];
         //used magic __set
         $model->subCategoryList = $catsAndSub['subcats'];
         //used magic __set
         $output = $model->render('../views/admin/product/edit.php', 'admin');
         $fc->setPage($output);
     }
 }