|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Mongi\Mongicommerce\Http\Controllers\shop; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Illuminate\Support\Facades\DB; |
|
9
|
|
|
use Mongi\Mongicommerce\Http\Controllers\Controller; |
|
10
|
|
|
use Mongi\Mongicommerce\Models\ProductItemDetail; |
|
11
|
|
|
|
|
12
|
|
|
class ShopShowVariationProductController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
public function getData(Request $r) |
|
15
|
|
|
{ |
|
16
|
|
|
$r->validate([ |
|
17
|
|
|
'product_id' => 'required' |
|
18
|
|
|
]); |
|
19
|
|
|
|
|
20
|
|
|
$informations = $r->get('informations'); |
|
21
|
|
|
$product_id = $r->get('product_id'); |
|
22
|
|
|
$flash_data = $r->get('flash_data'); |
|
23
|
|
|
session()->flash('filters', $flash_data); |
|
24
|
|
|
|
|
25
|
|
|
$g = ''; |
|
26
|
|
|
foreach ($informations as $key => $information) { |
|
27
|
|
|
$information = (object)$information; |
|
28
|
|
|
$product_detail_id = $information->product_detail_id; |
|
29
|
|
|
$product_detail_value_id = $information->product_detail_value_id; |
|
30
|
|
|
$condition = ''; |
|
31
|
|
|
|
|
32
|
|
|
if(count($informations) == $key +1){ |
|
33
|
|
|
$condition = ''; |
|
34
|
|
|
}else{ |
|
35
|
|
|
$condition = 'or'; |
|
36
|
|
|
} |
|
37
|
|
|
$g .= ('(a.product_detail_id ='.$product_detail_id.' and a.product_detail_value_id ='.$product_detail_value_id.') '.$condition.''); |
|
38
|
|
|
} |
|
39
|
|
|
$q = DB::table('product_item_details AS p')->select(DB::raw('product_item_id, count(*) as num_details'))->groupByRaw('product_item_id having num_details = ( select count(*) from product_item_details a where a.product_item_id = p.product_item_id and ('.$g.'))'); |
|
40
|
|
|
|
|
41
|
|
|
$result = $q->first(); |
|
42
|
|
|
|
|
43
|
|
|
if($result){ |
|
44
|
|
|
$filters = $result->num_details >= count($informations); |
|
45
|
|
|
if($filters){ |
|
46
|
|
|
$product_item_id = $result->product_item_id; |
|
47
|
|
|
|
|
48
|
|
|
return response()->json(route('shop.single.product',[$product_id,$product_item_id])); |
|
49
|
|
|
}else{ |
|
50
|
|
|
return response()->json(false); |
|
51
|
|
|
} |
|
52
|
|
|
}else{ |
|
53
|
|
|
return response()->json(false); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|