public function buildProductsQuery()
 {
     $this->qry = Product::leftJoin('users', 'users.id', '=', 'product.product_user_id')->where('product_status', '!=', 'Deleted');
     //form the search query
     if (is_numeric($this->getSearchValue('search_product_id_from')) && $this->getSearchValue('search_product_id_from') > 0) {
         $this->qry->where('product.id', '>=', $this->getSearchValue('search_product_id_from'));
     }
     if (is_numeric($this->getSearchValue('search_product_id_to')) && $this->getSearchValue('search_product_id_to') > 0) {
         $this->qry->where('product.id', '<=', $this->getSearchValue('search_product_id_to'));
     }
     # Status
     if ($this->getSearchValue('search_product_status') != '') {
         $this->qry->where('product.product_status', '=', $this->getSearchValue('search_product_status'));
     }
     # Featured Status
     if ($this->getSearchValue('search_featured_product') != '') {
         $this->qry->where('product.is_featured_product', '=', $this->getSearchValue('search_featured_product'));
     }
     # Product title
     if ($this->getSearchValue('search_product_name') != '') {
         $this->qry->whereRaw("product.product_name LIKE '%" . addslashes($this->getSearchValue('search_product_name')) . "%'");
     }
     # Author
     if ($this->getSearchValue('search_product_author') != '') {
         $name_arr = explode(" ", $this->getSearchValue('search_product_author'));
         if (count($name_arr) > 0) {
             foreach ($name_arr as $names) {
                 $this->qry->whereRaw("( users.first_name LIKE '%" . addslashes($names) . "%' OR users.last_name LIKE '%" . addslashes($names) . "%' )");
             }
         }
         /*$name_arr = explode(" ",$this->getSrchVal('user_name'));
         		if(count($name_arr) > 0)
         		{
         			foreach($name_arr AS $names)
         			{
         				$this->qry->whereRaw("( users.first_name LIKE '%".addslashes($names)."%' OR users.last_name LIKE '%".addslashes($names)."%'  )");
         			}
         		}*/
     }
     # Category
     if ($this->getSearchValue('search_product_category') > 0) {
         $cat_id_arr = $this->getSubCategoryIds($this->getSearchValue('search_product_category'));
         $this->qry->whereIn('product.product_category_id', $cat_id_arr);
     }
     $this->qry->select('product.id', 'product_category_id', 'product_status', 'product_code', 'product_price_currency', 'product_name', 'product_sold', 'product_user_id', 'product_price', 'product_discount_price', 'product_discount_fromdate', 'product_discount_todate', 'is_free_product', 'is_featured_product', 'product_preview_type', 'product.url_slug');
     return $this->qry;
 }
Example #2
0
    return "OK!";
});
Route::get('test_add_best', function () {
    BestSelling::increase(6);
});
//Untuk kepentingan debugging. bisa dihapus kemudian hari
Route::get('hapuscart', function () {
    Session::forget('shopping_cart');
    Session::forget('shopping_cart["item"]');
    Session::forget('shopping_cart["totalprice"]');
});
Route::get('test_locations', function () {
    $q = "vaio";
    $category = 6;
    $location = "Nangroe Aceh Darussalam";
    $products = Product::leftJoin('brands', function ($j) {
        $j->on('products.brand_id', '=', 'brands.id');
    })->leftJoin('users', function ($j) {
        $j->on('products.seller_id', '=', 'users.id');
    })->leftJoin('locations', function ($j) {
        $j->on('users.location_id', '=', 'locations.id');
    })->select('products.*')->where('products.name', 'like', '%' . $q . '%')->orWhere('brands.name', 'like', '%' . $q . '%');
    $products->where('category_id', '=', $category);
    $products->where('locations.province', '=', $location);
    foreach ($products->get() as $product) {
        echo $product->name . " " . $product->location;
    }
});
Route::get('courier_test', function () {
    return Courier::all()->first()->company_name;
});