feat: Implement order and invoice management, enhance addon features, and remove the 'Type' module.

This commit is contained in:
pbao9
2026-02-11 17:02:07 +07:00
parent 58a9aa685b
commit 556b2c02e6
47 changed files with 1367 additions and 497 deletions
+3 -6
View File
@@ -12,16 +12,13 @@ class Addon extends Model
protected $table = 'product_addon';
protected $fillable = [
'code',
'name',
'price',
'min',
'max',
'prefix',
'step',
'type_id'
'prefix',
'status'
];
public function type()
{
return $this->belongsTo(\App\Models\Type::class);
}
}
+18
View File
@@ -64,4 +64,22 @@ class Cart extends Model
{
return $this->belongsTo(ProductPricings::class, 'product_pricing_id');
}
/**
* Relationship: Cart has many addons
*/
public function addons()
{
return $this->hasMany(CartAddon::class, 'cart_id');
}
/**
* Get total price including addons
*/
public function getTotalPriceAttribute()
{
$basePrice = $this->price * $this->quantity;
$addonsPrice = $this->addons->sum('price');
return $basePrice + $addonsPrice;
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CartAddon extends Model
{
use HasFactory;
protected $table = 'cart_addons';
protected $fillable = [
'cart_id',
'addon_id',
'qty',
'price',
];
/**
* Relationship: CartAddon belongs to Cart
*/
public function cart()
{
return $this->belongsTo(Cart::class, 'cart_id');
}
/**
* Relationship: CartAddon belongs to Addon
*/
public function addon()
{
return $this->belongsTo(Addon::class, 'addon_id');
}
}
+11
View File
@@ -103,6 +103,17 @@ class Product extends Model
return $this->belongsToMany(ProductCategories::class, 'product_product_category', 'product_id', 'product_category_id');
}
/**
* Relationship: Product has many addons (through product type)
* Addons are linked via type_id in product_addon table
*/
public function addons()
{
// Assuming product_addon has type_id field that links to product type
return $this->hasMany(Addon::class, 'type_id', 'product_type')
->orderBy('sort_order');
}
/**
* Get monthly pricing (or first available pricing)
*/
-44
View File
@@ -1,44 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Type extends Model
{
use HasFactory;
protected $table = 'type';
protected $fillable = [
'name',
'status',
'icon'
];
public function invoiceItem()
{
return $this->belongsTo(\App\Models\InvoiceItem::class);
}
public function group()
{
return $this->hasMany(\App\Models\Group::class);
}
public function hosting()
{
return $this->hasMany(\App\Models\Hosting::class);
}
public function vps()
{
return $this->hasMany(\App\Models\VPS::class);
}
public function domain()
{
return $this->hasMany(\App\Models\Domain::class);
}
}