feat: implement Bundle and BundleItem models, migrations, and polymorphic relationships for cart and purchase items

This commit is contained in:
2026-07-14 16:02:26 -03:00
parent 18c80b075b
commit 1d56d27350
8 changed files with 323 additions and 10 deletions

View File

@@ -10,7 +10,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
#[Fillable([
'compra_id',
'producto_variante_id',
'buyable_id',
'buyable_type',
'cantidad',
'precio_unitario',
'discount_total',
@@ -27,7 +28,8 @@ class PurchaseItem extends Model
{
return [
'compra_id' => 'integer',
'producto_variante_id' => 'integer',
'buyable_id' => 'integer',
'buyable_type' => 'string',
'cantidad' => 'integer',
'precio_unitario' => 'decimal:2',
'discount_total' => 'decimal:2',
@@ -45,10 +47,10 @@ class PurchaseItem extends Model
}
/**
* @return BelongsTo<ProductVariant, $this>
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function variant(): BelongsTo
public function buyable()
{
return $this->belongsTo(ProductVariant::class, 'producto_variante_id');
return $this->morphTo();
}
}