@@ -13,54 +13,54 @@ |
||
| 13 | 13 | use Mongi\Mongicommerce\Http\Controllers\shop\ShopShowVariationProductController; |
| 14 | 14 | use Mongi\Mongicommerce\Http\Controllers\shop\ShopSingleProductController; |
| 15 | 15 | |
| 16 | -Route::group(['middleware' => ['web']], function () { |
|
| 16 | +Route::group(['middleware' => ['web']], function() { |
|
| 17 | 17 | /***************** |
| 18 | 18 | *-----SHOP------* |
| 19 | 19 | *****************/ |
| 20 | 20 | |
| 21 | - Route::get('/shop/{id?}',[ShopController::class,'page'])->name('shop'); |
|
| 22 | - Route::get('/prodotto/{id}/{item_id?}',[ShopSingleProductController::class,'page'])->name('shop.single.product'); |
|
| 21 | + Route::get('/shop/{id?}', [ShopController::class, 'page'])->name('shop'); |
|
| 22 | + Route::get('/prodotto/{id}/{item_id?}', [ShopSingleProductController::class, 'page'])->name('shop.single.product'); |
|
| 23 | 23 | |
| 24 | - Route::post('/shop/get/product-information',[ShopShowVariationProductController::class,'getData'])->name('shop.get.product.information'); |
|
| 24 | + Route::post('/shop/get/product-information', [ShopShowVariationProductController::class, 'getData'])->name('shop.get.product.information'); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | /***************** |
| 28 | 28 | *------GET------* |
| 29 | 29 | *****************/ |
| 30 | - Route::get('/admin/dashboard',[DashboardController::class,'page'])->name('admin.dashboard'); |
|
| 31 | - Route::get('/admin/categorie/',[AdminCategoryController::class,'page'])->name('admin.category.new'); |
|
| 32 | - Route::get('/admin/dettagli',[AdminDetailController::class,'page'])->name('admin.details'); |
|
| 33 | - Route::get('/admin/settings',[AdminSettingsController::class,'page'])->name('admin.settings'); |
|
| 30 | + Route::get('/admin/dashboard', [DashboardController::class, 'page'])->name('admin.dashboard'); |
|
| 31 | + Route::get('/admin/categorie/', [AdminCategoryController::class, 'page'])->name('admin.category.new'); |
|
| 32 | + Route::get('/admin/dettagli', [AdminDetailController::class, 'page'])->name('admin.details'); |
|
| 33 | + Route::get('/admin/settings', [AdminSettingsController::class, 'page'])->name('admin.settings'); |
|
| 34 | 34 | //products |
| 35 | - Route::get('/admin/prodotto/crea-prodotto',[AdminNewProductController::class,'page'])->name('admin.product.new'); |
|
| 36 | - Route::get('/admin/prodotti',[AdminProductsListController::class,'page'])->name('admin.product.list'); |
|
| 37 | - Route::get('/admin/prodotto-variante/{id_product}',[AdminNewProductVariationController::class,'page'])->name('admin.product.new.variante'); |
|
| 35 | + Route::get('/admin/prodotto/crea-prodotto', [AdminNewProductController::class, 'page'])->name('admin.product.new'); |
|
| 36 | + Route::get('/admin/prodotti', [AdminProductsListController::class, 'page'])->name('admin.product.list'); |
|
| 37 | + Route::get('/admin/prodotto-variante/{id_product}', [AdminNewProductVariationController::class, 'page'])->name('admin.product.new.variante'); |
|
| 38 | 38 | //orders |
| 39 | - Route::get('/admin/ordini',[AdminOrdersController::class,'page'])->name('admin.orders.list'); |
|
| 39 | + Route::get('/admin/ordini', [AdminOrdersController::class, 'page'])->name('admin.orders.list'); |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /***************** |
| 44 | 44 | *-----POST------* |
| 45 | 45 | *****************/ |
| 46 | - Route::post('/admin/post/get/categories/tree',[AdminCategoryController::class,'getStructureCategories'])->name('admin.post.get.categories.tree'); |
|
| 47 | - Route::post('/admin/post/get/categories',[AdminCategoryController::class,'getCategories'])->name('admin.post.get.categories'); |
|
| 48 | - Route::post('/admin/post/create-new-category',[AdminCategoryController::class,'setNewCategory'])->name('admin.post.create.new.category'); |
|
| 46 | + Route::post('/admin/post/get/categories/tree', [AdminCategoryController::class, 'getStructureCategories'])->name('admin.post.get.categories.tree'); |
|
| 47 | + Route::post('/admin/post/get/categories', [AdminCategoryController::class, 'getCategories'])->name('admin.post.get.categories'); |
|
| 48 | + Route::post('/admin/post/create-new-category', [AdminCategoryController::class, 'setNewCategory'])->name('admin.post.create.new.category'); |
|
| 49 | 49 | |
| 50 | 50 | //details |
| 51 | - Route::post('/admin/post/create/detail',[AdminDetailController::class,'setNewDetail'])->name('admin.post.create.detail'); |
|
| 52 | - Route::post('/admin/post/get/details',[AdminDetailController::class,'getDetails'])->name('admin.post.get.details'); |
|
| 51 | + Route::post('/admin/post/create/detail', [AdminDetailController::class, 'setNewDetail'])->name('admin.post.create.detail'); |
|
| 52 | + Route::post('/admin/post/get/details', [AdminDetailController::class, 'getDetails'])->name('admin.post.get.details'); |
|
| 53 | 53 | |
| 54 | 54 | //configuration |
| 55 | - Route::post('/admin/post/create/configuration',[AdminConfigurationFieldController::class,'setNewConfiguration'])->name('admin.post.create.configuration'); |
|
| 56 | - Route::post('/admin/post/get/configuration',[AdminConfigurationFieldController::class,'getConfigurationFields'])->name('admin.post.get.configuration'); |
|
| 55 | + Route::post('/admin/post/create/configuration', [AdminConfigurationFieldController::class, 'setNewConfiguration'])->name('admin.post.create.configuration'); |
|
| 56 | + Route::post('/admin/post/get/configuration', [AdminConfigurationFieldController::class, 'getConfigurationFields'])->name('admin.post.get.configuration'); |
|
| 57 | 57 | |
| 58 | 58 | //product |
| 59 | - Route::post('/admin/prodotto/crea-prodotto',[AdminNewProductController::class,'createNewProduct'])->name('admin.post.product.new'); |
|
| 60 | - Route::post('/admin/prodotto/crea-variante-prodotto',[AdminNewProductVariationController::class,'createNewVariation'])->name('admin.post.product.variation.new'); |
|
| 59 | + Route::post('/admin/prodotto/crea-prodotto', [AdminNewProductController::class, 'createNewProduct'])->name('admin.post.product.new'); |
|
| 60 | + Route::post('/admin/prodotto/crea-variante-prodotto', [AdminNewProductVariationController::class, 'createNewVariation'])->name('admin.post.product.variation.new'); |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | //refresh |
| 64 | - Route::get('/admin/update',[AdminUpdatePackageController::class,'update'])->name('admin.updatepackage'); |
|
| 64 | + Route::get('/admin/update', [AdminUpdatePackageController::class, 'update'])->name('admin.updatepackage'); |
|
| 65 | 65 | |
| 66 | 66 | }); |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | class Template |
| 16 | 16 | { |
| 17 | - public static function getStructureCategories(){ |
|
| 17 | + public static function getStructureCategories() { |
|
| 18 | 18 | |
| 19 | 19 | $categories = Category::with('children')->whereNull('parent_id')->get(); |
| 20 | 20 | $tree = []; |
| 21 | - foreach($categories as $category){ |
|
| 21 | + foreach ($categories as $category) { |
|
| 22 | 22 | $tree[] = [ |
| 23 | 23 | 'id' => $category->id, |
| 24 | 24 | 'text' => $category->name, |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | return $tree; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - private static function recursiveChildren($childrens){ |
|
| 32 | + private static function recursiveChildren($childrens) { |
|
| 33 | 33 | $childs = []; |
| 34 | - foreach ($childrens as $children){ |
|
| 34 | + foreach ($childrens as $children) { |
|
| 35 | 35 | $childs[] = [ |
| 36 | 36 | 'id' => $children->id, |
| 37 | 37 | 'text' => $children->name, |
@@ -47,47 +47,47 @@ discard block |
||
| 47 | 47 | * @param Int $id |
| 48 | 48 | * @return Product |
| 49 | 49 | */ |
| 50 | - public static function getProducts($id = null){ |
|
| 51 | - if($id === null){ |
|
| 50 | + public static function getProducts($id = null) { |
|
| 51 | + if ($id === null) { |
|
| 52 | 52 | $products = Product::all(); |
| 53 | - }else{ |
|
| 54 | - if(Category::find($id)){ |
|
| 53 | + } else { |
|
| 54 | + if (Category::find($id)) { |
|
| 55 | 55 | $belong_to_this_category = Category::find($id)->children->pluck('id')->toArray(); |
| 56 | 56 | $result = array_merge($belong_to_this_category, [0 =>$id]); |
| 57 | - $products = Product::whereIn('category_id',$result)->get(); |
|
| 58 | - }else{ |
|
| 57 | + $products = Product::whereIn('category_id', $result)->get(); |
|
| 58 | + } else { |
|
| 59 | 59 | $products = []; |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | return $products; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public static function getDetailsFields(Product $product){ |
|
| 65 | + public static function getDetailsFields(Product $product) { |
|
| 66 | 66 | $element = '<div class="row">'; |
| 67 | 67 | |
| 68 | - foreach($product->details->groupBy('product_detail_id') as $key => $details){ |
|
| 69 | - $element.= self::generateDetailHtml(Detail::find($key),$details,$product->id); |
|
| 68 | + foreach ($product->details->groupBy('product_detail_id') as $key => $details) { |
|
| 69 | + $element .= self::generateDetailHtml(Detail::find($key), $details, $product->id); |
|
| 70 | 70 | } |
| 71 | - $element.= '<button class="btn btn-primary mt-3">Salva nel carrello</button>'; |
|
| 72 | - $element.= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>'; |
|
| 71 | + $element .= '<button class="btn btn-primary mt-3">Salva nel carrello</button>'; |
|
| 72 | + $element .= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>'; |
|
| 73 | 73 | $element .= '</div>'; |
| 74 | 74 | return $element; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public static function generateDetailHtml($detail,$values,$product_id){ |
|
| 77 | + public static function generateDetailHtml($detail, $values, $product_id) { |
|
| 78 | 78 | $type = $detail->type; |
| 79 | 79 | $html = ''; |
| 80 | 80 | $filters = Session()->get('filters'); |
| 81 | - if($type === 'select'){ |
|
| 81 | + if ($type === 'select') { |
|
| 82 | 82 | $html = '<label>'.$detail->name.'</label>'; |
| 83 | - $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id .'" class="form-control mongifield_into_product">'; |
|
| 83 | + $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id.'" class="form-control mongifield_into_product">'; |
|
| 84 | 84 | $html .= '<option value="">Seleziona</option>'; |
| 85 | 85 | $selected = ''; |
| 86 | - foreach ($values as $value){ |
|
| 87 | - if(isset($filters[$detail->id])){ |
|
| 88 | - if($filters[$detail->id] == $value->detail->id){ |
|
| 86 | + foreach ($values as $value) { |
|
| 87 | + if (isset($filters[$detail->id])) { |
|
| 88 | + if ($filters[$detail->id] == $value->detail->id) { |
|
| 89 | 89 | $selected = 'selected'; |
| 90 | - }else{ |
|
| 90 | + } else { |
|
| 91 | 91 | $selected = ''; |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -96,21 +96,21 @@ discard block |
||
| 96 | 96 | $html .= '</select>'; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if($type === 'checkbox'){ |
|
| 99 | + if ($type === 'checkbox') { |
|
| 100 | 100 | $html = ''; |
| 101 | - foreach($values as $value){ |
|
| 101 | + foreach ($values as $value) { |
|
| 102 | 102 | $html .= '<div class="custom-control custom-checkbox mongifield">'; |
| 103 | - $html .= '<input data-detail_id="'.$detail->id .'" type="checkbox" class="custom-control-input mongifield" id="defaultUnchecked_'.$value->id.'">'; |
|
| 103 | + $html .= '<input data-detail_id="'.$detail->id.'" type="checkbox" class="custom-control-input mongifield" id="defaultUnchecked_'.$value->id.'">'; |
|
| 104 | 104 | $html .= '<label class="custom-control-label" for="defaultUnchecked_'.$value->id.'">'.$value->value.'</label>'; |
| 105 | 105 | $html .= '</div>'; |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if($type === 'radio'){ |
|
| 109 | + if ($type === 'radio') { |
|
| 110 | 110 | $html = ''; |
| 111 | - foreach($values as $value){ |
|
| 111 | + foreach ($values as $value) { |
|
| 112 | 112 | $html .= '<div class="custom-control custom-radio mongifield">'; |
| 113 | - $html .= '<input name="radio_'.$value->detail_id.'" data-detail_id="'.$detail->id .'" type="radio" class="custom-control-input mongifield" id="defaultradio_'.$value->id.'">'; |
|
| 113 | + $html .= '<input name="radio_'.$value->detail_id.'" data-detail_id="'.$detail->id.'" type="radio" class="custom-control-input mongifield" id="defaultradio_'.$value->id.'">'; |
|
| 114 | 114 | $html .= '<label class="custom-control-label" for="defaultradio_'.$value->id.'">'.$value->value.'</label>'; |
| 115 | 115 | $html .= '</div>'; |
| 116 | 116 | } |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | public static function getProducts($id = null){ |
| 51 | 51 | if($id === null){ |
| 52 | 52 | $products = Product::all(); |
| 53 | - }else{ |
|
| 53 | + } else{ |
|
| 54 | 54 | if(Category::find($id)){ |
| 55 | 55 | $belong_to_this_category = Category::find($id)->children->pluck('id')->toArray(); |
| 56 | 56 | $result = array_merge($belong_to_this_category, [0 =>$id]); |
| 57 | 57 | $products = Product::whereIn('category_id',$result)->get(); |
| 58 | - }else{ |
|
| 58 | + } else{ |
|
| 59 | 59 | $products = []; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | if(isset($filters[$detail->id])){ |
| 88 | 88 | if($filters[$detail->id] == $value->detail->id){ |
| 89 | 89 | $selected = 'selected'; |
| 90 | - }else{ |
|
| 90 | + } else{ |
|
| 91 | 91 | $selected = ''; |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -13,13 +13,13 @@ |
||
| 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 | - $details_fields = Template::getDetailsFields($product); |
|
| 19 | - if($product_item_id != null){ |
|
| 20 | - $product = ProductItem::find($product_item_id); |
|
| 21 | - } |
|
| 16 | + public function page($id,$product_item_id = null){ |
|
| 17 | + $product = Product::find($id); |
|
| 18 | + $details_fields = Template::getDetailsFields($product); |
|
| 19 | + if($product_item_id != null){ |
|
| 20 | + $product = ProductItem::find($product_item_id); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - return view('mongicommerce.pages.single-product',compact('product','details_fields')); |
|
| 24 | - } |
|
| 23 | + return view('mongicommerce.pages.single-product',compact('product','details_fields')); |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -13,13 +13,13 @@ |
||
| 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 | 18 | $details_fields = Template::getDetailsFields($product); |
| 19 | - if($product_item_id != null){ |
|
| 19 | + if ($product_item_id != null) { |
|
| 20 | 20 | $product = ProductItem::find($product_item_id); |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - return view('mongicommerce.pages.single-product',compact('product','details_fields')); |
|
| 23 | + return view('mongicommerce.pages.single-product', compact('product', 'details_fields')); |
|
| 24 | 24 | } |
| 25 | 25 | } |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | $g = ''; |
| 26 | 26 | foreach ($informations as $key => $information) { |
| 27 | - $information = (object)$information; |
|
| 27 | + $information = (object) $information; |
|
| 28 | 28 | $product_detail_id = $information->product_detail_id; |
| 29 | 29 | $product_detail_value_id = $information->product_detail_value_id; |
| 30 | 30 | $condition = ''; |
| 31 | 31 | |
| 32 | - if(count($informations) == $key +1){ |
|
| 32 | + if (count($informations) == $key + 1) { |
|
| 33 | 33 | $condition = ''; |
| 34 | - }else{ |
|
| 34 | + } else { |
|
| 35 | 35 | $condition = 'or'; |
| 36 | 36 | } |
| 37 | 37 | $g .= ('(a.product_detail_id ='.$product_detail_id.' and a.product_detail_value_id ='.$product_detail_value_id.') '.$condition.''); |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | $result = $q->first(); |
| 42 | 42 | |
| 43 | - if($result){ |
|
| 43 | + if ($result) { |
|
| 44 | 44 | $filters = $result->num_details >= count($informations); |
| 45 | - if($filters){ |
|
| 45 | + if ($filters) { |
|
| 46 | 46 | $product_item_id = $result->product_item_id; |
| 47 | 47 | |
| 48 | - return response()->json(route('shop.single.product',[$product_id,$product_item_id])); |
|
| 49 | - }else{ |
|
| 48 | + return response()->json(route('shop.single.product', [$product_id, $product_item_id])); |
|
| 49 | + } else { |
|
| 50 | 50 | return response()->json(false); |
| 51 | 51 | } |
| 52 | - }else{ |
|
| 52 | + } else { |
|
| 53 | 53 | return response()->json(false); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | if(count($informations) == $key +1){ |
| 33 | 33 | $condition = ''; |
| 34 | - }else{ |
|
| 34 | + } else{ |
|
| 35 | 35 | $condition = 'or'; |
| 36 | 36 | } |
| 37 | 37 | $g .= ('(a.product_detail_id ='.$product_detail_id.' and a.product_detail_value_id ='.$product_detail_value_id.') '.$condition.''); |
@@ -46,10 +46,10 @@ discard block |
||
| 46 | 46 | $product_item_id = $result->product_item_id; |
| 47 | 47 | |
| 48 | 48 | return response()->json(route('shop.single.product',[$product_id,$product_item_id])); |
| 49 | - }else{ |
|
| 49 | + } else{ |
|
| 50 | 50 | return response()->json(false); |
| 51 | 51 | } |
| 52 | - }else{ |
|
| 52 | + } else{ |
|
| 53 | 53 | return response()->json(false); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -11,14 +11,14 @@ |
||
| 11 | 11 | |
| 12 | 12 | class ShopController extends Controller |
| 13 | 13 | { |
| 14 | - public function page($category_id=null){ |
|
| 14 | + public function page($category_id = null) { |
|
| 15 | 15 | $products = Template::getProducts($category_id); |
| 16 | 16 | $category = Category::find($category_id); |
| 17 | 17 | $category_name = ''; |
| 18 | 18 | $category_description = ''; |
| 19 | - if($category){ |
|
| 19 | + if ($category) { |
|
| 20 | 20 | $category_name = $category->name; |
| 21 | 21 | }; |
| 22 | - return view('mongicommerce.pages.shop',compact('products','category_name','category_description')); |
|
| 22 | + return view('mongicommerce.pages.shop', compact('products', 'category_name', 'category_description')); |
|
| 23 | 23 | } |
| 24 | 24 | } |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | |
| 10 | 10 | class AdminUpdatePackageController extends Controller |
| 11 | 11 | { |
| 12 | - public function update(){ |
|
| 12 | + public function update() { |
|
| 13 | 13 | #$dd = shell_exec('cd .. && composer update mongi/mongicommerce'); |
| 14 | 14 | $dd = shell_exec('cd .. && php artisan mongicommerce:update'); |
| 15 | 15 | echo '<pre>'; |
@@ -11,18 +11,18 @@ |
||
| 11 | 11 | { |
| 12 | 12 | use HasFactory; |
| 13 | 13 | |
| 14 | - protected $dates = ["created_at","updated_at"]; |
|
| 14 | + protected $dates = ["created_at", "updated_at"]; |
|
| 15 | 15 | |
| 16 | - public function items(){ |
|
| 16 | + public function items() { |
|
| 17 | 17 | return $this->hasMany(ProductItem::class); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function category(){ |
|
| 20 | + public function category() { |
|
| 21 | 21 | return $this->belongsTo(Category::class); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function details(){ |
|
| 25 | - return $this->hasManyThrough(ProductItemDetail::class,ProductItem::class); |
|
| 24 | + public function details() { |
|
| 25 | + return $this->hasManyThrough(ProductItemDetail::class, ProductItem::class); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |