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 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; }
public function getProductsBySubcategoryIdAction() { header('Content-Type: application/json; charset=utf-8'); header('Cache-Control: no-store, no-cache'); header('Expires: ' . date('r')); $id = Validate::validateInputVar('id', 'INPUT_GET', 'int'); $model = new ProductTableModel(); $model->setTable('product AS p, image AS i'); $model->setId($id); echo json_encode($model->readRecordsById('subcategory_id', '*', 'AND i.product_id IN (p.id) AND i.main =1 LIMIT 4')); }