More Service display

This commit is contained in:
Deon George
2019-07-02 15:28:27 +10:00
parent 6103b61265
commit 59a8ef2476
14 changed files with 311 additions and 14 deletions

View File

@@ -3,14 +3,26 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use App\Traits\NextKey;
class Product extends Model
{
use NextKey;
const RECORD_ID = 'product';
protected $table = 'ab_product';
protected $with = ['descriptions'];
const CREATED_AT = 'date_orig';
const UPDATED_AT = 'date_last';
public $incrementing = FALSE;
public $dateFormat = 'U';
public function descriptions()
{
return $this->hasMany(ProductTranslate::class);
@@ -21,6 +33,16 @@ class Product extends Model
return $this->hasMany(Service::class);
}
/**
* Return a child model with details of the service
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function type()
{
return $this->morphTo(null,'model','prod_plugin_data');
}
/**
* Get the service category (from the product)
*
@@ -91,6 +113,14 @@ class Product extends Model
return $this->descriptions->where('language_id',$lo->id)->first()->description_short;
}
public function getNameShortAttribute(Language $lo=NULL)
{
if (is_null($lo))
$lo = $this->getDefaultLanguage();
return $this->descriptions->where('language_id',$lo->id)->first()->name;
}
public function getProductTypeAttribute()
{
return $this->plugin()->product->name;
@@ -149,6 +179,11 @@ class Product extends Model
}
}
public function price(int $period)
{
return Arr::get($this->price_array,sprintf('%s.1.price_base',$period));
}
public function PricePeriods()
{
return [