feat(catalog): add GroupLayout enum and integrate into FeaturedGroup model, migrations, and seeders
This commit is contained in:
19
app/Domains/Catalog/Enums/GroupLayout.php
Normal file
19
app/Domains/Catalog/Enums/GroupLayout.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Enums;
|
||||
|
||||
enum GroupLayout: string
|
||||
{
|
||||
case Paginated = 'paginated';
|
||||
case Simple = 'simple';
|
||||
case SimpleVertical = 'simple_vertical';
|
||||
case Carousel = 'carousel';
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domains\Catalog\Models;
|
||||
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
@@ -13,6 +14,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
#[Fillable([
|
||||
'tenant_code',
|
||||
'product_layout',
|
||||
'group_layout',
|
||||
'group_name',
|
||||
'group_order',
|
||||
])]
|
||||
@@ -28,6 +30,7 @@ class FeaturedGroup extends Model
|
||||
{
|
||||
return [
|
||||
'product_layout' => ProductLayout::class,
|
||||
'group_layout' => GroupLayout::class,
|
||||
'group_order' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ class CatalogFeaturedGroupResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'title' => $this->group_name,
|
||||
'layout' => $this->product_layout->value,
|
||||
'group_layout' => $this->group_layout->value,
|
||||
'group_order' => $this->group_order,
|
||||
'items' => $this->itemsPage,
|
||||
];
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
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('featured_groups', function (Blueprint $table): void {
|
||||
$table->enum('group_layout', GroupLayout::values())
|
||||
->default(GroupLayout::Paginated->value)
|
||||
->after('product_layout');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('featured_groups', function (Blueprint $table): void {
|
||||
$table->dropColumn('group_layout');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
@@ -167,6 +168,7 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
$featuredGroup = FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'product_layout' => ProductLayout::Row,
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
'group_name' => $groupName,
|
||||
'group_order' => $groupOrder++,
|
||||
]);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
@@ -170,6 +171,7 @@ class ProductCatalogFromImagesSeeder extends Seeder
|
||||
$group = FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'product_layout' => ProductLayout::ColumnWithImage,
|
||||
'group_layout' => GroupLayout::Paginated,
|
||||
'group_name' => 'Productos',
|
||||
'group_order' => 0,
|
||||
]);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature\Catalog;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
@@ -21,7 +22,13 @@ class CatalogControllerTest extends TestCase
|
||||
{
|
||||
$tenant = $this->createTenant('catalog-index');
|
||||
$row = $this->createGroup($tenant, ProductLayout::Row, 'Row', 2);
|
||||
$cart = $this->createGroup($tenant, ProductLayout::ColumnWithCart, 'Cart', 1);
|
||||
$cart = $this->createGroup(
|
||||
$tenant,
|
||||
ProductLayout::ColumnWithCart,
|
||||
'Cart',
|
||||
1,
|
||||
GroupLayout::SimpleVertical,
|
||||
);
|
||||
|
||||
$directInventory = Inventory::query()->create([
|
||||
'real_stock' => 10,
|
||||
@@ -50,6 +57,7 @@ class CatalogControllerTest extends TestCase
|
||||
->assertJsonCount(2)
|
||||
->assertJsonPath('0.title', 'Cart')
|
||||
->assertJsonPath('0.layout', ProductLayout::ColumnWithCart->value)
|
||||
->assertJsonPath('0.group_layout', GroupLayout::SimpleVertical->value)
|
||||
->assertJsonPath('0.items.meta.current_page', 1)
|
||||
->assertJsonPath('0.items.data.0.nombre', 'Variants')
|
||||
->assertJsonPath('0.items.data.0.descripcion', 'Variants description')
|
||||
@@ -142,10 +150,12 @@ class CatalogControllerTest extends TestCase
|
||||
ProductLayout $layout,
|
||||
string $name,
|
||||
int $order = 0,
|
||||
GroupLayout $groupLayout = GroupLayout::Paginated,
|
||||
): FeaturedGroup {
|
||||
return FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'product_layout' => $layout,
|
||||
'group_layout' => $groupLayout,
|
||||
'group_name' => $name,
|
||||
'group_order' => $order,
|
||||
]);
|
||||
|
||||
@@ -78,6 +78,7 @@ class CatalogSchemaTest extends TestCase
|
||||
'id',
|
||||
'tenant_code',
|
||||
'product_layout',
|
||||
'group_layout',
|
||||
'group_name',
|
||||
'group_order',
|
||||
], Schema::getColumnListing('featured_groups'));
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature\Seeders;
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
@@ -133,6 +134,10 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
->with('featuredItems.catalogItem')
|
||||
->orderBy('group_order')
|
||||
->get()
|
||||
->each(fn (FeaturedGroup $group) => $this->assertSame(
|
||||
GroupLayout::Paginated,
|
||||
$group->group_layout,
|
||||
))
|
||||
->mapWithKeys(fn (FeaturedGroup $group): array => [
|
||||
$group->group_name => $group->featuredItems->pluck('catalogItem.slug')->all(),
|
||||
])
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
@@ -58,6 +59,7 @@ class ProductCatalogFromImagesSeederTest extends TestCase
|
||||
|
||||
$this->assertSame('Productos', $group->group_name);
|
||||
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
||||
$this->assertSame(GroupLayout::Paginated, $group->group_layout);
|
||||
$this->assertSame(0, $group->group_order);
|
||||
$this->assertSame(
|
||||
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('id')->pluck('slug')->all(),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Unit\Catalog;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
@@ -25,6 +26,16 @@ use Tests\TestCase;
|
||||
|
||||
class CatalogModelsTest extends TestCase
|
||||
{
|
||||
public function test_group_layout_has_all_supported_values(): void
|
||||
{
|
||||
$this->assertSame([
|
||||
'paginated',
|
||||
'simple',
|
||||
'simple_vertical',
|
||||
'carousel',
|
||||
], GroupLayout::values());
|
||||
}
|
||||
|
||||
public function test_attribute_maps_its_values_and_relations(): void
|
||||
{
|
||||
$attribute = new Attribute;
|
||||
@@ -83,6 +94,7 @@ class CatalogModelsTest extends TestCase
|
||||
$group = new FeaturedGroup;
|
||||
$group->setRawAttributes([
|
||||
'product_layout' => ProductLayout::ColumnWithImage->value,
|
||||
'group_layout' => GroupLayout::SimpleVertical->value,
|
||||
'group_order' => '2',
|
||||
]);
|
||||
$featuredItem = new FeaturedItem;
|
||||
@@ -95,6 +107,7 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertSame('featured_groups', $group->getTable());
|
||||
$this->assertFalse($group->usesTimestamps());
|
||||
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
||||
$this->assertSame(GroupLayout::SimpleVertical, $group->group_layout);
|
||||
$this->assertSame(2, $group->group_order);
|
||||
$this->assertInstanceOf(Tenant::class, $group->tenant()->getRelated());
|
||||
$this->assertInstanceOf(FeaturedItem::class, $group->featuredItems()->getRelated());
|
||||
|
||||
Reference in New Issue
Block a user