feat: implement Bundle and BundleItem models, migrations, and polymorphic relationships for cart and purchase items
This commit is contained in:
@@ -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('bundles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('tenant_codigo', 10);
|
||||
$table->string('nombre');
|
||||
$table->text('descripcion')->nullable();
|
||||
$table->decimal('precio', 10, 2);
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('tenant_codigo')->references('codigo')->on('tenants')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bundles');
|
||||
}
|
||||
};
|
||||
@@ -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('bundle_items', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('bundle_id')->constrained('bundles')->onDelete('cascade');
|
||||
$table->foreignId('producto_variante_id')->constrained('productos_variantes')->onDelete('cascade');
|
||||
$table->integer('cantidad');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bundle_items');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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('carrito_items', function (Blueprint $table) {
|
||||
$table->string('buyable_type')->nullable();
|
||||
$table->unsignedBigInteger('buyable_id')->nullable();
|
||||
});
|
||||
|
||||
// Copy existing data
|
||||
\Illuminate\Support\Facades\DB::table('carrito_items')->update([
|
||||
'buyable_type' => 'App\Domains\Catalog\Models\ProductVariant',
|
||||
'buyable_id' => \Illuminate\Support\Facades\DB::raw('producto_variante_id'),
|
||||
]);
|
||||
|
||||
Schema::table('carrito_items', function (Blueprint $table) {
|
||||
$table->dropForeign(['producto_variante_id']);
|
||||
$table->dropColumn('producto_variante_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('carrito_items', function (Blueprint $table) {
|
||||
$table->foreignId('producto_variante_id')->nullable()->constrained('productos_variantes')->onDelete('cascade');
|
||||
});
|
||||
|
||||
\Illuminate\Support\Facades\DB::table('carrito_items')->update([
|
||||
'producto_variante_id' => \Illuminate\Support\Facades\DB::raw('buyable_id'),
|
||||
]);
|
||||
|
||||
Schema::table('carrito_items', function (Blueprint $table) {
|
||||
$table->dropColumn(['buyable_type', 'buyable_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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('compra_items', function (Blueprint $table) {
|
||||
$table->string('buyable_type')->nullable();
|
||||
$table->unsignedBigInteger('buyable_id')->nullable();
|
||||
});
|
||||
|
||||
// Copy existing data
|
||||
\Illuminate\Support\Facades\DB::table('compra_items')->update([
|
||||
'buyable_type' => 'App\Domains\Catalog\Models\ProductVariant',
|
||||
'buyable_id' => \Illuminate\Support\Facades\DB::raw('producto_variante_id'),
|
||||
]);
|
||||
|
||||
Schema::table('compra_items', function (Blueprint $table) {
|
||||
$table->dropForeign(['producto_variante_id']);
|
||||
$table->dropColumn('producto_variante_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('compra_items', function (Blueprint $table) {
|
||||
$table->foreignId('producto_variante_id')->nullable()->constrained('productos_variantes')->onDelete('cascade');
|
||||
});
|
||||
|
||||
\Illuminate\Support\Facades\DB::table('compra_items')->update([
|
||||
'producto_variante_id' => \Illuminate\Support\Facades\DB::raw('buyable_id'),
|
||||
]);
|
||||
|
||||
Schema::table('compra_items', function (Blueprint $table) {
|
||||
$table->dropColumn(['buyable_type', 'buyable_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user