Skip to content

Commit da7413b

Browse files
committed
feat: add product data table and more attributes
1 parent 507d66e commit da7413b

3 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
Schema::create('catalogue_product_data', function (Blueprint $table) {
11+
$table->id();
12+
$table->foreignId('product_id');
13+
14+
// Add foreign key for tenant if it's configured in the catalogue config
15+
if (config('eclipse-catalogue.tenancy.model')) {
16+
$tenantClass = config('eclipse-catalogue.tenancy.model');
17+
/** @var \Illuminate\Database\Eloquent\Model $tenant */
18+
$tenant = new $tenantClass;
19+
$table->foreignId(config('eclipse-catalogue.tenancy.foreign_key'))
20+
->constrained($tenant->getTable(), $tenant->getKeyName())
21+
->cascadeOnUpdate()
22+
->cascadeOnDelete();
23+
}
24+
25+
$table->string('sorting_label')->nullable();
26+
$table->boolean('is_active')->default(false);
27+
$table->dateTime('available_from_date')->nullable();
28+
$table->boolean('has_free_delivery')->default(false);
29+
});
30+
}
31+
32+
public function down(): void
33+
{
34+
Schema::dropIfExists('catalogue_product_data');
35+
}
36+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
Schema::table('catalogue_products', function (Blueprint $table) {
11+
$table->foreignId('origin_country_id')
12+
->nullable()
13+
->constrained('world_countries')
14+
->cascadeOnUpdate()
15+
->restrictOnDelete();
16+
$table->text('meta_description')
17+
->nullable();
18+
$table->string('meta_title')
19+
->nullable();
20+
});
21+
}
22+
23+
public function down(): void
24+
{
25+
Schema::table('catalogue_products', function (Blueprint $table) {
26+
$table->dropForeign('origin_country_id');
27+
$table->dropColumn([
28+
'origin_country_id',
29+
'meta_description',
30+
'meta_title',
31+
]);
32+
});
33+
}
34+
};

src/Models/ProductData.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Eclipse\Catalogue\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
8+
class ProductData extends Model
9+
{
10+
protected $table = 'catalogue_product_data';
11+
12+
public $timestamps = false;
13+
14+
protected $fillable = [
15+
'product_id',
16+
'sorting_label',
17+
'is_active',
18+
'available_from_date',
19+
'has_free_delivery',
20+
];
21+
22+
public function product(): BelongsTo
23+
{
24+
return $this->belongsTo(Product::class);
25+
}
26+
27+
protected function casts(): array
28+
{
29+
return [
30+
'is_active' => 'boolean',
31+
'available_from_date' => 'datetime',
32+
'has_free_delivery' => 'boolean',
33+
];
34+
}
35+
}

0 commit comments

Comments
 (0)