feat: refactor cart and bundle handling to support Buyable interface for improved flexibility
This commit is contained in:
@@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
use App\Domains\Shared\Contracts\Stockable;
|
||||
use App\Domains\Shared\Contracts\Buyable;
|
||||
|
||||
#[Fillable([
|
||||
'producto_id',
|
||||
@@ -24,7 +24,7 @@ use App\Domains\Shared\Contracts\Stockable;
|
||||
'minimum_use_date',
|
||||
'maximum_use_date',
|
||||
])]
|
||||
class ProductVariant extends Model implements Stockable
|
||||
class ProductVariant extends Model implements Buyable
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
@@ -54,6 +54,28 @@ class ProductVariant extends Model implements Stockable
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrice(): float
|
||||
{
|
||||
return (float) ($this->product->precio ?? 0.0);
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
$name = $this->product->nombre ?? 'Producto';
|
||||
|
||||
if ($this->relationLoaded('definitions') && $this->definitions->isNotEmpty()) {
|
||||
$definitions = $this->definitions->map(function ($def) {
|
||||
return $def->value ?? $def->productAttribute?->attribute?->nombre;
|
||||
})->filter()->implode(', ');
|
||||
|
||||
if ($definitions !== '') {
|
||||
$name .= " ({$definitions})";
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function incrementRealStock(int $amount): void
|
||||
{
|
||||
if ($amount < 0) {
|
||||
|
||||
Reference in New Issue
Block a user