osb/app/Models/Product/Type.php

71 lines
1.8 KiB
PHP

<?php
namespace App\Models\Product;
use Illuminate\Database\Eloquent\Model;
use App\Models\Product;
use App\Traits\{OrderServiceOptions,SiteID};
/**
* @todo These tables have a base_cost/setup_cost/contract_term columns - how is that different to the supplier_tables?
* @todo Ensure our terminology is consistent - we have a "cost", we "charge" clients, and we have a "price" which is not official charges nor a cost.
*/
abstract class Type extends Model
{
use SiteID,OrderServiceOptions;
/* RELATIONS */
/**
* The product that sells this type
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
final public function products()
{
return $this->morphMany(Product::class, null,'model','model_id');
}
/**
* The offering supplied with this product
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
final public function supplied()
{
return $this->hasOne(static::SupplierModel,'id','supplier_item_id');
}
/**
* This will return the category of the product (eg: domain, hosting, etc) which is the basis for all
* other logic of these types.
*
* @return string
* @deprecated - can this be replaced with product->supplied->category?
*/
final public function getCategoryAttribute(): string
{
abort(500,'use product->supplied->category_name');
return strtolower((new \ReflectionClass($this))->getShortName());
}
/**
* Return a friendly name for this product, used for display
*
* @return string
* @deprecated - can this be replaced with product->supplied->category_name
*/
final public function getCategoryNameAttribute(): string
{
abort(500,'use product->supplied->category_name');
return static::category_name;
}
/* METHODs */
final function normalizeBillingInterval(): int
{
return static::DefaultBill;
}
}