✅ Yapılacak Değişiklikler Özeti
- EKLE
price_without_tax → fillable array'e
- EKLE
price_without_tax → casts array'e (decimal:2)
- EKLE
getPriceWithTaxAttribute() → Yeni accessor metod
- EKLE
getTaxAmountAttribute() → Yeni accessor metod
- TUT Tüm mevcut alanlar ve metodlar korunacak
❌ HİÇBİR ŞEY SİLİNMEYECEK!
Mevcut base_price, tax_rate, accessor'lar aynen kalacak.
Sadece YENİ alanlar ve metodlar EKLENİYOR.
1️⃣ Fillable Array - Tek Satır Ekleme
❌ ŞİMDİ (Line 47-52)
'price_display_mode',
'base_price',
'tax_rate',
'compare_at_price',
'cost_price',
✅ SONRA (Line 47-53)
'price_display_mode',
'base_price',
'price_without_tax', // ← YENİ!
'tax_rate',
'compare_at_price',
'cost_price',
📍 Neden Eklenecek?
Database'de price_without_tax alanı olacak. Model üzerinden set edilebilmesi için fillable'da olmalı.
2️⃣ Casts Array - Tek Satır Ekleme
❌ ŞİMDİ (Line 105-108)
'base_price' => 'decimal:2',
'tax_rate' => 'decimal:2',
'compare_at_price' => 'decimal:2',
'cost_price' => 'decimal:2',
✅ SONRA (Line 105-109)
'base_price' => 'decimal:2',
'price_without_tax' => 'decimal:2', // ← YENİ!
'tax_rate' => 'decimal:2',
'compare_at_price' => 'decimal:2',
'cost_price' => 'decimal:2',
📍 Neden Eklenecek?
Database'den gelen değer string, Laravel otomatik float'a çevirecek (2 decimal basamak).
3️⃣ Accessor Metodları - İki Yeni Metod Ekle
❌ ŞİMDİ (Line 1321-1324)
public function getFinalPriceAttribute(): float
{
return (float) ($this->base_price ?? 0.0);
}
protected static function newFactory()
Mevcut accessor'lar aynen kalacak!
✅ SONRA (Line 1321-1350)
public function getFinalPriceAttribute(): float
{
return (float) ($this->base_price ?? 0.0);
}
/**
* KDV dahil fiyat (Runtime calculation)
*/
public function getPriceWithTaxAttribute(): float
{
if (!$this->price_without_tax) {
return 0.0;
}
$taxRate = $this->tax_rate ?? 20.0;
return (float) ($this->price_without_tax * (1 + $taxRate / 100));
}
/**
* KDV tutarı hesaplama
*/
public function getTaxAmountAttribute(): float
{
return $this->price_with_tax - ($this->price_without_tax ?? 0.0);
}
protected static function newFactory()
📍 Accessor'lar Ne İşe Yarar?
getPriceWithTaxAttribute():
- Database'de olmayan bir alan gibi çalışır
$product->price_with_tax dediğinde runtime'da hesaplanır
- Formül:
price_without_tax × (1 + tax_rate / 100)
getTaxAmountAttribute():
$product->tax_amount dediğinde KDV tutarını döner
- Formül:
price_with_tax - price_without_tax
4️⃣ Kullanım Örneği
❌ ŞİMDİ
$product = ShopProduct::find(1);
// Sadece base_price var
echo $product->base_price; // 1000.00
echo $product->tax_rate; // 20.00
// KDV dahil fiyat YOK!
// Manuel hesaplaman gerekir:
$withTax = $product->base_price * 1.20;
✅ SONRA
$product = ShopProduct::find(1);
// Database'den gelir:
echo $product->price_without_tax; // 1000.00
echo $product->tax_rate; // 20.00
// Accessor'dan gelir (hesaplanır):
echo $product->price_with_tax; // 1200.00
echo $product->tax_amount; // 200.00
// Blade'de:
{{ number_format($product->price_with_tax, 2) }} ₺
5️⃣ Korunacak Alanlar ve Metodlar
🛡️ BUNLAR HİÇ DEĞİŞMEYECEK!
base_price → Fillable ve casts'ta kalacak
tax_rate → Fillable ve casts'ta kalacak
compare_at_price → Aynen kalacak
cost_price → Aynen kalacak
getDiscountPercentageAttribute() → Aynen kalacak
getHasDiscountAttribute() → Aynen kalacak
getFinalPriceAttribute() → Aynen kalacak
- TÜM DİĞER ALANLAR VE METODLAR → Aynen kalacak
6️⃣ Değişiklik Özeti
| Değişiklik |
Nerede |
Ne Yapılacak |
Tip |
price_without_tax |
fillable (line 48) |
Tek satır eklenecek |
EKLE |
price_without_tax |
casts (line 107) |
Tek satır eklenecek |
EKLE |
getPriceWithTaxAttribute() |
accessor (line ~1327) |
11 satır eklenecek |
EKLE |
getTaxAmountAttribute() |
accessor (line ~1340) |
7 satır eklenecek |
EKLE |
📊 Toplam Değişiklik
- Eklenen satır: ~21 satır
- Silinen satır: 0 satır
- Değiştirilen satır: 0 satır
- Risk seviyesi: Çok Düşük (sadece ekleme yapılıyor)