function indexAction() { $fc = FrontController::getInstance(); $model = new FrontModel(); $popProducts = (new IndexWidgets())->recAndPopProductsWidget('popular', 6); $recProducts = (new IndexWidgets())->recAndPopProductsWidget('recommended'); $model->setData(['slides' => IndexWidgets::getSliderWidget(), 'currentCategory' => (new IndexWidgets())->currentCategoryWidget(Helper::getSiteConfig()->currentCategoryWidget), 'popularProducts' => Generator::popularProducts($popProducts, 6), 'recommendedProducts' => Generator::recommendedProducts($recProducts)]); $output = $model->render('../views/index.php', 'main'); $fc->setPage($output); }
public static function sideBarMenuWidget() { $catsNsubs = IndexWidgets::getCatsAndSubCats(TRUE); if (count($catsNsubs) !== 2) { throw new Exception('Передан неверный массив категорий и подкатегорий'); } $cats = current($catsNsubs); $subs = end($catsNsubs); foreach ($cats as $key => $c) { foreach ($subs as $s) { if ($c['id'] === $s['category_id']) { $cats[$key]['subcategories'][] = $s; } } } return ['catsAndSubCats' => $cats, 'brands' => (new ProductTableModel())->getBrandsOrColors('brand'), 'colors' => (new ProductTableModel())->getBrandsOrColors('color')]; }
function __construct() { parent::__construct(); $this->setData(['sideBarData' => IndexWidgets::sideBarMenuWidget(), 'footerData' => IndexWidgets::footerWidget()]); Helper::redirectChecker(); }
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); } }