-
Notifications
You must be signed in to change notification settings - Fork 2
feat(properties): implement product properties #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c8dcadd
feat(product-types): add migration and prototype model
SlimDeluxe f3c3f1d
Merge branch 'main' into feat/types
SlimDeluxe 9586084
fix: fix migration
SlimDeluxe 549bbed
feat(properties): implement product properties
KilianTrunk f29262d
fix: product value fixes on product resource
KilianTrunk 6b59264
fix: more testing fixes
KilianTrunk 85742f7
fix: remove unnecessary code
KilianTrunk 2956340
chore: add seeder to CatalogueSeeder & fix namespace
KilianTrunk ba8cd95
fix: fix translations
KilianTrunk 9e91b68
fix: fix breadcrumbs & add more translations
KilianTrunk 80a8fb3
fix: db structure fixes
KilianTrunk 7a0b436
fix: max values fix
KilianTrunk 5d25af8
style: fix code style
KilianTrunk 07531f8
chore: more improvements
KilianTrunk f79158a
Merge branch 'feat/properties' of github.com:KilianTrunk/eclipsephp-c…
KilianTrunk 18ce832
chore: product type fixes & removage of sort column
KilianTrunk 799c9b9
chore: update sorting of product type
KilianTrunk 7fae8ec
chore: improve sorting reordering for property values
KilianTrunk d6ecc8e
chore: set default property
KilianTrunk 6e42b4f
fix: fix reordering for property value
KilianTrunk 0d3e655
Merge branch 'main' into feat/properties
KilianTrunk cd784e6
fix: fix
KilianTrunk f2723e5
chore: property values improvements
KilianTrunk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
database/migrations/2025_08_19_171247_create_pim_property_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::create('pim_property', function (Blueprint $table) { | ||
| $table->id(); | ||
| $table->string('code', 50)->nullable()->unique(); | ||
| $table->string('name'); | ||
| $table->mediumText('description')->nullable(); | ||
| $table->string('internal_name')->nullable(); | ||
| $table->boolean('is_active')->default(true); | ||
| $table->boolean('is_global')->default(false); | ||
| $table->tinyInteger('max_values')->nullable(); | ||
| $table->boolean('enable_sorting')->default(false); | ||
| $table->boolean('is_filter')->default(false); | ||
| $table->timestamps(); | ||
| $table->softDeletes(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists('pim_property'); | ||
| } | ||
| }; |
33 changes: 33 additions & 0 deletions
33
database/migrations/2025_08_19_172834_create_pim_property_value_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::create('pim_property_value', function (Blueprint $table) { | ||
| $table->id(); | ||
| $table->foreignId('property_id')->constrained('pim_property')->onDelete('cascade'); | ||
| $table->string('value'); | ||
| $table->smallInteger('sort')->default(0); | ||
| $table->string('info_url')->nullable(); | ||
| $table->string('image')->nullable(); | ||
| $table->timestamps(); | ||
| $table->softDeletes(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists('pim_property_value'); | ||
| } | ||
| }; | ||
30 changes: 30 additions & 0 deletions
30
database/migrations/2025_08_19_174519_create_pim_product_type_has_property_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::create('pim_product_type_has_property', function (Blueprint $table) { | ||
| $table->foreignId('product_type_id')->constrained('pim_product_types')->onDelete('cascade'); | ||
|
SlimDeluxe marked this conversation as resolved.
Outdated
|
||
| $table->foreignId('property_id')->constrained('pim_property')->onDelete('cascade'); | ||
| $table->smallInteger('sort')->nullable(); | ||
| $table->timestamps(); | ||
| $table->primary(['product_type_id', 'property_id']); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists('pim_product_type_has_property'); | ||
| } | ||
| }; | ||
29 changes: 29 additions & 0 deletions
29
database/migrations/2025_08_19_175623_create_catalogue_product_has_property_value_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::create('catalogue_product_has_property_value', function (Blueprint $table) { | ||
| $table->foreignId('product_id')->constrained('catalogue_products')->onDelete('cascade'); | ||
| $table->foreignId('property_value_id')->constrained('pim_property_value')->onDelete('cascade'); | ||
| $table->timestamps(); | ||
| $table->unique(['product_id', 'property_value_id'], 'product_property_value_unique'); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists('catalogue_product_has_property_value'); | ||
| } | ||
| }; |
42 changes: 42 additions & 0 deletions
42
database/migrations/2025_08_19_175841_add_indexes_to_property_tables.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::table('pim_property', function (Blueprint $table) { | ||
| $table->index(['is_active', 'is_global']); | ||
| $table->index('is_filter'); | ||
|
SlimDeluxe marked this conversation as resolved.
Outdated
|
||
| }); | ||
| Schema::table('pim_property_value', function (Blueprint $table) { | ||
| $table->index(['property_id', 'sort']); | ||
| }); | ||
| Schema::table('pim_product_type_has_property', function (Blueprint $table) { | ||
| $table->index(['product_type_id', 'sort']); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::table('pim_property', function (Blueprint $table) { | ||
| $table->dropIndex('pim_property_is_active_is_global_index'); | ||
| $table->dropIndex('pim_property_is_filter_index'); | ||
| }); | ||
| Schema::table('pim_property_value', function (Blueprint $table) { | ||
| $table->dropIndex('pim_property_value_property_id_sort_index'); | ||
| }); | ||
| Schema::table('pim_product_type_has_property', function (Blueprint $table) { | ||
| $table->dropIndex('pim_product_type_has_property_product_type_id_sort_index'); | ||
| }); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| <?php | ||
|
|
||
| namespace Eclipse\Catalogue\Database\Seeders; | ||
|
SlimDeluxe marked this conversation as resolved.
Outdated
|
||
|
|
||
| use Eclipse\Catalogue\Models\ProductType; | ||
| use Eclipse\Catalogue\Models\Property; | ||
| use Eclipse\Catalogue\Models\PropertyValue; | ||
| use Illuminate\Database\Seeder; | ||
|
|
||
| class PropertySeeder extends Seeder | ||
| { | ||
| public function run(): void | ||
| { | ||
| // Create Brand property (global) | ||
| $brandProperty = Property::create([ | ||
| 'code' => 'brand', | ||
| 'name' => ['en' => 'Brand'], | ||
| 'description' => ['en' => 'Product brand or manufacturer'], | ||
| 'internal_name' => 'Brand/Manufacturer', | ||
| 'is_active' => true, | ||
| 'is_global' => true, | ||
| 'max_values' => 1, | ||
| 'enable_sorting' => false, | ||
| 'is_filter' => true, | ||
| ]); | ||
|
|
||
| // Create brand values | ||
| $brands = ['Nike', 'Adidas', 'Apple', 'Samsung', 'Sony']; | ||
| foreach ($brands as $index => $brand) { | ||
| PropertyValue::create([ | ||
| 'property_id' => $brandProperty->id, | ||
| 'value' => ['en' => $brand], | ||
| 'sort' => $index * 10, | ||
| ]); | ||
| } | ||
|
|
||
| // Create Color property (global) | ||
| $colorProperty = Property::create([ | ||
| 'code' => 'color', | ||
| 'name' => ['en' => 'Color'], | ||
| 'description' => ['en' => 'Product color'], | ||
| 'is_active' => true, | ||
| 'is_global' => true, | ||
| 'max_values' => 3, // Allow multiple colors | ||
| 'enable_sorting' => true, | ||
| 'is_filter' => true, | ||
| ]); | ||
|
|
||
| // Create color values | ||
| $colors = ['Red', 'Blue', 'Green', 'Black', 'White', 'Yellow', 'Purple', 'Orange']; | ||
| foreach ($colors as $index => $color) { | ||
| PropertyValue::create([ | ||
| 'property_id' => $colorProperty->id, | ||
| 'value' => ['en' => $color], | ||
| 'sort' => $index * 10, | ||
| ]); | ||
| } | ||
|
|
||
| // Create Size property (for clothing type only) | ||
| $sizeProperty = Property::create([ | ||
| 'code' => 'size', | ||
| 'name' => ['en' => 'Size'], | ||
| 'description' => ['en' => 'Clothing size'], | ||
| 'is_active' => true, | ||
| 'is_global' => false, | ||
| 'max_values' => 1, | ||
| 'enable_sorting' => true, | ||
| 'is_filter' => true, | ||
| ]); | ||
|
|
||
| // Create size values | ||
| $sizes = ['XS', 'S', 'M', 'L', 'XL', 'XXL']; | ||
| foreach ($sizes as $index => $size) { | ||
| PropertyValue::create([ | ||
| 'property_id' => $sizeProperty->id, | ||
| 'value' => ['en' => $size], | ||
| 'sort' => $index * 10, | ||
| ]); | ||
| } | ||
|
|
||
| // Create Material property | ||
| $materialProperty = Property::create([ | ||
| 'code' => 'material', | ||
| 'name' => ['en' => 'Material'], | ||
| 'description' => ['en' => 'Product material composition'], | ||
| 'is_active' => true, | ||
| 'is_global' => false, | ||
| 'max_values' => 2, // Allow multiple materials | ||
| 'enable_sorting' => false, | ||
| 'is_filter' => true, | ||
| ]); | ||
|
|
||
| // Create material values | ||
| $materials = ['Cotton', 'Polyester', 'Wool', 'Silk', 'Leather', 'Plastic', 'Metal', 'Wood']; | ||
| foreach ($materials as $index => $material) { | ||
| PropertyValue::create([ | ||
| 'property_id' => $materialProperty->id, | ||
| 'value' => ['en' => $material], | ||
| 'sort' => $index * 10, | ||
| ]); | ||
| } | ||
|
|
||
| // If there are product types, assign non-global properties to some of them | ||
| $productTypes = ProductType::all(); | ||
| if ($productTypes->isNotEmpty()) { | ||
| // Assign size to first product type (assuming it's clothing) | ||
| if ($productTypes->count() > 0) { | ||
| $productTypes->first()->properties()->attach($sizeProperty->id, ['sort' => 10]); | ||
| } | ||
|
|
||
| // Assign material to first two product types | ||
| foreach ($productTypes->take(2) as $index => $productType) { | ||
| $productType->properties()->attach($materialProperty->id, ['sort' => 20]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php | ||
|
|
||
| namespace Eclipse\Catalogue\Factories; | ||
|
|
||
| use Eclipse\Catalogue\Models\Property; | ||
| use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
|
||
| class PropertyFactory extends Factory | ||
| { | ||
| protected $model = Property::class; | ||
|
|
||
| public function definition(): array | ||
| { | ||
| return [ | ||
| 'code' => $this->faker->unique()->slug(2), | ||
| 'name' => ['en' => $this->faker->words(2, true)], | ||
| 'description' => ['en' => $this->faker->sentence()], | ||
| 'internal_name' => $this->faker->words(3, true), | ||
| 'is_active' => true, | ||
| 'is_global' => $this->faker->boolean(20), // 20% chance of being global | ||
| 'max_values' => $this->faker->randomElement([1, 2, 5]), | ||
| 'enable_sorting' => $this->faker->boolean(30), | ||
| 'is_filter' => $this->faker->boolean(40), | ||
| ]; | ||
| } | ||
|
|
||
| public function global(): static | ||
| { | ||
| return $this->state(fn (array $attributes) => [ | ||
| 'is_global' => true, | ||
| ]); | ||
| } | ||
|
|
||
| public function singleValue(): static | ||
| { | ||
| return $this->state(fn (array $attributes) => [ | ||
| 'max_values' => 1, | ||
| ]); | ||
| } | ||
|
|
||
| public function multipleValues(): static | ||
| { | ||
| return $this->state(fn (array $attributes) => [ | ||
| 'max_values' => $this->faker->numberBetween(2, 10), | ||
| ]); | ||
| } | ||
|
|
||
| public function filter(): static | ||
| { | ||
| return $this->state(fn (array $attributes) => [ | ||
| 'is_filter' => true, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| namespace Eclipse\Catalogue\Factories; | ||
|
|
||
| use Eclipse\Catalogue\Models\Property; | ||
| use Eclipse\Catalogue\Models\PropertyValue; | ||
| use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
|
||
| class PropertyValueFactory extends Factory | ||
| { | ||
| protected $model = PropertyValue::class; | ||
|
|
||
| public function definition(): array | ||
| { | ||
| return [ | ||
| 'property_id' => Property::factory(), | ||
| 'value' => ['en' => $this->faker->word()], | ||
| 'sort' => $this->faker->numberBetween(0, 100), | ||
| 'info_url' => $this->faker->optional(0.3)->url(), | ||
| 'image' => $this->faker->optional(0.2)->imageUrl(200, 200), | ||
| ]; | ||
| } | ||
|
|
||
| public function forProperty(Property $property): static | ||
| { | ||
| return $this->state(fn (array $attributes) => [ | ||
| 'property_id' => $property->id, | ||
| ]); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.