@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | |
16 | 16 | class Template |
17 | 17 | { |
18 | - public static function getStructureCategories(){ |
|
18 | + public static function getStructureCategories() { |
|
19 | 19 | |
20 | 20 | $categories = Category::with('children')->whereNull('parent_id')->get(); |
21 | 21 | $tree = []; |
22 | - foreach($categories as $category){ |
|
22 | + foreach ($categories as $category) { |
|
23 | 23 | $tree[] = [ |
24 | 24 | 'id' => $category->id, |
25 | 25 | 'text' => $category->name, |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | return $tree; |
31 | 31 | } |
32 | 32 | |
33 | - private static function recursiveChildren($childrens){ |
|
33 | + private static function recursiveChildren($childrens) { |
|
34 | 34 | $childs = []; |
35 | - foreach ($childrens as $children){ |
|
35 | + foreach ($childrens as $children) { |
|
36 | 36 | $childs[] = [ |
37 | 37 | 'id' => $children->id, |
38 | 38 | 'text' => $children->name, |
@@ -48,51 +48,51 @@ discard block |
||
48 | 48 | * @param Int $id |
49 | 49 | * @return Product |
50 | 50 | */ |
51 | - public static function getProducts($id = null){ |
|
52 | - if($id === null){ |
|
51 | + public static function getProducts($id = null) { |
|
52 | + if ($id === null) { |
|
53 | 53 | $products = Product::all(); |
54 | - }else{ |
|
55 | - if(Category::find($id)){ |
|
54 | + } else { |
|
55 | + if (Category::find($id)) { |
|
56 | 56 | $belong_to_this_category = Category::find($id)->children->pluck('id')->toArray(); |
57 | 57 | $result = array_merge($belong_to_this_category, [0 =>$id]); |
58 | - $products = Product::whereIn('category_id',$result)->get(); |
|
59 | - }else{ |
|
58 | + $products = Product::whereIn('category_id', $result)->get(); |
|
59 | + } else { |
|
60 | 60 | $products = []; |
61 | 61 | } |
62 | 62 | } |
63 | 63 | return $products; |
64 | 64 | } |
65 | 65 | |
66 | - public static function getDetailsFields(Product $product){ |
|
66 | + public static function getDetailsFields(Product $product) { |
|
67 | 67 | $element = '<div class="row">'; |
68 | 68 | |
69 | - foreach($product->details->groupBy('product_detail_id') as $key => $details){ |
|
69 | + foreach ($product->details->groupBy('product_detail_id') as $key => $details) { |
|
70 | 70 | |
71 | - $element.= self::generateDetailHtml(Detail::find($key),$details->groupBy('product_detail_value_id'),$product->id); |
|
71 | + $element .= self::generateDetailHtml(Detail::find($key), $details->groupBy('product_detail_value_id'), $product->id); |
|
72 | 72 | } |
73 | - $element.= '<button class="btn btn-primary mt-3">Salva nel carrello</button>'; |
|
74 | - $element.= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>'; |
|
73 | + $element .= '<button class="btn btn-primary mt-3">Salva nel carrello</button>'; |
|
74 | + $element .= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>'; |
|
75 | 75 | $element .= '</div>'; |
76 | 76 | return $element; |
77 | 77 | } |
78 | 78 | |
79 | - public static function generateDetailHtml($detail,$values,$product_id){ |
|
79 | + public static function generateDetailHtml($detail, $values, $product_id) { |
|
80 | 80 | |
81 | 81 | $type = $detail->type; |
82 | 82 | $html = ''; |
83 | 83 | $filters = Session()->get('filters'); |
84 | - if($type === 'select'){ |
|
84 | + if ($type === 'select') { |
|
85 | 85 | $html = '<label>'.$detail->name.'</label>'; |
86 | - $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id .'" class="form-control mongifield_into_product">'; |
|
86 | + $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id.'" class="form-control mongifield_into_product">'; |
|
87 | 87 | $html .= '<option value="">Seleziona</option>'; |
88 | 88 | $selected = ''; |
89 | 89 | |
90 | - foreach ($values as $detail_value_id =>$value){ |
|
90 | + foreach ($values as $detail_value_id =>$value) { |
|
91 | 91 | |
92 | - if(isset($filters[$detail->id])){ |
|
93 | - if($filters[$detail->id] == $detail_value_id){ |
|
92 | + if (isset($filters[$detail->id])) { |
|
93 | + if ($filters[$detail->id] == $detail_value_id) { |
|
94 | 94 | $selected = 'selected'; |
95 | - }else{ |
|
95 | + } else { |
|
96 | 96 | $selected = ''; |
97 | 97 | } |
98 | 98 | } |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | public static function getProducts($id = null){ |
52 | 52 | if($id === null){ |
53 | 53 | $products = Product::all(); |
54 | - }else{ |
|
54 | + } else{ |
|
55 | 55 | if(Category::find($id)){ |
56 | 56 | $belong_to_this_category = Category::find($id)->children->pluck('id')->toArray(); |
57 | 57 | $result = array_merge($belong_to_this_category, [0 =>$id]); |
58 | 58 | $products = Product::whereIn('category_id',$result)->get(); |
59 | - }else{ |
|
59 | + } else{ |
|
60 | 60 | $products = []; |
61 | 61 | } |
62 | 62 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | if(isset($filters[$detail->id])){ |
93 | 93 | if($filters[$detail->id] == $detail_value_id){ |
94 | 94 | $selected = 'selected'; |
95 | - }else{ |
|
95 | + } else{ |
|
96 | 96 | $selected = ''; |
97 | 97 | } |
98 | 98 | } |