osb/app/Models/Product/Type.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2022-02-01 05:40:46 +00:00
<?php
namespace App\Models\Product;
use Illuminate\Database\Eloquent\Model;
2023-05-05 05:48:24 +00:00
use Illuminate\Support\Arr;
2022-02-01 05:40:46 +00:00
use App\Models\Product;
2023-05-05 12:05:42 +00:00
use App\Traits\{OrderServiceOptions,ProductDetails,SiteID};
2022-02-01 05:40:46 +00:00
abstract class Type extends Model
{
2023-05-05 12:05:42 +00:00
use SiteID,ProductDetails,OrderServiceOptions;
2022-02-01 05:40:46 +00:00
/* RELATIONS */
/**
* The product that sells this type
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
2022-02-01 05:40:46 +00:00
*/
final public function products()
2022-02-01 05:40:46 +00:00
{
return $this->morphMany(Product::class, null,'model','model_id');
2022-02-01 05:40:46 +00:00
}
2023-05-04 00:02:25 +00:00
/**
* The offering supplied with this product
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
final public function supplied()
2023-05-04 00:02:25 +00:00
{
return $this->hasOne(static::SupplierModel,'id','supplier_item_id');
}
2023-05-05 05:48:24 +00:00
/* ATTRIBUTES */
2023-05-05 12:05:42 +00:00
/**
* The Billing interval that the supplier normally uses for this offering
*
* @return int
*/
public function getBillingIntervalAttribute(): int
{
return static::DefaultBill;
}
2023-05-05 05:48:24 +00:00
/**
* The product contract term is the highest of our defined contract_term (in Products/*) vs the suppliers
* contract term (defined in Supplier/*).
*
* @return int
*/
public function getContractTermAttribute(): int
{
return max(Arr::get($this->attributes,'contract_term',0),$this->supplied->contract_term);
}
2022-02-01 05:40:46 +00:00
}