@@ -14,21 +14,21 @@ |
||
14 | 14 | { |
15 | 15 | use HasFactory; |
16 | 16 | |
17 | - protected $dates = ["created_at","updated_at"]; |
|
17 | + protected $dates = ["created_at", "updated_at"]; |
|
18 | 18 | |
19 | - public function status(){ |
|
20 | - return $this->belongsTo(OrderStatus::class,'status_id'); |
|
19 | + public function status() { |
|
20 | + return $this->belongsTo(OrderStatus::class, 'status_id'); |
|
21 | 21 | } |
22 | 22 | |
23 | - public function typePayment(){ |
|
24 | - return $this->belongsTo(TypePayment::class,'payment_type_id'); |
|
23 | + public function typePayment() { |
|
24 | + return $this->belongsTo(TypePayment::class, 'payment_type_id'); |
|
25 | 25 | } |
26 | 26 | |
27 | - public function user(){ |
|
28 | - return $this->belongsTo(User::class,'user_id'); |
|
27 | + public function user() { |
|
28 | + return $this->belongsTo(User::class, 'user_id'); |
|
29 | 29 | } |
30 | 30 | |
31 | - public function products(){ |
|
32 | - return $this->belongsToMany(ProductItem::class,'product_order','order_id','product_item_id')->withPivot('number_products'); |
|
31 | + public function products() { |
|
32 | + return $this->belongsToMany(ProductItem::class, 'product_order', 'order_id', 'product_item_id')->withPivot('number_products'); |
|
33 | 33 | } |
34 | 34 | } |
@@ -12,15 +12,15 @@ |
||
12 | 12 | { |
13 | 13 | use HasFactory; |
14 | 14 | protected $table = 'cart'; |
15 | - protected $dates = ["created_at","updated_at"]; |
|
15 | + protected $dates = ["created_at", "updated_at"]; |
|
16 | 16 | |
17 | 17 | |
18 | - public function user(){ |
|
19 | - return $this->belongsTo(User::class,'user_id'); |
|
18 | + public function user() { |
|
19 | + return $this->belongsTo(User::class, 'user_id'); |
|
20 | 20 | } |
21 | 21 | |
22 | - static function emptyCart(){ |
|
23 | - self::where('user_id',Auth::user()->id)->delete(); |
|
22 | + static function emptyCart() { |
|
23 | + self::where('user_id', Auth::user()->id)->delete(); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | public function up() |
15 | 15 | { |
16 | - Schema::create('product_order', function (Blueprint $table) { |
|
16 | + Schema::create('product_order', function(Blueprint $table) { |
|
17 | 17 | $table->id(); |
18 | 18 | $table->unsignedBigInteger('order_id'); |
19 | 19 | $table->unsignedBigInteger('product_item_id'); |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | public function up() |
15 | 15 | { |
16 | - Schema::table('users', function (Blueprint $table) { |
|
16 | + Schema::table('users', function(Blueprint $table) { |
|
17 | 17 | $table->string('name')->nullable()->change(); |
18 | 18 | $table->string('first_name')->nullable(); |
19 | 19 | $table->string('last_name')->nullable(); |
@@ -14,33 +14,33 @@ |
||
14 | 14 | { |
15 | 15 | use HasFactory; |
16 | 16 | |
17 | - protected $dates = ["created_at","updated_at"]; |
|
17 | + protected $dates = ["created_at", "updated_at"]; |
|
18 | 18 | |
19 | - public function items(){ |
|
19 | + public function items() { |
|
20 | 20 | return $this->hasMany(ProductItem::class); |
21 | 21 | } |
22 | 22 | |
23 | - public function category(){ |
|
23 | + public function category() { |
|
24 | 24 | return $this->belongsTo(Category::class); |
25 | 25 | } |
26 | 26 | |
27 | - public function details(){ |
|
28 | - return $this->hasManyThrough(ProductItemDetail::class,ProductItem::class); |
|
27 | + public function details() { |
|
28 | + return $this->hasManyThrough(ProductItemDetail::class, ProductItem::class); |
|
29 | 29 | } |
30 | 30 | |
31 | - public static function getPrice($product_item_id){ |
|
31 | + public static function getPrice($product_item_id) { |
|
32 | 32 | return ProductItem::find($product_item_id)->price; |
33 | 33 | } |
34 | 34 | |
35 | - public static function getImage($product_item_id){ |
|
35 | + public static function getImage($product_item_id) { |
|
36 | 36 | return ProductItem::find($product_item_id)->image; |
37 | 37 | } |
38 | 38 | |
39 | - public static function getDescription($product_item_id){ |
|
39 | + public static function getDescription($product_item_id) { |
|
40 | 40 | return ProductItem::find($product_item_id)->description; |
41 | 41 | } |
42 | 42 | |
43 | - public static function getName($product_item_id){ |
|
43 | + public static function getName($product_item_id) { |
|
44 | 44 | return ProductItem::find($product_item_id)->name; |
45 | 45 | } |
46 | 46 |
@@ -7,20 +7,20 @@ |
||
7 | 7 | |
8 | 8 | class ShopSingleProductController extends Controller |
9 | 9 | { |
10 | - public function page($id,$product_item_id = null){ |
|
11 | - $product = Product::find($id); |
|
12 | - if($product_item_id == null){ |
|
13 | - return redirect()->route('shop.single.product',[$product->id,$product->items->first()->id]); |
|
14 | - } |
|
10 | + public function page($id,$product_item_id = null){ |
|
11 | + $product = Product::find($id); |
|
12 | + if($product_item_id == null){ |
|
13 | + return redirect()->route('shop.single.product',[$product->id,$product->items->first()->id]); |
|
14 | + } |
|
15 | 15 | |
16 | - $details_fields = Template::getDetailsFields($product,$product_item_id); |
|
17 | - $configuration_fields = Template::getConfigurationFields($product_item_id); |
|
18 | - $btn_cart = Template::buttonCart($product_item_id); |
|
19 | - $price = Product::getPrice($product_item_id); |
|
20 | - $image = Product::getImage($product_item_id); |
|
21 | - $description = Product::getDescription($product_item_id); |
|
22 | - $name = Product::getName($product_item_id); |
|
16 | + $details_fields = Template::getDetailsFields($product,$product_item_id); |
|
17 | + $configuration_fields = Template::getConfigurationFields($product_item_id); |
|
18 | + $btn_cart = Template::buttonCart($product_item_id); |
|
19 | + $price = Product::getPrice($product_item_id); |
|
20 | + $image = Product::getImage($product_item_id); |
|
21 | + $description = Product::getDescription($product_item_id); |
|
22 | + $name = Product::getName($product_item_id); |
|
23 | 23 | |
24 | - return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart','price','image','description','name')); |
|
25 | - } |
|
24 | + return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart','price','image','description','name')); |
|
25 | + } |
|
26 | 26 | } |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | |
8 | 8 | class ShopSingleProductController extends Controller |
9 | 9 | { |
10 | - public function page($id,$product_item_id = null){ |
|
10 | + public function page($id, $product_item_id = null) { |
|
11 | 11 | $product = Product::find($id); |
12 | - if($product_item_id == null){ |
|
13 | - return redirect()->route('shop.single.product',[$product->id,$product->items->first()->id]); |
|
12 | + if ($product_item_id == null) { |
|
13 | + return redirect()->route('shop.single.product', [$product->id, $product->items->first()->id]); |
|
14 | 14 | } |
15 | 15 | |
16 | - $details_fields = Template::getDetailsFields($product,$product_item_id); |
|
16 | + $details_fields = Template::getDetailsFields($product, $product_item_id); |
|
17 | 17 | $configuration_fields = Template::getConfigurationFields($product_item_id); |
18 | 18 | $btn_cart = Template::buttonCart($product_item_id); |
19 | 19 | $price = Product::getPrice($product_item_id); |
@@ -21,6 +21,6 @@ discard block |
||
21 | 21 | $description = Product::getDescription($product_item_id); |
22 | 22 | $name = Product::getName($product_item_id); |
23 | 23 | |
24 | - return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart','price','image','description','name')); |
|
24 | + return view('mongicommerce.pages.single-product', compact('product', 'details_fields', 'configuration_fields', 'btn_cart', 'price', 'image', 'description', 'name')); |
|
25 | 25 | } |
26 | 26 | } |
@@ -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, |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | public static function getCategoryTree($parent_id = null, $spacing = '', $tree_array = array()) { |
47 | - $categories = Category::select('id', 'name', 'parent_id')->where('parent_id' ,'=', $parent_id)->orderBy('parent_id')->get(); |
|
48 | - foreach ($categories as $item){ |
|
49 | - $tree_array[] = ['id' => $item->id, 'name' =>$spacing . $item->name] ; |
|
50 | - $tree_array = self::getCategoryTree($item->id, $spacing . '- ', $tree_array); |
|
47 | + $categories = Category::select('id', 'name', 'parent_id')->where('parent_id', '=', $parent_id)->orderBy('parent_id')->get(); |
|
48 | + foreach ($categories as $item) { |
|
49 | + $tree_array[] = ['id' => $item->id, 'name' =>$spacing.$item->name]; |
|
50 | + $tree_array = self::getCategoryTree($item->id, $spacing.'- ', $tree_array); |
|
51 | 51 | } |
52 | 52 | return $tree_array; |
53 | 53 | } |
@@ -56,34 +56,34 @@ discard block |
||
56 | 56 | * @param Int $id |
57 | 57 | * @return Product |
58 | 58 | */ |
59 | - public static function getProducts($id = null){ |
|
60 | - if($id === null){ |
|
59 | + public static function getProducts($id = null) { |
|
60 | + if ($id === null) { |
|
61 | 61 | $products = Product::all(); |
62 | - }else{ |
|
63 | - $products = Category::where('id',$id)->orWhere('parent_id',$id)->first()->products; |
|
62 | + } else { |
|
63 | + $products = Category::where('id', $id)->orWhere('parent_id', $id)->first()->products; |
|
64 | 64 | } |
65 | 65 | return $products; |
66 | 66 | } |
67 | 67 | |
68 | - public static function getDetailsFields(Product $product,$product_item_id){ |
|
68 | + public static function getDetailsFields(Product $product, $product_item_id) { |
|
69 | 69 | $element = '<div class="row col">'; |
70 | 70 | |
71 | - foreach($product->details->groupBy('product_detail_id') as $key => $details){ |
|
71 | + foreach ($product->details->groupBy('product_detail_id') as $key => $details) { |
|
72 | 72 | |
73 | - $element.= self::generateDetailHtml(Detail::find($key),$details->groupBy('product_detail_value_id'),$product->id,$product_item_id); |
|
73 | + $element .= self::generateDetailHtml(Detail::find($key), $details->groupBy('product_detail_value_id'), $product->id, $product_item_id); |
|
74 | 74 | } |
75 | - $element.= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>'; |
|
75 | + $element .= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>'; |
|
76 | 76 | $element .= '</div>'; |
77 | 77 | return $element; |
78 | 78 | } |
79 | 79 | |
80 | - public static function generateHtmlField($type,$value,$label){ |
|
81 | - if($type !== 'textarea'){ |
|
80 | + public static function generateHtmlField($type, $value, $label) { |
|
81 | + if ($type !== 'textarea') { |
|
82 | 82 | $html = ''; |
83 | 83 | $html .= "<label>{$label}</label>"; |
84 | 84 | $html .= "<input disabled class='form-control' type='{$type}' value='{$value}'>"; |
85 | 85 | return $html; |
86 | - }else{ |
|
86 | + } else { |
|
87 | 87 | $html = ''; |
88 | 88 | $html .= "<label>{$label}</label>"; |
89 | 89 | $html .= "<textarea disabled class='form-control'>{$value}</textarea>"; |
@@ -91,40 +91,40 @@ discard block |
||
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - public static function getConfigurationFields($product_item_id){ |
|
95 | - $configurationFields = ProductConfigurationField::where('product_item_id',$product_item_id)->get(); |
|
94 | + public static function getConfigurationFields($product_item_id) { |
|
95 | + $configurationFields = ProductConfigurationField::where('product_item_id', $product_item_id)->get(); |
|
96 | 96 | $element = '<div class="col row">'; |
97 | - foreach ($configurationFields as $field){ |
|
98 | - $element .= self::generateHtmlField($field->field->type,$field->value,$field->field->name); |
|
97 | + foreach ($configurationFields as $field) { |
|
98 | + $element .= self::generateHtmlField($field->field->type, $field->value, $field->field->name); |
|
99 | 99 | |
100 | 100 | } |
101 | 101 | $element .= '</div>'; |
102 | 102 | return $element; |
103 | 103 | } |
104 | 104 | |
105 | - public static function buttonCart($product_item_id){ |
|
105 | + public static function buttonCart($product_item_id) { |
|
106 | 106 | return "<button onclick='addToCart(this)' data-product_item_id='{$product_item_id}' class='btn btn-primary mt-3'>Salva nel carrello</button>"; |
107 | 107 | } |
108 | 108 | |
109 | - public static function generateDetailHtml($detail,$values,$product_id,$product_item_id){ |
|
109 | + public static function generateDetailHtml($detail, $values, $product_id, $product_item_id) { |
|
110 | 110 | |
111 | 111 | $type = $detail->type; |
112 | 112 | $html = ''; |
113 | - if($type === 'select'){ |
|
113 | + if ($type === 'select') { |
|
114 | 114 | $html = '<label>'.$detail->name.'</label>'; |
115 | - $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id .'" class="form-control mongifield_into_product">'; |
|
115 | + $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id.'" class="form-control mongifield_into_product">'; |
|
116 | 116 | $selected = ''; |
117 | 117 | |
118 | - $details = ProductItemDetail::where('product_item_id',$product_item_id)->get(); |
|
118 | + $details = ProductItemDetail::where('product_item_id', $product_item_id)->get(); |
|
119 | 119 | $filter = []; |
120 | - foreach ($details as $_detail){ |
|
120 | + foreach ($details as $_detail) { |
|
121 | 121 | $filter[$_detail->product_detail_id] = $_detail->product_detail_value_id; |
122 | 122 | } |
123 | - foreach ($values as $detail_value_id =>$value){ |
|
124 | - if(isset($filter[$detail->id])){ |
|
125 | - if($filter[$detail->id] == $detail_value_id){ |
|
123 | + foreach ($values as $detail_value_id =>$value) { |
|
124 | + if (isset($filter[$detail->id])) { |
|
125 | + if ($filter[$detail->id] == $detail_value_id) { |
|
126 | 126 | $selected = 'selected'; |
127 | - }else{ |
|
127 | + } else { |
|
128 | 128 | $selected = ''; |
129 | 129 | } |
130 | 130 | } |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | return $html; |
138 | 138 | } |
139 | 139 | |
140 | - public static function MoveSessionToCart($user_id){ |
|
140 | + public static function MoveSessionToCart($user_id) { |
|
141 | 141 | $user = User::find($user_id); |
142 | 142 | $elements_in_cart = session('cart'); |
143 | - if(!empty($elements_in_cart)){ |
|
144 | - if(Cart::where('user_id',$user->id)->count() <= 0){ |
|
145 | - foreach($elements_in_cart as $product_id => $count){ |
|
143 | + if (!empty($elements_in_cart)) { |
|
144 | + if (Cart::where('user_id', $user->id)->count() <= 0) { |
|
145 | + foreach ($elements_in_cart as $product_id => $count) { |
|
146 | 146 | $cart = new Cart(); |
147 | 147 | $cart->user_id = $user->id; |
148 | 148 | $cart->product_item_id = $product_id; |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | public static function getProducts($id = null){ |
60 | 60 | if($id === null){ |
61 | 61 | $products = Product::all(); |
62 | - }else{ |
|
62 | + } else{ |
|
63 | 63 | $products = Category::where('id',$id)->orWhere('parent_id',$id)->first()->products; |
64 | 64 | } |
65 | 65 | return $products; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $html .= "<label>{$label}</label>"; |
84 | 84 | $html .= "<input disabled class='form-control' type='{$type}' value='{$value}'>"; |
85 | 85 | return $html; |
86 | - }else{ |
|
86 | + } else{ |
|
87 | 87 | $html = ''; |
88 | 88 | $html .= "<label>{$label}</label>"; |
89 | 89 | $html .= "<textarea disabled class='form-control'>{$value}</textarea>"; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | if(isset($filter[$detail->id])){ |
125 | 125 | if($filter[$detail->id] == $detail_value_id){ |
126 | 126 | $selected = 'selected'; |
127 | - }else{ |
|
127 | + } else{ |
|
128 | 128 | $selected = ''; |
129 | 129 | } |
130 | 130 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | public function boot(Router $router, Kernel $kernel) |
25 | 25 | { |
26 | 26 | |
27 | - Blade::directive('money', function ($amount) { |
|
27 | + Blade::directive('money', function($amount) { |
|
28 | 28 | #return $fmt->formatCurrency($amount,"EUR"); |
29 | 29 | /*return "<?= $fmt->formatCurrency($amount,'EUR'); ?>";*/ |
30 | 30 | return "<?= abs($amount) > 1000 ? '€ ' .number_format($amount, 0, ',', '.') : '€ ' . number_format($amount, 2, ',', '.') ?>"; |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | * Optional methods to load your package assets |
34 | 34 | */ |
35 | 35 | // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'mongicommerce'); |
36 | - $this->loadViewsFrom(__DIR__ . '/../resources/views', 'mongicommerce'); |
|
37 | - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
|
38 | - $this->loadRoutesFrom(__DIR__ . '/routes.php'); |
|
36 | + $this->loadViewsFrom(__DIR__.'/../resources/views', 'mongicommerce'); |
|
37 | + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
|
38 | + $this->loadRoutesFrom(__DIR__.'/routes.php'); |
|
39 | 39 | |
40 | 40 | if (Schema::hasTable('admin_settings')) { |
41 | 41 | //inject global information into views |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | #$router->middleware(AdminMiddleware::class); |
51 | - $router->aliasMiddleware('admin',AdminMiddleware::class); |
|
51 | + $router->aliasMiddleware('admin', AdminMiddleware::class); |
|
52 | 52 | |
53 | 53 | |
54 | 54 | if ($this->app->runningInConsole()) { |
@@ -56,19 +56,19 @@ discard block |
||
56 | 56 | |
57 | 57 | // Publishing the config file. |
58 | 58 | $this->publishes([ |
59 | - __DIR__ . '/../config/config.php' => config_path('mongicommerce.php'), |
|
59 | + __DIR__.'/../config/config.php' => config_path('mongicommerce.php'), |
|
60 | 60 | ], 'config'); |
61 | 61 | |
62 | 62 | |
63 | 63 | // Publishing the views. |
64 | 64 | $this->publishes([ |
65 | - __DIR__ . '/../resources/views/shop' => resource_path('/views/mongicommerce'), |
|
65 | + __DIR__.'/../resources/views/shop' => resource_path('/views/mongicommerce'), |
|
66 | 66 | ], 'views'); |
67 | 67 | |
68 | 68 | |
69 | 69 | // Publishing assets. |
70 | 70 | $this->publishes([ |
71 | - __DIR__ . '/../resources/assets' => public_path('/mongicommerce/template'), |
|
71 | + __DIR__.'/../resources/assets' => public_path('/mongicommerce/template'), |
|
72 | 72 | ], 'assets'); |
73 | 73 | |
74 | 74 | // Registering package commands. |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | public function register() |
91 | 91 | { |
92 | 92 | // Automatically apply the package configuration |
93 | - $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'mongicommerce'); |
|
93 | + $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'mongicommerce'); |
|
94 | 94 | |
95 | 95 | // Register the main class to use with the facade |
96 | - $this->app->singleton('mongicommerce', function () { |
|
96 | + $this->app->singleton('mongicommerce', function() { |
|
97 | 97 | return new Mongicommerce; |
98 | 98 | }); |
99 | 99 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | use Mongi\Mongicommerce\Http\Controllers\admin\AdminNewProductVariationController; |
30 | 30 | use Mongi\Mongicommerce\Http\Middleware\AdminMiddleware; |
31 | 31 | |
32 | -Route::group(['middleware' => ['web']], function () { |
|
32 | +Route::group(['middleware' => ['web']], function() { |
|
33 | 33 | /***************** |
34 | 34 | *-----SHOP------* |
35 | 35 | *****************/ |