/** * Просмотр продуктов заданной категории * формат URL /product/view_products_by_category/<имя категории>/<тип - html или json> * @param $req */ public function view_products_by_category($req) { Auth::check_token(); $category_name = category::normalize_urlencode($req[0]); $type = isset($req[0]) && in_array($req[1], ['json', 'html']) ? $req[1] : 'json'; //указан ли вид и правильно ли $db = new T2_Db(); $category = $db->select_category_by_name($category_name); if (!$category) { echo json_encode(['result' => 'error', 'msg' => 'category does not exist']); die; } $products = $db->select_products_by_category_id($category['id']); if (!$products) { echo json_encode(['result' => 'error', 'msg' => 'no products in this category']); die; } if ($type == 'json') { echo json_encode(['result' => 'ok', 'product' => $products]); die; } $tpl = new Tpl_Obj(); $tpl->display('common/page_header.tpl'); $tpl->assign('products', $products); $tpl->display('product_view/prod_by_cat.tpl'); $tpl->display('common/page_footer.tpl'); }
/** * Удаление категории * формат URL /category/delete/<имя категории> * @param $req */ public function delete($req) { $name = self::normalize_urlencode($req[0]); $db = new T2_Db(); $check_category_name = $db->select_category_by_name($name); //проверим, существует ли категория if (!$check_category_name) { $out = ['result' => 'error', 'msg' => 'category does not exists']; echo json_encode($out); die; } $db->category_delete($name); $out = ['result' => 'ok']; echo json_encode($out); }