feat(migration): enhance Mutual SMEP catalog seeding with featured groups and highlighted products
This commit is contained in:
@@ -15,7 +15,34 @@ return new class extends Migration
|
||||
|
||||
private const BRAND_MARKER = 'Provisioned by Mutual SMEP catalog migration v1.';
|
||||
|
||||
private const FEATURED_GROUP_CODE = 'productos-smep';
|
||||
/** @var list<array{code: string, category: string}> */
|
||||
private const FEATURED_GROUPS = [
|
||||
['code' => 'smep-dormitorio-y-blanco', 'category' => 'Dormitorio y Blanco'],
|
||||
['code' => 'smep-electrodomesticos', 'category' => 'Electrodomésticos'],
|
||||
['code' => 'smep-climatizacion', 'category' => 'Climatización'],
|
||||
['code' => 'smep-tecnologia', 'category' => 'Tecnología'],
|
||||
['code' => 'smep-bicicletas-y-aire-libre', 'category' => 'Bicicletas y Aire Libre'],
|
||||
['code' => 'smep-bazar', 'category' => 'Bazar'],
|
||||
];
|
||||
|
||||
private const HIGHLIGHTED_GROUP_CODE = 'productos-destacados-smep';
|
||||
|
||||
/** @var list<string> */
|
||||
private const HIGHLIGHTED_PRODUCT_SLUGS = [
|
||||
'acolchado-kavanagh-simil-plumon-reversible',
|
||||
'acolchado-sense-duo-bitono-corderito',
|
||||
'colchon-inducol-constanza',
|
||||
'edredon-lisboa-jean-cartier',
|
||||
'frazada-kavanagh-premium-soft',
|
||||
'kit-edredon-alaska-corderito',
|
||||
'motorola-g15',
|
||||
'smart-tv-noblex-50-dr50-x8500-google-tv',
|
||||
'heladera-gafa-hgf-368afp-330-lt-color-plata',
|
||||
'cafetera-express-atma-ceat-5418p-1-litro',
|
||||
'split-3300-w-tcl-taca-3300fcsa-frio-calor',
|
||||
'bicicleta-venzo-loki-r29-fd-21-v-shimano',
|
||||
'termo-stanley-1-l-adventure-go-to-con-tapon',
|
||||
];
|
||||
|
||||
/** @var list<string> */
|
||||
private array $storedPaths = [];
|
||||
@@ -121,16 +148,7 @@ return new class extends Migration
|
||||
}
|
||||
}
|
||||
|
||||
DB::table('featured_groups')->insert([
|
||||
'tenant_code' => self::TENANT_CODE,
|
||||
'code' => self::FEATURED_GROUP_CODE,
|
||||
'source_type' => 'all',
|
||||
'category_id' => null,
|
||||
'product_layout' => 'column_with_image',
|
||||
'group_layout' => 'paginated',
|
||||
'group_name' => 'Productos',
|
||||
'group_order' => 1,
|
||||
]);
|
||||
$this->createFeaturedGroups();
|
||||
});
|
||||
} catch (Throwable $throwable) {
|
||||
Storage::disk('s3')->delete($this->storedPaths);
|
||||
@@ -172,7 +190,10 @@ return new class extends Migration
|
||||
): void {
|
||||
DB::table('featured_groups')
|
||||
->where('tenant_code', self::TENANT_CODE)
|
||||
->where('code', self::FEATURED_GROUP_CODE)
|
||||
->whereIn('code', [
|
||||
self::HIGHLIGHTED_GROUP_CODE,
|
||||
...array_column(self::FEATURED_GROUPS, 'code'),
|
||||
])
|
||||
->delete();
|
||||
DB::table('catalog_items')->whereIn('id', $catalogItemIds)->delete();
|
||||
DB::table('inventories')
|
||||
@@ -306,6 +327,84 @@ return new class extends Migration
|
||||
]);
|
||||
}
|
||||
|
||||
private function createFeaturedGroups(): void
|
||||
{
|
||||
$this->createHighlightedGroup();
|
||||
|
||||
foreach (self::FEATURED_GROUPS as $order => $group) {
|
||||
$categoryId = DB::table('categorias')
|
||||
->where('tenant_code', self::TENANT_CODE)
|
||||
->whereNull('categoria_id')
|
||||
->where('nombre', $group['category'])
|
||||
->value('id');
|
||||
|
||||
if ($categoryId === null) {
|
||||
throw new RuntimeException("Parent category '{$group['category']}' not found for Mutual SMEP.");
|
||||
}
|
||||
|
||||
$featuredGroupId = DB::table('featured_groups')->insertGetId([
|
||||
'tenant_code' => self::TENANT_CODE,
|
||||
'code' => $group['code'],
|
||||
'source_type' => 'manual',
|
||||
'category_id' => $categoryId,
|
||||
'product_layout' => 'column_with_image',
|
||||
'group_layout' => 'carousel',
|
||||
'group_name' => $group['category'],
|
||||
'group_order' => $order + 2,
|
||||
]);
|
||||
|
||||
$catalogItemIds = DB::table('catalog_items')
|
||||
->join('categorias', 'categorias.id', '=', 'catalog_items.category_id')
|
||||
->where('catalog_items.tenant_code', self::TENANT_CODE)
|
||||
->where('categorias.tenant_code', self::TENANT_CODE)
|
||||
->where('categorias.categoria_id', $categoryId)
|
||||
->orderBy('catalog_items.group_order')
|
||||
->orderBy('catalog_items.id')
|
||||
->pluck('catalog_items.id');
|
||||
|
||||
foreach ($catalogItemIds as $itemOrder => $catalogItemId) {
|
||||
DB::table('featured_items')->insert([
|
||||
'featured_group_id' => $featuredGroupId,
|
||||
'catalog_item_id' => $catalogItemId,
|
||||
'order' => $itemOrder + 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createHighlightedGroup(): void
|
||||
{
|
||||
$featuredGroupId = DB::table('featured_groups')->insertGetId([
|
||||
'tenant_code' => self::TENANT_CODE,
|
||||
'code' => self::HIGHLIGHTED_GROUP_CODE,
|
||||
'source_type' => 'manual',
|
||||
'category_id' => null,
|
||||
'product_layout' => 'column_with_image',
|
||||
'group_layout' => 'carousel',
|
||||
'group_name' => 'Productos destacados',
|
||||
'group_order' => 1,
|
||||
]);
|
||||
|
||||
$catalogItemIds = DB::table('catalog_items')
|
||||
->where('tenant_code', self::TENANT_CODE)
|
||||
->whereIn('slug', self::HIGHLIGHTED_PRODUCT_SLUGS)
|
||||
->pluck('id', 'slug');
|
||||
|
||||
foreach (self::HIGHLIGHTED_PRODUCT_SLUGS as $order => $slug) {
|
||||
$catalogItemId = $catalogItemIds->get($slug);
|
||||
|
||||
if ($catalogItemId === null) {
|
||||
throw new RuntimeException("Highlighted product '{$slug}' not found for Mutual SMEP.");
|
||||
}
|
||||
|
||||
DB::table('featured_items')->insert([
|
||||
'featured_group_id' => $featuredGroupId,
|
||||
'catalog_item_id' => $catalogItemId,
|
||||
'order' => $order + 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @param list<string> $images */
|
||||
private function attachImages(int $catalogItemId, ?int $variantId, array $images): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user