Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"eclipsephp/common": "dev-main",
"filament/filament": "^3.3",
"filament/spatie-laravel-translatable-plugin": "^3.2",
"solution-forest/filament-tree": "^2.1",
"spatie/laravel-package-tools": "^1.19",
"spatie/laravel-translatable": "^6.11"
},
Expand Down
11 changes: 10 additions & 1 deletion config/eclipse-catalogue.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

return [
//

/*
|--------------------------------------------------------------------------
| Multi-tenancy config
|--------------------------------------------------------------------------
*/
'tenancy' => [
'model' => null,
'foreign_key' => null,
],
];
97 changes: 97 additions & 0 deletions database/factories/CategoryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace Eclipse\Catalogue\Factories;

use Eclipse\Catalogue\Models\Category;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;

class CategoryFactory extends Factory
{
protected $model = Category::class;

public function definition(): array
{
$englishName = mb_ucfirst(fake()->words(2, true));
$slovenianName = 'SI: '.$englishName;

$englishShortDesc = fake()->sentence();
$slovenianShortDesc = 'SI: '.$englishShortDesc;

$englishDesc = fake()->paragraphs(3, true);
$slovenianDesc = 'SI: '.$englishDesc;

return [
'name' => [
'en' => $englishName,
'sl' => $slovenianName,
],
'parent_id' => null,
'image' => self::generateCategoryImage($englishName),
'sort' => fake()->randomNumber(),
'is_active' => fake()->boolean(),
'code' => fake()->optional()->bothify('CAT-####'),
'recursive_browsing' => fake()->boolean(),
'sef_key' => [
'en' => Str::slug($englishName),
'sl' => Str::slug($slovenianName),
],
'short_desc' => [
'en' => $englishShortDesc,
'sl' => $slovenianShortDesc,
],
'description' => [
'en' => $englishDesc,
'sl' => $slovenianDesc,
],
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
'site_id' => null,
];
}

private static function generateCategoryImage(string $name): ?string
{
$colors = ['3B82F6', '10B981', 'F59E0B', 'EF4444', '8B5CF6', '06B6D4', 'F97316', 'EC4899'];
$backgrounds = ['E0F2FE', 'ECFDF5', 'FFFBEB', 'FEF2F2', 'F3E8FF', 'ECFEFF', 'FFF7ED', 'FDF2F8'];

$color = fake()->randomElement($colors);
$background = fake()->randomElement($backgrounds);

return fake()->optional(0.8)->passthrough(
'https://ui-avatars.com/api/?name='.urlencode($name).
'&size=400&background='.$background.
'&color='.$color.
'&bold=true&format=png'
);
}

public function parent(): static
{
return $this->state(fn (array $attributes): array => [
'parent_id' => null,
]);
}

public function child(?Category $parent = null): static
{
return $this->state(fn (array $attributes): array => [
'parent_id' => $parent?->id ?? Category::factory()->parent()->create()->id,
]);
}

public function active(): static
{
return $this->state(fn (array $attributes): array => [
'is_active' => true,
]);
}

public function inactive(): static
{
return $this->state(fn (array $attributes): array => [
'is_active' => false,
]);
}
}
2 changes: 2 additions & 0 deletions database/factories/ProductFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Eclipse\Catalogue\Factories;

use Eclipse\Catalogue\Models\Category;
use Eclipse\Catalogue\Models\Product;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -32,6 +33,7 @@ public function definition(): array
'en' => $englishName,
'sl' => $slovenianName,
],
'category_id' => Category::inRandomOrder()->first()?->id ?? Category::factory(),
'short_description' => [
'en' => $englishShortDesc,
'sl' => $slovenianShortDesc,
Expand Down
36 changes: 36 additions & 0 deletions database/migrations/2025_07_01_141618_create_categories_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('catalogue_categories', function (Blueprint $table) {
$table->id();
$table->foreignId('site_id')
->constrained()
->cascadeOnDelete()
->cascadeOnUpdate();
$table->string('name');
$table->integer('parent_id')->default(-1);
$table->string('image')->nullable();
$table->integer('sort')->default(0)->index();
$table->boolean('is_active');
$table->string('code')->nullable();
$table->boolean('recursive_browsing')->nullable();
$table->string('sef_key')->nullable();
$table->text('short_desc')->nullable();
$table->text('description')->nullable();
$table->timestamps();
$table->softDeletes();
});
}

