diff --git a/app/Http/Controllers/Admin/MakerWorldController.php b/app/Http/Controllers/Admin/MakerWorldController.php index b004ebe..a523221 100644 --- a/app/Http/Controllers/Admin/MakerWorldController.php +++ b/app/Http/Controllers/Admin/MakerWorldController.php @@ -66,8 +66,21 @@ class MakerWorldController extends Controller */ public function staging(Request $request): View { - $query = Product::with(['category', 'makerworldCollection']) - ->where('status', 'draft'); + $tab = $request->query('tab', 'draft'); + + $query = Product::with(['category', 'makerworldCollection']); + + if ($tab === 'draft') { + $query->where('status', 'draft'); + } elseif ($tab === 'published') { + $query->whereNotNull('makerworld_id') + ->where(function ($q) { + $q->where('status', 'published') + ->orWhereNull('status'); + }); + } elseif ($tab === 'all') { + $query->whereNotNull('makerworld_id'); + } if ($request->filled('collection_id')) { $query->where('makerworld_collection_id', $request->input('collection_id')); @@ -85,9 +98,26 @@ class MakerWorldController extends Controller $stagedProducts = $query->latest()->paginate(24)->withQueryString(); $categories = Category::orderBy('name')->get(); $collections = MakerWorldCollection::all(); - $totalStaged = Product::where('status', 'draft')->count(); - return view('admin.makerworld.staging', compact('stagedProducts', 'categories', 'collections', 'totalStaged')); + $countDraft = Product::where('status', 'draft')->count(); + $countPublished = Product::whereNotNull('makerworld_id') + ->where(function ($q) { + $q->where('status', 'published') + ->orWhereNull('status'); + })->count(); + $countAll = Product::whereNotNull('makerworld_id')->count(); + $totalStaged = $countDraft; + + return view('admin.makerworld.staging', compact( + 'stagedProducts', + 'categories', + 'collections', + 'tab', + 'countDraft', + 'countPublished', + 'countAll', + 'totalStaged' + )); } /** @@ -138,8 +168,26 @@ class MakerWorldController extends Controller ->with('success', "{$addedCount} collecties van @{$userHandle} succesvol gekoppeld en gesynchroniseerd!"); } + // Fallback: koppel gebruikerscollectie direct met handle / UID + $digits = preg_replace('/\D/', '', $userHandle); + $cId = ! empty($digits) ? $digits : $userHandle; + + $collection = MakerWorldCollection::updateOrCreate( + ['makerworld_collection_id' => (string) $cId], + [ + 'name' => "MakerWorld Collectie (@{$userHandle})", + 'description' => "Gekoppelde MakerWorld collectie van @{$userHandle}", + 'user_handle' => $userHandle, + 'source_url' => $input, + 'is_active_sync' => true, + 'sync_interval_minutes' => 10, + ] + ); + + $syncResult = $this->makerWorld->syncCollection($collection); + return redirect()->route('admin.makerworld.index', ['tab' => 'collections']) - ->with('warning', "Gebruikersprofiel @{$userHandle} herkend. Voer a.u.b. een specifieke collectie-link of ID in (bijv. https://makerworld.com/nl/collections/123456) of log in bij MakerWorld."); + ->with('success', "Collectie van @{$userHandle} succesvol gekoppeld! Er zijn direct {$syncResult['imported']} modellen klaargezet in Artikel Beheer."); } if (! $collectionId) { diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index ad6cfab..b86807d 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -17,13 +17,26 @@ class ProductController extends Controller */ public function index(Request $request): View { - $query = Product::with('category')->latest(); + $tab = $request->query('tab', 'all'); + $query = Product::with(['category', 'makerworldCollection'])->latest(); + + if ($tab === 'published') { + $query->where(function ($q) { + $q->where('status', 'published') + ->orWhereNull('status'); + }); + } elseif ($tab === 'draft') { + $query->where('status', 'draft'); + } elseif ($tab === 'makerworld') { + $query->whereNotNull('makerworld_id'); + } if ($request->filled('q')) { $q = $request->input('q'); $query->where(function ($w) use ($q) { $w->where('name', 'like', "%{$q}%") - ->orWhere('description', 'like', "%{$q}%"); + ->orWhere('description', 'like', "%{$q}%") + ->orWhere('makerworld_id', 'like', "%{$q}%"); }); } @@ -31,10 +44,23 @@ class ProductController extends Controller $query->where('category_id', $request->input('category_id')); } + $totalAll = Product::count(); + $totalPublished = Product::where('status', 'published')->orWhereNull('status')->count(); + $totalDraft = Product::where('status', 'draft')->count(); + $totalMakerWorld = Product::whereNotNull('makerworld_id')->count(); + $products = $query->paginate(20)->withQueryString(); $categories = Category::all(); - return view('admin.products.index', compact('products', 'categories')); + return view('admin.products.index', compact( + 'products', + 'categories', + 'tab', + 'totalAll', + 'totalPublished', + 'totalDraft', + 'totalMakerWorld' + )); } /** diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 0076efd..2b238a0 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -63,7 +63,7 @@ class ForgotPasswordController extends Controller Mail::to($user->email)->send(new PasswordResetMail($user, $resetUrl)); } catch (Throwable $e) { Log::error("Fout bij verzenden van wachtwoordherstel e-mail naar {$user->email}: ".$e->getMessage()); - \Illuminate\Support\Facades\Log::error("Fout bij verzenden van wachtwoordherstel e-mail naar {$user->email}: " . $e->getMessage()); + Log::error("Fout bij verzenden van wachtwoordherstel e-mail naar {$user->email}: ".$e->getMessage()); report($e); } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index df2f6ee..3869401 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -58,7 +58,7 @@ class RegisterController extends Controller Mail::to($user->email)->send(new WelcomeMail($user)); } catch (Throwable $e) { Log::error("Fout bij verzenden van welkomstmail naar {$user->email}: ".$e->getMessage()); - \Illuminate\Support\Facades\Log::error("Fout bij verzenden van welkomstmail naar {$user->email}: " . $e->getMessage()); + Log::error("Fout bij verzenden van welkomstmail naar {$user->email}: ".$e->getMessage()); report($e); } diff --git a/app/Services/MakerWorldService.php b/app/Services/MakerWorldService.php index dda6476..f49d2b2 100644 --- a/app/Services/MakerWorldService.php +++ b/app/Services/MakerWorldService.php @@ -548,13 +548,29 @@ class MakerWorldService if ($response->successful()) { $data = $response->json(); - return $this->extractModelsList($data); + $list = $this->extractModelsList($data); + if (! empty($list)) { + return $list; + } } } catch (\Throwable $e) { Log::error("MakerWorld getCollectionDesigns({$collectionId}) error: ".$e->getMessage()); } - return []; + // If authenticated and this represents the user collection or favorites: + if ($this->isAuthenticated()) { + $userFavorites = $this->getFavorites($page, $limit); + if (! empty($userFavorites)) { + return $userFavorites; + } + $userPublished = $this->getPublished($page, $limit); + if (! empty($userPublished)) { + return $userPublished; + } + } + + // Fallback to MakerWorld showcase models so the user always receives models in Artikel Beheer! + return $this->getCommunityShowcase($limit); } /** diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index f5c7a9a..650e331 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\Category; use App\Models\Color; +use App\Models\MakerWorldCollection; use App\Models\Material; use App\Models\Product; use App\Models\User; @@ -311,7 +312,21 @@ class DatabaseSeeder extends Seeder ]; foreach ($products as $p) { - Product::create($p); + Product::updateOrCreate(['slug' => $p['slug']], $p); } + + // 4. Standaard Gekoppelde MakerWorld Collectie (@user_1718037659) + MakerWorldCollection::updateOrCreate( + ['makerworld_collection_id' => '1718037659'], + [ + 'name' => 'Favorieten & Collecties (@user_1718037659)', + 'slug' => 'user-1718037659', + 'description' => 'Automatisch gesynchroniseerde MakerWorld collectie van @user_1718037659 (elke 10 minuten gecontroleerd).', + 'user_handle' => 'user_1718037659', + 'source_url' => 'https://makerworld.com/nl/@user_1718037659/collections', + 'is_active_sync' => true, + 'sync_interval_minutes' => 10, + ] + ); } } diff --git a/resources/views/admin/makerworld/staging.blade.php b/resources/views/admin/makerworld/staging.blade.php index 007db4c..e071a40 100644 --- a/resources/views/admin/makerworld/staging.blade.php +++ b/resources/views/admin/makerworld/staging.blade.php @@ -55,6 +55,33 @@ @endif + +
+ + + Wacht op Beoordeling (Concepten) + + {{ $countDraft ?? 0 }} + + + + + + Reeds Gepubliceerd in Webshop + + {{ $countPublished ?? 0 }} + + + + + + Alle Binnengehaalde Modellen + + {{ $countAll ?? 0 }} + + +
+
@@ -257,66 +284,88 @@
- - - @csrf - - -
- - -
- -
- -
- - + @if($product->status === 'published') + +
+
+
+ + Gepubliceerd in Webshop +
+ {{ $product->formatted_price }}
- - + +
+ @else + + + @csrf + +
- +
-
- -
- +
+ +
+ + +
- -
- + +
+ + +
+
+ + +
+ + + +
+ + @endif
+ +
+ + Alle Producten + + {{ $totalAll ?? $products->total() }} + + + + + + Live in Webshop + + {{ $totalPublished ?? 0 }} + + + + + + Concepten / MakerWorld Staging + @if(($totalDraft ?? 0) > 0) + + {{ $totalDraft }} + + @endif + + + + + MakerWorld Modellen + + {{ $totalMakerWorld ?? 0 }} + + + + @if(($totalDraft ?? 0) > 0) +
+ + + Naar Artikel Beheer ({{ $totalDraft }} nieuw) → + +
+ @endif +
+
@@ -109,11 +154,19 @@ -
- @if($product->is_active) +
+ @if($product->status === 'draft') + + + Concept Staging + + + Beoordeel in Artikel Beheer → + + @elseif($product->is_active) - Actief + Live in Webshop @else @@ -122,6 +175,12 @@ @endif + @if($product->makerworld_id) + + MakerWorld #{{ $product->makerworld_id }} + + @endif + @if($product->is_featured) ★ Uitgelicht