public function search()
 {
     if (!isset($_GET['search'])) {
         $this->redirect_to('');
         break;
     }
     #$where = 'WHERE ((product_name LIKE %?%) OR (product_description LIKE %?%) OR person_name LIKE %?%)) ';
     $where = [];
     $where['sql'] = 'WHERE ((product_name LIKE ?) OR (product_description LIKE ?) OR (person_name LIKE ?)) ';
     $where['datatypes'] = 'sss';
     $where['values'] = [];
     for ($i = 0; $i < 3; $i++) {
         array_push($where['values'], '%' . $_GET['search'] . '%');
     }
     // Uncomment this, and comment out the above $where in order to turn this back to original functionality.
     /*$where = "WHERE ((product_name LIKE '%" . $_GET['search'] . "%') " .
     	 "OR (product_description LIKE '%" . $_GET['search'] . "%') " .
     	 "OR (person_name LIKE '%" . $_GET['search'] . "%')) ";*/
     $validCatagories = ['book', 'film'];
     if ($_GET['catagory'] != 'all' && in_array($_GET['catagory'], $validCatagories)) {
         $where['sql'] .= "AND product_catagory='" . $_GET['catagory'] . "' ";
     }
     $join = ['madeby' => ['fk_madeby_base_product', 'base_product_id'], 'person' => ['person_id', 'fk_madeby_person']];
     require_once '../app/models/Product.php';
     $searchResults = Product::findProducts($where, $join);
     $orderedResults = Product::groupByBaseProduct($searchResults);
     $view = new View('products/results');
     $view->set_title("Search results - '" . $_GET['search'] . "'");
     $view->pass_data('products', $orderedResults);
     $view->load_page();
 }
Example #2
0
 public function generateCartFromSession($cart)
 {
     $where = [];
     $where['sql'] = 'WHERE product_version_id IN (';
     $where['datatypes'] = '';
     $where['values'] = [];
     foreach ($cart as $productVersionId => $quantity) {
         $where['sql'] .= ' ?, ';
         $where['datatypes'] .= 'i';
         array_push($where['values'], $productVersionId);
     }
     $where['sql'] = substr($where['sql'], 0, -2) . ') ';
     $join = [];
     $join['product_version'] = ['fk_product_version_base_product', 'base_product_id'];
     require_once '../app/models/Product.php';
     $returnCart = Product::findProducts($where, $join);
     foreach ($returnCart as $key => $product) {
         $returnCart[$key]['cart_quantity'] = $cart[$product['product_version_id']]['cart_quantity'];
     }
     return $returnCart;
 }
 public function findById($wishListId)
 {
     $where = [];
     $where['sql'] = 'WHERE fk_wish_list_product_version_wish_list = ?';
     $where['datatypes'] = 'i';
     $where['values'] = [$wishListId];
     $join = [];
     $join['product_version'] = ['fk_product_version_base_product', 'base_product_id'];
     $join['wish_list_product_version'] = ['fk_wish_list_product_version_product_version', 'product_version_id'];
     $join['wish_list'] = ['fk_wish_list_product_version_wish_list', 'wish_list_id'];
     require_once '../app/models/Product.php';
     $wishList = Product::findProducts($where, $join);
     if (count($wishList) == 0) {
         $sql = 'SELECT * FROM wish_list WHERE wish_list_id = ?';
         $datatypes = 'i';
         $params = [$wishListId];
         $wishListInfo = Model::buildAndRunPreparedStatement($sql, $datatypes, $params);
         $wishListInfo = Model::createResultsArray($wishListInfo);
         $wishList['listInfo'] = $wishListInfo[0];
     }
     return $wishList;
 }