feat: add cart editing feature to tenants
- Added 'cart_editing_enabled' attribute to Tenant model with default value true. - Updated StoreTenantRequest and UpdateTenantRequest to include validation for 'cart_editing_enabled'. - Modified TenantResource to expose 'cart_editing_enabled' in API responses. - Created migration to add 'cart_editing_enabled' column to tenants table, defaulting to true, and set to false for specific tenant. - Updated DesfilePuraTendenciaSeeder to set 'cart_editing_enabled' to false for the desfile tenant. - Enhanced Postman collection generation script to include 'cart_editing_enabled' in tenant creation and update requests. - Added tests to verify the correct behavior of 'cart_editing_enabled' during migrations and tenant provisioning.
This commit is contained in:
@@ -9,27 +9,35 @@ return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('clients', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
if (! Schema::hasTable('clients')) {
|
||||
Schema::create('clients', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreignId('client_id')->nullable()->after('id')->constrained('clients')->restrictOnDelete();
|
||||
});
|
||||
if (! Schema::hasColumn('tenants', 'client_id')) {
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreignId('client_id')->nullable()->after('id')->constrained('clients')->restrictOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
DB::table('tenants')
|
||||
->select(['id', 'codigo', 'nombre', 'created_at', 'updated_at'])
|
||||
->orderBy('id')
|
||||
->each(function (object $tenant): void {
|
||||
$clientId = DB::table('clients')->insertGetId([
|
||||
'code' => $tenant->codigo,
|
||||
'name' => $tenant->nombre,
|
||||
'created_at' => $tenant->created_at ?? now(),
|
||||
'updated_at' => $tenant->updated_at ?? now(),
|
||||
]);
|
||||
$clientId = DB::table('clients')->where('code', $tenant->codigo)->value('id');
|
||||
|
||||
if ($clientId === null) {
|
||||
$clientId = DB::table('clients')->insertGetId([
|
||||
'code' => $tenant->codigo,
|
||||
'name' => $tenant->nombre,
|
||||
'created_at' => $tenant->created_at ?? now(),
|
||||
'updated_at' => $tenant->updated_at ?? now(),
|
||||
]);
|
||||
}
|
||||
|
||||
DB::table('tenants')->where('id', $tenant->id)->update(['client_id' => $clientId]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const DESFILE_TENANT_CODE = 'desfile_pura_tendencia';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->boolean('cart_editing_enabled')->default(true)->after('display_cart');
|
||||
});
|
||||
|
||||
DB::table('tenants')
|
||||
->where('codigo', self::DESFILE_TENANT_CODE)
|
||||
->update(['cart_editing_enabled' => false]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->dropColumn('cart_editing_enabled');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -40,7 +40,10 @@ class DesfilePuraTendenciaSeeder extends Seeder
|
||||
$tenant = Tenant::query()->where('codigo', self::TENANT_CODE)->first();
|
||||
|
||||
if ($tenant) {
|
||||
$tenant->update(['client_id' => $client->id]);
|
||||
$tenant->update([
|
||||
'client_id' => $client->id,
|
||||
'cart_editing_enabled' => false,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -72,6 +75,7 @@ class DesfilePuraTendenciaSeeder extends Seeder
|
||||
'display_categories' => false,
|
||||
'display_seach_bar' => false,
|
||||
'display_cart' => true,
|
||||
'cart_editing_enabled' => false,
|
||||
'scanner_category_validation_enabled' => false,
|
||||
'website_type_code' => 'onticket',
|
||||
'header_logo' => $this->uploadedImage(
|
||||
|
||||
Reference in New Issue
Block a user