Beispiel #1
0
 /**
  * Return cached products from specified category
  *
  * @param  string
  * 
  * @return Array
  */
 public function getCachedItems($category = 'washers')
 {
     $items = \Cache::remember($category, 60, function () use($category) {
         return $this->getItems($category);
     });
     return $items;
 }
Beispiel #2
0
 public function scopeRefine($query, $filters)
 {
     foreach ($filters as $key => $value) {
         switch ($key) {
             case 'category':
                 $children = \Cache::remember('progeny_of_' . $value, 15, function () use($value) {
                     Category::progeny($value, $children, ['id']);
                     return $children;
                 });
                 $children[] = ["id" => $value * 1];
                 $query->whereIn('category_id', $children);
                 break;
             case 'conditions':
                 $query->where('condition', 'LIKE', $value);
                 break;
             case 'brands':
                 $query->where('brand', 'LIKE', $value);
                 break;
             case 'min':
             case 'max':
                 $min = array_key_exists('min', $filters) ? trim($filters['min']) != '' ? $filters['min'] : '' : '';
                 $max = array_key_exists('max', $filters) ? trim($filters['max']) != '' ? $filters['max'] : '' : '';
                 if ($min != '' && $max != '') {
                     $query->whereBetween('price', [$min, $max]);
                 } elseif ($min == '' && $max != '') {
                     $query->where('price', '<=', $max);
                 } elseif ($min != '' && $max == '') {
                     $query->where('price', '>=', $min);
                 }
                 break;
             default:
                 if ($key != 'category_name' && $key != 'search' && $key != 'page') {
                     //changing url encoded character by the real ones
                     $value = urldecode($value);
                     //applying filter to json field
                     $query->whereRaw("features LIKE '%\"" . $key . "\":%\"%" . str_replace('/', '%', $value) . "%\"%'");
                 }
                 break;
         }
     }
 }