feat: refactor product attributes handling to use product_attribute table and update related models and requests

This commit is contained in:
2026-06-30 16:35:56 -03:00
parent 191a40fcb9
commit cb15905c46
15 changed files with 189 additions and 63 deletions

View File

@@ -10,6 +10,7 @@ use App\Domains\Catalog\Services\ProductService;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Database\Seeder;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use RuntimeException;
@@ -205,6 +206,10 @@ class ProductCatalogFromImagesSeeder extends Seeder
'attribute_ids' => array_values($attributeIds->all()),
]);
$productAttributeIds = DB::table('products_attributes')
->where('product_id', $product->id)
->pluck('id', 'attribute_id');
$sizes = $metadata['type'] === 'zapatillas'
? self::SHOE_SIZES
: self::CLOTHING_SIZES;
@@ -219,8 +224,14 @@ class ProductCatalogFromImagesSeeder extends Seeder
$definitions = [];
if (isset($attributeIds['color']) && $variantGroup['metadata']['color'] !== null) {
$colorProductAttributeId = $productAttributeIds[$attributeIds['color']] ?? null;
if ($colorProductAttributeId === null) {
throw new RuntimeException("Missing product attribute for color on product '{$metadata['product_slug']}'.");
}
$definitions[] = [
'attribute_id' => $attributeIds['color'],
'products_attribute_id' => $colorProductAttributeId,
'value' => $variantGroup['metadata']['color'],
];
}
@@ -229,8 +240,14 @@ class ProductCatalogFromImagesSeeder extends Seeder
? 'talle_numerico'
: 'talle';
$sizeProductAttributeId = $productAttributeIds[$attributeIds[$sizeAttributeCode]] ?? null;
if ($sizeProductAttributeId === null) {
throw new RuntimeException("Missing product attribute for size on product '{$metadata['product_slug']}'.");
}
$definitions[] = [
'attribute_id' => $attributeIds[$sizeAttributeCode],
'products_attribute_id' => $sizeProductAttributeId,
'value' => $size,
];