public function down(): void
{
Schema::dropIfExists('catalogue_categories');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('catalogue_products', function (Blueprint $table) {
$table->foreignId('category_id')
->nullable()
->after('name')
->constrained('catalogue_categories')
->nullOnDelete()
->cascadeOnUpdate();
});
}

public function down(): void
{
Schema::table('catalogue_products', function (Blueprint $table) {
$table->dropForeign(['category_id']);
$table->dropColumn('category_id');
});
}
};
38 changes: 38 additions & 0 deletions database/seeders/CategorySeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Eclipse\Catalogue\Seeders;

use Eclipse\Catalogue\Models\Category;
use Illuminate\Database\Seeder;

class CategorySeeder extends Seeder
{
public function run(): void
{
$tenantModel = config('eclipse-catalogue.tenancy.model');
$tenantFK = config('eclipse-catalogue.tenancy.foreign_key');
$tenants = $tenantModel::all();

foreach ($tenants as $tenant) {
$parents = Category::factory()
->parent()
->active()
->count(3)
->create([$tenantFK => $tenant->id]);

foreach ($parents as $index => $parent) {
$childrenCount = match ($index) {
0 => 3,
1 => 2,
2 => 2,
};

Category::factory()
->child($parent)
->active()
->count($childrenCount)
->create([$tenantFK => $tenant->id]);
}
}
}
}
81 changes: 81 additions & 0 deletions resources/lang/en/categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

return [
'title' => 'Categories',
'navigation_group' => 'Catalogue',
'sorting' => 'Sorting',

'form' => [
'sections' => [
'basic_information' => 'Basic Information',
'content' => 'Content',
'media_settings' => 'Media & Settings',
'system_information' => 'System Information',
],
'fields' => [
'parent_id' => 'Parent Category',
'parent_id_placeholder' => 'Select parent category (optional)',
'name' => 'Name',
'name_placeholder' => 'Enter category name',
'code' => 'Code',
'code_placeholder' => 'Enter category code',
'sef_key' => 'SEF Key',
'sef_key_placeholder' => 'URL-friendly key (auto-generated if empty)',
'sef_key_helper' => 'Leave empty to auto-generate from category name',
'short_desc' => 'Short Description',
'short_desc_placeholder' => 'Enter a brief description',
'description' => 'Full Description',
'description_placeholder' => 'Enter detailed category description',
'image' => 'Category Image',
'is_active' => 'Active',
'is_active_helper' => 'Whether this category is visible',
'recursive_browsing' => 'Recursive Browsing',
'recursive_browsing_helper' => 'Allow browsing subcategories recursively',
'created_at' => 'Created Date',
'updated_at' => 'Last Modified Date',
'not_yet_saved' => 'Not yet saved',
],
'errors' => [
'sef_key' => 'The SEF key has already been taken.',
'parent_id' => 'Cannot select this category as parent - it would create a circular reference',
],
],

'table' => [
'columns' => [
'image' => 'Image',
'name' => 'Category',
'sef_key' => 'SEF Key',
'is_active' => 'Active',
'code' => 'Code',
'recursive_browsing' => 'Recursive',
'description' => 'Long Desc.',
'short_desc' => 'Short Description',
],
'tooltips' => [
'recursive_browsing' => 'Include products from subcategories',
'has_description' => 'Has description',
'no_description' => 'No description',
],
],

'filters' => [
'parent_category' => 'Parent Category',
'category_placeholder' => 'All Categories',
'is_active' => 'Status',
'active' => 'Active',
'inactive' => 'Inactive',
'all_statuses' => 'All Statuses',
'has_description' => 'Has Description',
],

'actions' => [
'create' => 'Create',
'edit' => 'Edit',
'delete' => 'Delete',
'restore' => 'Restore',
'force_delete' => 'Force Delete',
'sorting' => 'Sorting',
'bulk_actions' => 'Bulk Actions',
],
];
5 changes: 0 additions & 5 deletions resources/lang/en/plugin-template.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/CatalogueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Eclipse\Catalogue;

use Eclipse\Catalogue\Models\Category;
use Eclipse\Catalogue\Models\Product;
use Illuminate\Support\Facades\Config;
use Spatie\LaravelPackageTools\Package;
Expand All @@ -28,6 +29,7 @@ public function register()

$settings += [
Product::class => Product::getTypesenseSettings(),
Category::class => Category::getTypesenseSettings(),
];

Config::set('scout.typesense.model-settings', $settings);
Expand Down
Loading