feat: Implement order and invoice management, enhance addon features, and remove the 'Type' module.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user