Retrieves a list of models based on the current search/filter conditions.
public search ( ) : CActiveDataProvider | ||
return | CActiveDataProvider | the data provider that can return the models based on the search/filter conditions. |
public function index() { // Check if user has sent a search query if ($query = Input::get('query', false)) { // Use the Elasticquent search method to search ElasticSearch $products = Product::search($query); } else { // Show all posts if no query is set $products = Product::all(); } return View::make('products', compact('products')); }
public function actionLocation() { $cat = Yii::app()->getRequest()->getQuery('cat'); $bname = Yii::app()->getRequest()->getQuery('keyword'); $catname = Category::model()->getCategoryName($cat); if ($cat == 'all' || empty($catname)) { $query = "SELECT * \n\t\t\t\t\t\tFROM `mm_product` \n\t\t\t\t\t\tWHERE `product_name` LIKE '" . $bname . "%' \n\t\t\t\t\t\tORDER BY `product_name` LIMIT 10"; } else { $query = "SELECT * \n\t\t\t\t\tFROM `mm_product` \n\t\t\t\t\tWHERE `product_name` LIKE '%" . $bname . "%'\n\t\t\t\t\tAND\t`product_category_id` IN (SELECT entity_id FROM category WHERE category_name LIKE '" . $catname . "')"; } $command = Yii::app()->db->createCommand($query); $result = $command->queryAll(); $model = new Product('search'); $model->unsetAttributes(); // clear any $model->product_name = $bname; $model->product_category = $catname; //send model object for search $this->render('index', array('dataProvider' => $model->search(), 'model' => $model)); /* $dataProvider=new CArrayDataProvider($result, array( 'sort'=>false, 'keyField'=>'id', //this is what will be considered your key field 'pagination'=>array( 'pageSize'=>30, //eureka! you can configure your pagination from here ), )); //echo '<pre>'; var_dump($pp); die(); $this->render('index',array( 'dataProvider'=>$dataProvider, ));*/ //throw new CHttpException(404,'The requested page does not exist.'); }
include_once "../config/core.php"; // check if logged in as admin include_once "login_checker.php"; // include classes include_once '../config/database.php'; include_once '../objects/product.php'; include_once '../objects/product_image.php'; include_once '../objects/product_pdf.php'; include_once '../objects/category.php'; // get database connection $database = new Database(); $db = $database->getConnection(); // initialize objects $product = new Product($db); $product_image = new ProductImage($db); $product_pdf = new ProductPdf($db); $category = new Category($db); // get search term $search_term = isset($_GET['s']) ? $_GET['s'] : ''; // set page title $page_title = "Product Search Results"; // include page header HTML include_once "layout_head.php"; // search products $stmt = $product->search($search_term, $from_record_num, $records_per_page); // count retrieved products $num = $stmt->rowCount(); // include products table HTML template include_once "read_products_template.php"; // include page footer HTML include_once "layout_foot.php";
$_SESSION['limit'] = 7; //���������� ��������� �������� ������ �� ��������� $limit = $_SESSION['limit']; } else { $_SESSION['limit'] += 7; $limit = $_SESSION['limit']; } } else { unset($_SESSION['limit']); $_SESSION['limit'] = 7; //���������� ��������� �������� ������ �� ��������� $limit = $_SESSION['limit']; } require_once 'class.php'; $obj = new Product(); switch ($_POST["form"]) { case 'selectId': $result = $obj->selectId($_POST['id'], $_POST['category'], $limit); echo json_encode($result); break; case 'search': $result = $obj->search($_POST["id"], $_POST["capacity"], $_POST["frame"], $_POST["price"], $_POST["waterproof"], $_POST['category'], $_POST["weight"], $_POST['sort'], $limit); echo json_encode($result); break; case 'moreInfo': $result = $obj->moreInfo($_POST["id"]); $result[0]['attr'] = unserialize($result[0]['attr']); $result[0]['img'] = unserialize($result[0]['img']); echo json_encode($result); break; }
$item->picture = HOST . "includes/webservices/images/" . $filename . "x" . $random . ".jpg"; $html .= "<tr>"; $html .= " <td><img src='" . $item->picture . "' height='40' width='40'/></td>"; $html .= " <td>storeid " . $item->storeid . "</td>"; $html .= " <td><a class='btn btn-primary' href='updatestorepic.php?id=" . $item->id . "'>Update</a></td>"; $html .= " <td><button class='btn btn-danger btndelete'>Delete <span hidden>" . $item->id . "</span></button></td>"; $html .= "</tr>"; } $filename = 0; echo $html; } else { echo "no data"; } } else { if ($_GET['itemtype'] == "product") { $items = Product::search($input); if (count($items) > 0) { foreach ($items as $item) { $filename++; $random = rand(0, 1); file_put_contents("images/" . $filename . "x" . $random . ".jpg", base64_decode($item->picture)); $item->picture = HOST . "includes/webservices/images/" . $filename . "x" . $random . ".jpg"; $html .= "<tr>"; $html .= " <td><img src='" . $item->picture . "' height='40' width='40'/></td>"; $html .= " <td>storeid " . $item->storeid . "</td>"; $html .= " <td>" . $item->name . "</td>"; $html .= " <td>" . $item->description . "</td>"; $html .= " <td><a class='btn btn-primary' href='updateproduct.php?id=" . $item->id . "'>Update</a></td>"; $html .= " <td><button class='btn btn-danger btndelete'>Delete <span hidden>" . $item->id . "</span></button></td>"; $html .= "</tr>"; }
* which is then json encoded and returned as a json file response */ $result = new stdClass(); $code = 200; /** * Process the search request */ if (isset($_POST['form']) && $_POST['form'] == "search") { if (isset($_POST['search_term']) && isset($_POST['search_type'])) { $search_term = $_POST['search_term']; $search_type = $_POST['search_type']; $result = ""; $filters = $_POST['filters']; require_once APPLICATION_PATH . MODEL_DIR . '/Product.php'; $order = new Product('replicated'); $result = $order->search($search_term, $filters, $search_type); } } elseif (isset($_POST['form']) && $_POST['form'] == "search_by_sku") { require_once APPLICATION_PATH . MODEL_DIR . '/Product.php'; $result = ""; $item_sku = $_POST['item_sku']; $products = new Product('replicated'); $result = $products->SearchItemsBySku($item_sku); } elseif (isset($_POST['form']) && $_POST['form'] == "master_products") { require_once APPLICATION_PATH . MODEL_DIR . '/Product.php'; $result = ""; $products = new Product('replicated'); $result = $order->getAllMasterProducts(); header('Content-Type: application/json'); echo json_encode(array("result" => $result)); } elseif (isset($_POST['form']) && $_POST['form'] == "get_search_history") {
<?php require_once $libpath = substr(str_replace('\\', '/', __DIR__), 0, -29) . 'library/initialize.php'; if (isset($_POST['keyword'])) { $keywords = htmlentities($_POST["keyword"]); if ($keywords == "" && !isset($_SESSION["user_id"])) { redirect_to(HOME); } elseif ($keywords == "" && isset($_SESSION["user_id"])) { redirect_to(HOME . "all-products"); } $products = Product::search($keywords); if ($products == null) { // No results found $session->message("Sorry could not find the product"); redirect_to(HOME); } } else { // Probably a GET request redirect_to(HOME); } global $categories; include $dir_public . 'search.php';
<?php // Find all the products require_once "../../includes/initialize.php"; $str = $_GET['q']; $products = Product::search($str); foreach ($products as $product) { ?> <article class="productInfo"><!-- Each individual product description --> <div><img src="../../<?php echo $product->image_path(); ?> "/></div> <p class="price"><?php echo $product->name; ?> </p> <p class="productContent"><?php $cat = Category::find_by_id($product->cat_id); echo $cat->get_name(); ?> </p> <p class="productContent"><?php $user = User::find_by_id($product->userid); echo $user->full_name(); ?> </p> </article> <?php }
<?php require_once 'config/config.conf.php'; try { $search = Product::search($_GET); //echo Utils::debug($search); $smarty = new Smarty(); $tpl_vars = array('pages' => $pages, 'current_page' => $current_page, 'search' => $search); $smarty->assign($tpl_vars); $smarty->display('search.tpl'); } catch (Exception $e) { exit($e->getMessage()); }
/** * Lists all models. */ public function actionIndex() { $this->layout = "column1"; $searchModel = new Product('search'); $dataProvider = new CActiveDataProvider('Product'); if (isset($_GET['Product'])) { $searchModel->attributes = $_GET['Product']; $dataProvider = $searchModel->search(); } $this->render('index', array('dataProvider' => $dataProvider, 'searchModel' => $searchModel)); }
$products = Product::search($input); } else { if ($_GET['itemtype'] == "traffic") { $traffics = Traffic::search($input); } else { if ($_GET['itemtype'] == "review") { $reviews = Review::search($input); } } } } } } else { $users = User::search($input); $stores = Store::search($input); $products = Product::search($input); $traffics = Traffic::search($input); $reviews = Review::search($input); } $tables = array(); if ($users != null) { $table = new Table("users", $users); array_push($tables, $table); } if ($stores != null) { $table = new Table("stores", $stores); array_push($tables, $table); } if ($products != null) { $table = new Table("products", $products); array_push($tables, $table);
public function collection_product_search() { $keywords = !empty($_GET['keywords']) ? $_GET['keywords'] : ''; $collection_id = $_GET['collection_id']; $products = Product::search(array('limit' => 10, 'offset' => 0, 'where' => 'p.title like \'%' . $keywords . '%\' or p.description like \'%' . $keywords . '%\'')); if ($products) { $output = '<ul>'; foreach ($products as $product) { $output .= '<li id="possible-product-' . $product->id . '"><form id="possible-product-' . $product->id . '-form"><input type="hidden" name="ecommerce_product_collection[collection_id]" value="' . $collection_id . '" /><input type="hidden" name="ecommerce_product_collection[product_id]" value="' . $product->id . '" /></form>'; $output .= '<a href="#" onclick="collection_product_create(' . $product->id . ');return false;">' . $product->title . '</a></li>'; } $output .= '</ul>'; } else { $output = '<p class="normal">No products matched your search.</p>'; } echo $output; }
/** * Displays a particular model's products as a long list. * @param str $slug the 'slug' identifier of the model to be displayed */ public function actionList($slug) { // Retrieve the model via it's slug $model_localization = $this->loadLocalizationModelSlug($slug); $model = $model_localization->category; if (!$model->visible) { throw new CHttpException(404, Yii::t('app', 'La page demandée n\'existe pas.')); } $this->pageTitle = $model_localization->name . " - " . Yii::app()->name; $alternatives = array(); foreach ($model->categoryLocalizations as $localization) { $alternatives[$localization->locale_id] = $this->createAbsoluteUrl("view", array("slug" => $localization->slug, "language" => $localization->locale_id)); } $this->alternatives = $alternatives; // Generate the subcategories to display in the sidebar. // Generate the subcategories to display in the sidebar. $children_cache_id = Yii::app()->request->hostInfo . " CategoryController:[children_cats_for_cat] " . $model->id; $cache_duration = 300; $menu_array = Yii::app()->cache->get($children_cache_id); if (!$menu_array) { $menu_array = array(); $children = new Category(); $children->unsetAttributes(); $children->visible = 1; $children->id = $model->id; $category_data_provider = $children->searchChildren(); foreach ($category_data_provider->getData() as $child) { if ($this->isB2b()) { // In a B2B store, we show a list of products so users can select many products at once $menu_array[] = array('label' => $child->categoryLocalization->name, 'url' => array('category/list', "slug" => $child->categoryLocalization->slug)); } else { $menu_array[] = array('label' => $child->categoryLocalization->name, 'url' => array('category/view', "slug" => $child->categoryLocalization->slug)); } } Yii::app()->cache->set($children_cache_id, $menu_array, $cache_duration); } $this->menu = $menu_array; if ($model->parent_category) { // This is a subcategory // Subcategories must display their products. They must also add their parents categories to the page's breadcrumbs // Display breadcrumbs in the right order (home >> root category >> subcategory 1 >> subcatory 2, etc.) $this->breadcrumbs = array(); function appendMotherCatToBreadcrumbs($cat, &$breadarray, $locale) { $locale_category = CategoryLocalization::model()->find("category_id = :category AND locale_id = :locale", array(":category" => $cat->id, ":locale" => $locale)); $breadarray[$locale_category->name] = array("category/view", "slug" => $locale_category->slug); if ($cat->parent_category) { appendMotherCatToBreadcrumbs($cat->parentCategory, $breadarray, $locale); } } if ($model->parent_category) { appendMotherCatToBreadcrumbs($model->parentCategory, $this->breadcrumbs, Yii::app()->language); // The array returned is reversed (top category at the end) we need to reverse it. $this->breadcrumbs = array_reverse($this->breadcrumbs); } // We're at the end of the run, just append our name $this->breadcrumbs[] = $model_localization->name; // Retrieve the order's products (with the correct localization) $products_data_provider = null; $product = new Product(); $product->unsetAttributes(); $product->visible = 1; $product->discontinued = 0; $product->categoryId = $model->id; $product->restrictScopeToCurrentLocale = false; if ($model->is_brand) { $products_data_provider = $product->searchForBrand($model); } else { $products_data_provider = $product->search(); } $products_data_provider->setPagination(array('pageSize' => 100)); $this->render('list', array('model' => $model, 'localization' => $model_localization, 'products' => $products_data_provider)); } else { throw new CHttpException(404, Yii::t('app', 'La page demandée n\'existe pas.')); } }