@@ -43,7 +43,7 @@ |
||
| 43 | 43 | 'email_verified_at' => 'datetime', |
| 44 | 44 | ]; |
| 45 | 45 | |
| 46 | - public function orders(){ |
|
| 47 | - return $this->hasMany(Order::class,'user_id'); |
|
| 46 | + public function orders() { |
|
| 47 | + return $this->hasMany(Order::class, 'user_id'); |
|
| 48 | 48 | } |
| 49 | 49 | } |
@@ -10,17 +10,17 @@ |
||
| 10 | 10 | { |
| 11 | 11 | use HasFactory; |
| 12 | 12 | |
| 13 | - public static function getStripeApiKey(){ |
|
| 13 | + public static function getStripeApiKey() { |
|
| 14 | 14 | $globalSetting = self::first(); |
| 15 | 15 | return $globalSetting->stripe_api_key; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public static function getStripeApiSecretKey(){ |
|
| 18 | + public static function getStripeApiSecretKey() { |
|
| 19 | 19 | $globalSetting = self::first(); |
| 20 | 20 | return $globalSetting->stripe_api_secret; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public static function getIban(){ |
|
| 23 | + public static function getIban() { |
|
| 24 | 24 | $globalSetting = self::first(); |
| 25 | 25 | return $globalSetting->iban; |
| 26 | 26 | } |
@@ -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(); |
@@ -7,17 +7,17 @@ |
||
| 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 | - return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart','price','image')); |
|
| 22 | - } |
|
| 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 | + return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart','price','image')); |
|
| 22 | + } |
|
| 23 | 23 | } |
@@ -7,17 +7,17 @@ |
||
| 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); |
| 20 | 20 | $image = Product::getImage($product_item_id); |
| 21 | - return view('mongicommerce.pages.single-product',compact('product','details_fields','configuration_fields','btn_cart','price','image')); |
|
| 21 | + return view('mongicommerce.pages.single-product', compact('product', 'details_fields', 'configuration_fields', 'btn_cart', 'price', 'image')); |
|
| 22 | 22 | } |
| 23 | 23 | } |
@@ -14,25 +14,25 @@ |
||
| 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 | |
@@ -51,7 +51,7 @@ 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 | $products = Category::find($id)->products; |
| 56 | 56 | } |
| 57 | 57 | return $products; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $html .= "<label>{$label}</label>"; |
| 76 | 76 | $html .= "<input disabled class='form-control' type='{$type}' value='{$value}'>"; |
| 77 | 77 | return $html; |
| 78 | - }else{ |
|
| 78 | + } else{ |
|
| 79 | 79 | $html = ''; |
| 80 | 80 | $html .= "<label>{$label}</label>"; |
| 81 | 81 | $html .= "<textarea disabled class='form-control'>{$value}</textarea>"; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | if(isset($filter[$detail->id])){ |
| 117 | 117 | if($filter[$detail->id] == $detail_value_id){ |
| 118 | 118 | $selected = 'selected'; |
| 119 | - }else{ |
|
| 119 | + } else{ |
|
| 120 | 120 | $selected = ''; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -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{ |
|
| 62 | + } else { |
|
| 63 | 63 | $products = Category::find($id)->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; |