Move some product product\supplier and product\type::class methods into __get(), no functional changes

This commit is contained in:
2025-05-22 18:17:27 +10:00
parent 72b11172c8
commit 251aefa947
11 changed files with 46 additions and 77 deletions

View File

@@ -5,12 +5,11 @@ namespace App\Models\Product;
use Illuminate\Support\Collection;
use Leenooks\Traits\ScopeActive;
use App\Interfaces\ProductItem;
use App\Models\Invoice;
use App\Models\Service\Broadband as ServiceBroadband;
use App\Models\Supplier\Broadband as SupplierBroadband;
final class Broadband extends Type implements ProductItem
final class Broadband extends Type
{
use ScopeActive;

View File

@@ -4,12 +4,11 @@ namespace App\Models\Product;
use Illuminate\Support\Collection;
use App\Interfaces\ProductItem;
use App\Models\Invoice;
use App\Models\Service\Domain as ServiceDomain;
use App\Models\Supplier\Domain as SupplierDomain;
final class Domain extends Type implements ProductItem
final class Domain extends Type
{
protected $table = 'product_domain';

View File

@@ -4,12 +4,11 @@ namespace App\Models\Product;
use Illuminate\Support\Collection;
use App\Interfaces\ProductItem;
use App\Models\Invoice;
use App\Models\Service\Email as ServiceEmail;
use App\Models\Supplier\Email as SupplierEmail;
final class Email extends Type implements ProductItem
final class Email extends Type
{
protected $table = 'product_email';

View File

@@ -4,12 +4,11 @@ namespace App\Models\Product;
use Illuminate\Support\Collection;
use App\Interfaces\ProductItem;
use App\Models\Invoice;
use App\Models\Service\Generic as ServiceGeneric;
use App\Models\Supplier\Generic as SupplierGeneric;
final class Generic extends Type implements ProductItem
final class Generic extends Type
{
protected $table = 'product_generic';

View File

@@ -4,12 +4,11 @@ namespace App\Models\Product;
use Illuminate\Support\Collection;
use App\Interfaces\ProductItem;
use App\Models\Invoice;
use App\Models\Service\Host as ServiceHost;
use App\Models\Supplier\Host as SupplierHost;
final class Host extends Type implements ProductItem
final class Host extends Type
{
protected $table = 'product_host';

View File

@@ -4,12 +4,11 @@ namespace App\Models\Product;
use Illuminate\Support\Collection;
use App\Interfaces\ProductItem;
use App\Models\Invoice;
use App\Models\Service\Phone as ServicePhone;
use App\Models\Supplier\Phone as SupplierPhone;
final class Phone extends Type implements ProductItem
final class Phone extends Type
{
protected $table = 'product_phone';

View File

@@ -4,12 +4,11 @@ namespace App\Models\Product;
use Illuminate\Support\Collection;
use App\Interfaces\ProductItem;
use App\Models\Invoice;
use App\Models\Service\SSL as ServiceSSL;
use App\Models\Supplier\SSL as SupplierSSL;
final class SSL extends Type implements ProductItem
final class SSL extends Type
{
protected $table = 'product_ssl';

View File

@@ -3,15 +3,31 @@
namespace App\Models\Product;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use App\Interfaces\ProductItem;
use App\Models\Product;
use App\Traits\{OrderServiceOptions,ProductDetails,SiteID};
use App\Traits\{OrderServiceOptions,SiteID};
abstract class Type extends Model
/**
* Class Supplier\Type
*
* Attributes for supplier types:
* + billing_interval : The Billing interval that the supplier normally uses for this offering
*/
abstract class Type extends Model implements ProductItem
{
use SiteID,OrderServiceOptions;
public function __get($key): mixed
{
return match ($key) {
'billing_interval' => static::DefaultBill,
default => parent::__get($key),
};
}
/* RELATIONS */
/**
@@ -36,24 +52,15 @@ abstract class Type extends Model
/* ATTRIBUTES */
/**
* The Billing interval that the supplier normally uses for this offering
*
* @return int
*/
public function getBillingIntervalAttribute(): int
{
return static::DefaultBill;
}
/**
* The product contract term is the highest of our defined contract_term (in Products/*) vs the suppliers
* contract term (defined in Supplier/*).
*
* @param int $val
* @return int
*/
public function getContractTermAttribute(): int
public function getContractTermAttribute(int $val): int
{
return max(Arr::get($this->attributes,'contract_term',0),$this->supplied->contract_term);
return max($val,$this->supplied->contract_term);
}
}