@@ -14,56 +14,56 @@ |
||
14 | 14 | use Mongi\Mongicommerce\Http\Controllers\shop\ShopShowVariationProductController; |
15 | 15 | use Mongi\Mongicommerce\Http\Controllers\shop\ShopSingleProductController; |
16 | 16 | |
17 | -Route::group(['middleware' => ['web']], function () { |
|
17 | +Route::group(['middleware' => ['web']], function() { |
|
18 | 18 | /***************** |
19 | 19 | *-----SHOP------* |
20 | 20 | *****************/ |
21 | 21 | |
22 | - Route::get('/shop/{id?}',[ShopController::class,'page'])->name('shop'); |
|
23 | - Route::get('/prodotto/{id}/{item_id?}',[ShopSingleProductController::class,'page'])->name('shop.single.product'); |
|
22 | + Route::get('/shop/{id?}', [ShopController::class, 'page'])->name('shop'); |
|
23 | + Route::get('/prodotto/{id}/{item_id?}', [ShopSingleProductController::class, 'page'])->name('shop.single.product'); |
|
24 | 24 | |
25 | - Route::post('/shop/get/product-information',[ShopShowVariationProductController::class,'getData'])->name('shop.get.product.information'); |
|
25 | + Route::post('/shop/get/product-information', [ShopShowVariationProductController::class, 'getData'])->name('shop.get.product.information'); |
|
26 | 26 | |
27 | 27 | |
28 | 28 | /***************** |
29 | 29 | *------GET------* |
30 | 30 | *****************/ |
31 | - Route::get('/admin/dashboard',[DashboardController::class,'page'])->name('admin.dashboard'); |
|
32 | - Route::get('/admin/categorie/',[AdminCategoryController::class,'page'])->name('admin.category.new'); |
|
33 | - Route::get('/admin/dettagli',[AdminDetailController::class,'page'])->name('admin.details'); |
|
34 | - Route::get('/admin/settings',[AdminSettingsController::class,'page'])->name('admin.settings'); |
|
31 | + Route::get('/admin/dashboard', [DashboardController::class, 'page'])->name('admin.dashboard'); |
|
32 | + Route::get('/admin/categorie/', [AdminCategoryController::class, 'page'])->name('admin.category.new'); |
|
33 | + Route::get('/admin/dettagli', [AdminDetailController::class, 'page'])->name('admin.details'); |
|
34 | + Route::get('/admin/settings', [AdminSettingsController::class, 'page'])->name('admin.settings'); |
|
35 | 35 | //products |
36 | - Route::get('/admin/prodotto/crea-prodotto',[AdminNewProductController::class,'page'])->name('admin.product.new'); |
|
37 | - Route::get('/admin/prodotti',[AdminProductsListController::class,'page'])->name('admin.product.list'); |
|
38 | - Route::get('/admin/prodotto/crea-singolo-prodotto',[AdminNewSingleProductController::class,'page'])->name('admin.new.single.product'); |
|
39 | - Route::get('/admin/prodotto-variante/{id_product}',[AdminNewProductVariationController::class,'page'])->name('admin.product.new.variante'); |
|
36 | + Route::get('/admin/prodotto/crea-prodotto', [AdminNewProductController::class, 'page'])->name('admin.product.new'); |
|
37 | + Route::get('/admin/prodotti', [AdminProductsListController::class, 'page'])->name('admin.product.list'); |
|
38 | + Route::get('/admin/prodotto/crea-singolo-prodotto', [AdminNewSingleProductController::class, 'page'])->name('admin.new.single.product'); |
|
39 | + Route::get('/admin/prodotto-variante/{id_product}', [AdminNewProductVariationController::class, 'page'])->name('admin.product.new.variante'); |
|
40 | 40 | //orders |
41 | - Route::get('/admin/ordini',[AdminOrdersController::class,'page'])->name('admin.orders.list'); |
|
41 | + Route::get('/admin/ordini', [AdminOrdersController::class, 'page'])->name('admin.orders.list'); |
|
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | 45 | /***************** |
46 | 46 | *-----POST------* |
47 | 47 | *****************/ |
48 | - Route::post('/admin/post/get/categories/tree',[AdminCategoryController::class,'getStructureCategories'])->name('admin.post.get.categories.tree'); |
|
49 | - Route::post('/admin/post/get/categories',[AdminCategoryController::class,'getCategories'])->name('admin.post.get.categories'); |
|
50 | - Route::post('/admin/post/create-new-category',[AdminCategoryController::class,'setNewCategory'])->name('admin.post.create.new.category'); |
|
48 | + Route::post('/admin/post/get/categories/tree', [AdminCategoryController::class, 'getStructureCategories'])->name('admin.post.get.categories.tree'); |
|
49 | + Route::post('/admin/post/get/categories', [AdminCategoryController::class, 'getCategories'])->name('admin.post.get.categories'); |
|
50 | + Route::post('/admin/post/create-new-category', [AdminCategoryController::class, 'setNewCategory'])->name('admin.post.create.new.category'); |
|
51 | 51 | |
52 | 52 | //details |
53 | - Route::post('/admin/post/create/detail',[AdminDetailController::class,'setNewDetail'])->name('admin.post.create.detail'); |
|
54 | - Route::post('/admin/post/get/details',[AdminDetailController::class,'getDetails'])->name('admin.post.get.details'); |
|
53 | + Route::post('/admin/post/create/detail', [AdminDetailController::class, 'setNewDetail'])->name('admin.post.create.detail'); |
|
54 | + Route::post('/admin/post/get/details', [AdminDetailController::class, 'getDetails'])->name('admin.post.get.details'); |
|
55 | 55 | |
56 | 56 | //configuration |
57 | - Route::post('/admin/post/create/configuration',[AdminConfigurationFieldController::class,'setNewConfiguration'])->name('admin.post.create.configuration'); |
|
58 | - Route::post('/admin/post/get/configuration',[AdminConfigurationFieldController::class,'getConfigurationFields'])->name('admin.post.get.configuration'); |
|
57 | + Route::post('/admin/post/create/configuration', [AdminConfigurationFieldController::class, 'setNewConfiguration'])->name('admin.post.create.configuration'); |
|
58 | + Route::post('/admin/post/get/configuration', [AdminConfigurationFieldController::class, 'getConfigurationFields'])->name('admin.post.get.configuration'); |
|
59 | 59 | |
60 | 60 | //product |
61 | - Route::post('/admin/prodotto/crea-prodotto',[AdminNewProductController::class,'createNewProduct'])->name('admin.post.product.new'); |
|
62 | - Route::post('/admin/prodotto/crea-variante-prodotto',[AdminNewProductVariationController::class,'createNewVariation'])->name('admin.post.product.variation.new'); |
|
63 | - Route::post('/admin/prodotto/crea-singolo-prodotto',[AdminNewSingleProductController::class,'createNewSingleProduct'])->name('admin.post.new.single.product'); |
|
61 | + Route::post('/admin/prodotto/crea-prodotto', [AdminNewProductController::class, 'createNewProduct'])->name('admin.post.product.new'); |
|
62 | + Route::post('/admin/prodotto/crea-variante-prodotto', [AdminNewProductVariationController::class, 'createNewVariation'])->name('admin.post.product.variation.new'); |
|
63 | + Route::post('/admin/prodotto/crea-singolo-prodotto', [AdminNewSingleProductController::class, 'createNewSingleProduct'])->name('admin.post.new.single.product'); |
|
64 | 64 | |
65 | 65 | |
66 | 66 | //refresh |
67 | - Route::get('/admin/update',[AdminUpdatePackageController::class,'update'])->name('admin.updatepackage'); |
|
67 | + Route::get('/admin/update', [AdminUpdatePackageController::class, 'update'])->name('admin.updatepackage'); |
|
68 | 68 | |
69 | 69 | }); |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | |
17 | 17 | class Template |
18 | 18 | { |
19 | - public static function getStructureCategories(){ |
|
19 | + public static function getStructureCategories() { |
|
20 | 20 | |
21 | 21 | $categories = Category::with('children')->whereNull('parent_id')->get(); |
22 | 22 | $tree = []; |
23 | - foreach($categories as $category){ |
|
23 | + foreach ($categories as $category) { |
|
24 | 24 | $tree[] = [ |
25 | 25 | 'id' => $category->id, |
26 | 26 | 'text' => $category->name, |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | return $tree; |
32 | 32 | } |
33 | 33 | |
34 | - private static function recursiveChildren($childrens){ |
|
34 | + private static function recursiveChildren($childrens) { |
|
35 | 35 | $childs = []; |
36 | - foreach ($childrens as $children){ |
|
36 | + foreach ($childrens as $children) { |
|
37 | 37 | $childs[] = [ |
38 | 38 | 'id' => $children->id, |
39 | 39 | 'text' => $children->name, |
@@ -49,34 +49,34 @@ discard block |
||
49 | 49 | * @param Int $id |
50 | 50 | * @return Product |
51 | 51 | */ |
52 | - public static function getProducts($id = null){ |
|
53 | - if($id === null){ |
|
52 | + public static function getProducts($id = null) { |
|
53 | + if ($id === null) { |
|
54 | 54 | $products = Product::all(); |
55 | - }else{ |
|
55 | + } else { |
|
56 | 56 | $products = Category::find($id)->products; |
57 | 57 | } |
58 | 58 | return $products; |
59 | 59 | } |
60 | 60 | |
61 | - public static function getDetailsFields(Product $product,$product_item_id){ |
|
61 | + public static function getDetailsFields(Product $product, $product_item_id) { |
|
62 | 62 | $element = '<div class="row">'; |
63 | 63 | |
64 | - foreach($product->details->groupBy('product_detail_id') as $key => $details){ |
|
64 | + foreach ($product->details->groupBy('product_detail_id') as $key => $details) { |
|
65 | 65 | |
66 | - $element.= self::generateDetailHtml(Detail::find($key),$details->groupBy('product_detail_value_id'),$product->id,$product_item_id); |
|
66 | + $element .= self::generateDetailHtml(Detail::find($key), $details->groupBy('product_detail_value_id'), $product->id, $product_item_id); |
|
67 | 67 | } |
68 | - $element.= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>'; |
|
68 | + $element .= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>'; |
|
69 | 69 | $element .= '</div>'; |
70 | 70 | return $element; |
71 | 71 | } |
72 | 72 | |
73 | - public static function generateHtmlField($type,$value,$label){ |
|
74 | - if($type !== 'textarea'){ |
|
73 | + public static function generateHtmlField($type, $value, $label) { |
|
74 | + if ($type !== 'textarea') { |
|
75 | 75 | $html = ''; |
76 | 76 | $html .= "<label>{$label}</label>"; |
77 | 77 | $html .= "<input class='form-control' type='{$type}' value='{$value}'>"; |
78 | 78 | return $html; |
79 | - }else{ |
|
79 | + } else { |
|
80 | 80 | $html = ''; |
81 | 81 | $html .= "<label>{$label}</label>"; |
82 | 82 | $html .= "<textarea class='form-control'>{$value}</textarea>"; |
@@ -84,40 +84,40 @@ discard block |
||
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - public static function getConfigurationFields($product_item_id){ |
|
88 | - $configurationFields = ProductConfigurationField::where('product_item_id',$product_item_id)->get(); |
|
87 | + public static function getConfigurationFields($product_item_id) { |
|
88 | + $configurationFields = ProductConfigurationField::where('product_item_id', $product_item_id)->get(); |
|
89 | 89 | $element = ''; |
90 | - foreach ($configurationFields as $field){ |
|
90 | + foreach ($configurationFields as $field) { |
|
91 | 91 | $element .= '<div class="row">'; |
92 | - $element .= self::generateHtmlField($field->field->type,$field->value,$field->field->name); |
|
92 | + $element .= self::generateHtmlField($field->field->type, $field->value, $field->field->name); |
|
93 | 93 | $element .= '</div>'; |
94 | 94 | } |
95 | 95 | return $element; |
96 | 96 | } |
97 | 97 | |
98 | - public static function buttonCart($product_item_id){ |
|
98 | + public static function buttonCart($product_item_id) { |
|
99 | 99 | return "<button onclick='addToCart(this)' data-product_item_id='{$product_item_id}' class='btn btn-primary mt-3'>Salva nel carrello</button>"; |
100 | 100 | } |
101 | 101 | |
102 | - public static function generateDetailHtml($detail,$values,$product_id,$product_item_id){ |
|
102 | + public static function generateDetailHtml($detail, $values, $product_id, $product_item_id) { |
|
103 | 103 | |
104 | 104 | $type = $detail->type; |
105 | 105 | $html = ''; |
106 | - if($type === 'select'){ |
|
106 | + if ($type === 'select') { |
|
107 | 107 | $html = '<label>'.$detail->name.'</label>'; |
108 | - $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id .'" class="form-control mongifield_into_product">'; |
|
108 | + $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id.'" class="form-control mongifield_into_product">'; |
|
109 | 109 | $selected = ''; |
110 | 110 | |
111 | - $details = ProductItemDetail::where('product_item_id',$product_item_id)->get(); |
|
111 | + $details = ProductItemDetail::where('product_item_id', $product_item_id)->get(); |
|
112 | 112 | $filter = []; |
113 | - foreach ($details as $_detail){ |
|
113 | + foreach ($details as $_detail) { |
|
114 | 114 | $filter[$_detail->product_detail_id] = $_detail->product_detail_value_id; |
115 | 115 | } |
116 | - foreach ($values as $detail_value_id =>$value){ |
|
117 | - if(isset($filter[$detail->id])){ |
|
118 | - if($filter[$detail->id] == $detail_value_id){ |
|
116 | + foreach ($values as $detail_value_id =>$value) { |
|
117 | + if (isset($filter[$detail->id])) { |
|
118 | + if ($filter[$detail->id] == $detail_value_id) { |
|
119 | 119 | $selected = 'selected'; |
120 | - }else{ |
|
120 | + } else { |
|
121 | 121 | $selected = ''; |
122 | 122 | } |
123 | 123 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public static function getProducts($id = null){ |
53 | 53 | if($id === null){ |
54 | 54 | $products = Product::all(); |
55 | - }else{ |
|
55 | + } else{ |
|
56 | 56 | $products = Category::find($id)->products; |
57 | 57 | } |
58 | 58 | return $products; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $html .= "<label>{$label}</label>"; |
77 | 77 | $html .= "<input class='form-control' type='{$type}' value='{$value}'>"; |
78 | 78 | return $html; |
79 | - }else{ |
|
79 | + } else{ |
|
80 | 80 | $html = ''; |
81 | 81 | $html .= "<label>{$label}</label>"; |
82 | 82 | $html .= "<textarea class='form-control'>{$value}</textarea>"; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | if(isset($filter[$detail->id])){ |
118 | 118 | if($filter[$detail->id] == $detail_value_id){ |
119 | 119 | $selected = 'selected'; |
120 | - }else{ |
|
120 | + } else{ |
|
121 | 121 | $selected = ''; |
122 | 122 | } |
123 | 123 | } |
@@ -13,16 +13,16 @@ |
||
13 | 13 | |
14 | 14 | class ShopSingleProductController extends Controller |
15 | 15 | { |
16 | - public function page($id,$product_item_id = null){ |
|
17 | - $product = Product::find($id); |
|
18 | - if($product_item_id == null){ |
|
19 | - return redirect()->route('shop.single.product',[$product->id,$product->items->first()->id]); |
|
20 | - } |
|
21 | - $details_fields = Template::getDetailsFields($product,$product_item_id); |
|
22 | - $configuration_fields = Template::getConfigurationFields($product_item_id); |
|
23 | - $btn_cart = Template::buttonCart($product_item_id); |
|
24 | - |
|
25 | - |
|
26 | - return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart')); |
|
27 | - } |
|
16 | + public function page($id,$product_item_id = null){ |
|
17 | + $product = Product::find($id); |
|
18 | + if($product_item_id == null){ |
|
19 | + return redirect()->route('shop.single.product',[$product->id,$product->items->first()->id]); |
|
20 | + } |
|
21 | + $details_fields = Template::getDetailsFields($product,$product_item_id); |
|
22 | + $configuration_fields = Template::getConfigurationFields($product_item_id); |
|
23 | + $btn_cart = Template::buttonCart($product_item_id); |
|
24 | + |
|
25 | + |
|
26 | + return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart')); |
|
27 | + } |
|
28 | 28 | } |
@@ -13,16 +13,16 @@ |
||
13 | 13 | |
14 | 14 | class ShopSingleProductController extends Controller |
15 | 15 | { |
16 | - public function page($id,$product_item_id = null){ |
|
16 | + public function page($id, $product_item_id = null) { |
|
17 | 17 | $product = Product::find($id); |
18 | - if($product_item_id == null){ |
|
19 | - return redirect()->route('shop.single.product',[$product->id,$product->items->first()->id]); |
|
18 | + if ($product_item_id == null) { |
|
19 | + return redirect()->route('shop.single.product', [$product->id, $product->items->first()->id]); |
|
20 | 20 | } |
21 | - $details_fields = Template::getDetailsFields($product,$product_item_id); |
|
21 | + $details_fields = Template::getDetailsFields($product, $product_item_id); |
|
22 | 22 | $configuration_fields = Template::getConfigurationFields($product_item_id); |
23 | 23 | $btn_cart = Template::buttonCart($product_item_id); |
24 | 24 | |
25 | 25 | |
26 | - return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart')); |
|
26 | + return view('mongicommerce.pages.single-product', compact('product', 'details_fields', 'configuration_fields', 'btn_cart')); |
|
27 | 27 | } |
28 | 28 | } |
@@ -14,12 +14,12 @@ discard block |
||
14 | 14 | |
15 | 15 | class AdminNewSingleProductController extends Controller |
16 | 16 | { |
17 | - public function page(){ |
|
17 | + public function page() { |
|
18 | 18 | $caregories = Category::all(); |
19 | - return view('mongicommerce::admin.pages.products.new_single_product',['categories' => $caregories]); |
|
19 | + return view('mongicommerce::admin.pages.products.new_single_product', ['categories' => $caregories]); |
|
20 | 20 | } |
21 | 21 | |
22 | - public function createNewSingleProduct(Request $r){ |
|
22 | + public function createNewSingleProduct(Request $r) { |
|
23 | 23 | $r->validate([ |
24 | 24 | 'category_id' => 'required', |
25 | 25 | 'quantity' => 'required', |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | 'image' => 'required', |
28 | 28 | ]); |
29 | 29 | |
30 | - $configuration_fields = json_decode($r->get('configuration_fields'),true); |
|
30 | + $configuration_fields = json_decode($r->get('configuration_fields'), true); |
|
31 | 31 | $quantity = $r->get('quantity'); |
32 | 32 | $price = $r->get('price'); |
33 | 33 | $product_name = $r->get('product_name'); |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | $product->image = null; |
44 | 44 | $product->save(); |
45 | 45 | |
46 | - $base64_str = substr($get_image, strpos($get_image, ",")+1); |
|
46 | + $base64_str = substr($get_image, strpos($get_image, ",") + 1); |
|
47 | 47 | $image = base64_decode($base64_str); |
48 | 48 | $destinationPath = public_path().'/uploads/products_img/'.$product->id.'/'.$product->id.'/'; |
49 | 49 | $destinationPathDB = url('/').'/uploads/products_img/'.$product->id.'/'.$product->id.'/'; |
50 | 50 | |
51 | - if(!File::isDirectory($destinationPath)){ |
|
51 | + if (!File::isDirectory($destinationPath)) { |
|
52 | 52 | File::makeDirectory($destinationPath, $mode = 0777, true, true); |
53 | 53 | } |
54 | 54 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $product_item->quantity = $quantity; |
71 | 71 | $product_item->save(); |
72 | 72 | |
73 | - foreach ($configuration_fields as $conf_field){ |
|
73 | + foreach ($configuration_fields as $conf_field) { |
|
74 | 74 | $conf_fields_obj = (object) $conf_field; |
75 | 75 | $configuration_field = new ProductConfigurationField(); |
76 | 76 | $configuration_field->product_item_id = $product_item->id; |
@@ -11,8 +11,8 @@ |
||
11 | 11 | { |
12 | 12 | use HasFactory; |
13 | 13 | |
14 | - public function field(){ |
|
15 | - return $this->belongsTo(ConfigurationField::class,'config_field_id'); |
|
14 | + public function field() { |
|
15 | + return $this->belongsTo(ConfigurationField::class, 'config_field_id'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | } |
@@ -11,19 +11,19 @@ |
||
11 | 11 | { |
12 | 12 | use HasFactory; |
13 | 13 | |
14 | - public function details(){ |
|
15 | - return $this->hasMany(ProductItemDetail::class,'product_item_id'); |
|
14 | + public function details() { |
|
15 | + return $this->hasMany(ProductItemDetail::class, 'product_item_id'); |
|
16 | 16 | } |
17 | 17 | |
18 | - public function configurationFields(){ |
|
19 | - return $this->hasMany(ProductConfigurationField::class,'product_item_id'); |
|
18 | + public function configurationFields() { |
|
19 | + return $this->hasMany(ProductConfigurationField::class, 'product_item_id'); |
|
20 | 20 | } |
21 | 21 | |
22 | - public function product(){ |
|
22 | + public function product() { |
|
23 | 23 | return $this->belongsTo(Product::class); |
24 | 24 | } |
25 | 25 | |
26 | - public function category(){ |
|
26 | + public function category() { |
|
27 | 27 | return $this->belongsTo(Category::class); |
28 | 28 | } |
29 | 29 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | public function up() |
15 | 15 | { |
16 | - Schema::create('product_items', function (Blueprint $table) { |
|
16 | + Schema::create('product_items', function(Blueprint $table) { |
|
17 | 17 | $table->id(); |
18 | 18 | $table->unsignedBigInteger('product_id')->nullable(); |
19 | 19 | $table->unsignedBigInteger('category_id')->nullable(); |