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); }
static function getProductsFromBasket($image = FALSE) { try { self::init(); $products = []; $productModel = new ProductTableModel(); $productModel->setTable('product as p'); $imageModel = new ImageTableModel(); foreach (self::$basket as $id => $quantity) { if ($id !== 'id' && is_int($id)) { $productModel->setId($id); $product = $productModel->readRecordsById('id', 'p.title, p.price')[0]; if ($image) { $imageModel->setId($id); $imageModel->setTable('image'); $product['image'] = $imageModel->readRecordsById('product_id', 'image', 'AND main = 1')[0]['image']; } $product['total'] = (int) $product['price'] * $quantity; if (is_array($product)) { $products[$id] = new Product($id, $quantity); $products[$id]->setData($product); } } } return $products; } catch (Exception $ex) { Basket::cleanBasket(); Basket::init(); header('Location: /'); exit; } }
public function deleteImageAction() { header('Content-Type: application/json; charset=utf-8'); header('Cache-Control: no-store, no-cache'); header('Expires: ' . date('r')); if (filter_has_var(INPUT_GET, 'id') && filter_has_var(INPUT_GET, 'image')) { $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); $image = json_decode(filter_input(INPUT_GET, 'image')); } else { return FALSE; } $model = new ImageTableModel(); $model->setId($id); $model->setTable('image'); $model->deleteRecord(); Helper::deleteFile($image); echo TRUE; }
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); } }