BAŞLANGIÇ: Admin "Generate AI Content" butonuna tıklar
1. ÜRÜN FİLTRELEME
$product = ShopProduct::find($productId);
// Kontrol 1: Yedek parça mı?
if ($product->category_id != 7 && $product->category->parent_id != 7) {
throw new Exception('Bu ürün yedek parça kategorisinde değil');
}
// Kontrol 2: Variant ürün mü?
if ($product->parent_product_id && $product->parent_product_id > 0) {
throw new Exception('Variant ürünler işlenmez, sadece ana ürünler');
}
2. MEVCUT İÇERİK KONTROLÜ (KRİTİK!)
$existingBody = $product->body['tr'] ?? '';
$hasContent = strlen($existingBody) > 100;
if ($hasContent) {
// BRANCH A → Genişlet
$strategy = 'expand';
} else {
// BRANCH B → Yeni oluştur
$strategy = 'create';
}
🟢 BRANCH A - Mevcut İçerik Varsa
A1. Mevcut veriyi parse et
$existingData = [
'body' => $product->body,
'primary_specs' => $product->primary_specs,
'faq_data' => $product->faq_data,
];
// Teknik detayları çıkar (regex ile)
// "150mm", "2.5 kg", "220V", "Döküm Çelik" gibi
A2. GPT-4 Prompt (Genişletme)
$prompt = "IMPROVE and EXPAND this existing product content for a forklift spare part.
PRODUCT: {$product->title['tr']}
CATEGORY: Yedek Parça
EXISTING CONTENT:
{$existingBody}
EXISTING SPECS:
{$extractedSpecs}
RULES:
✅ KEEP all technical details (dimensions, materials, compatibility)
✅ EXPAND descriptions with more context
✅ ADD SEO keywords (forklift, yedek parça, onarım, servis, montaj)
✅ Use Pattern v4 HTML structure
❌ NEVER mention price
✅ Bilingual output: TR + EN
OUTPUT FORMAT (JSON):
{
\"title\": {\"tr\": \"...\", \"en\": \"...\"},
\"short_description\": {\"tr\": \"...\", \"en\": \"...\"},
\"primary_specs\": [
{\"label\": \"Malzeme\", \"value\": \"Döküm Çelik\"},
{\"label\": \"Uyumluluk\", \"value\": \"Forklift Arka Dingil\"}
],
\"body\": {
\"tr\": \"\",
\"en\": \"\"
},
\"faq_data\": [
{\"question\": \"...\", \"answer\": \"...\"}
],
\"tags\": [\"forklift\", \"yedek parça\", \"akson kapağı\"]
}"
A3. Leonardo AI Görseller (2 adet)
// Foto 1: Kullanım ortamı
$prompt1 = "Industrial workshop scene, forklift spare part installation,
mechanic hands assembling parts, professional lighting, realistic photo";
// Foto 2: Teknik çizim (blueprint)
$prompt2 = "Technical blueprint drawing, forklift axle component diagram,
engineering schematic, white background, clean lines";
// Her ikisi de: 1024x1024, cinematic style
🔴 BRANCH B - Mevcut İçerik Yoksa
B1. Sadece başlık + kategori al
$basicInfo = [
'title' => $product->title,
'category' => $product->category->title,
];
// Başka BİLGİ YOK! Teknik detay yok!
B2. GPT-4 Prompt (Güvenli Mod)
$prompt = "CREATE GENERAL product description for a forklift spare part.
PRODUCT: {$product->title['tr']}
CATEGORY: Yedek Parça
⚠️ CRITICAL RULES:
❌ NO specific dimensions/weight/voltage
❌ NO price information
❌ NO exact technical specifications
✅ Use general phrases: 'Detaylar için arayın', 'Forklift modelinize uyumlu', 'Profesyonel montaj önerilir'
✅ Focus on: quality, reliability, OEM standards
✅ SEO keywords (forklift, yedek parça, onarım)
✅ Pattern v4 HTML structure
✅ Bilingual: TR + EN
OUTPUT FORMAT (same JSON as Branch A, but with general content)"
B3. Leonardo AI Görseller (2 adet)
// Aynı strateji (context görseller, exact product değil)
3. VALIDATION (Her iki branch için)
// Fiyat kontrolü
if (preg_match('/\d+\s*(TL|USD|\$|€|lira|dolar)/i', $content)) {
throw new Exception('Content contains price!');
}
// Branch B için teknik detay kontrolü
if ($strategy === 'create') {
if (preg_match('/\d+\s*(mm|cm|kg|volt|V|A)/i', $content)) {
throw new Exception('New content should not have technical specs!');
}
}
4. GÖRSELLER EMBED + SEO
// Görselleri body içine embed et
$imageTag = "<a href='{$imageUrl}' class='glightbox'>
<img src='{$imageUrl}'
alt='Forklift {$product->title['tr']} Yedek Parça Montaj Görseli'
title='{$product->title['tr']} - OEM Kalite Forklift Yedek Parça'
loading='lazy'
class='w-full aspect-square rounded-xl object-cover'>
</a>";
5. DATABASE SAVE
$product->update([
'title' => $aiContent['title'],
'short_description' => $aiContent['short_description'],
'body' => $aiContent['body'],
'primary_specs' => $aiContent['primary_specs'],
'faq_data' => $aiContent['faq_data'],
'tags' => $aiContent['tags'],
]);
// Cache clear
Artisan::call('view:clear');
Artisan::call('responsecache:clear');