2018-05-20 12:53:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2018-08-09 14:10:51 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2018-05-20 12:53:14 +00:00
|
|
|
|
|
|
|
class Product extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'ab_product';
|
|
|
|
protected $with = ['descriptions'];
|
|
|
|
|
|
|
|
public function descriptions()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ProductTranslate::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function services()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Service::class);
|
|
|
|
}
|
|
|
|
|
2018-08-09 14:10:51 +00:00
|
|
|
public function getCategoryAttribute()
|
|
|
|
{
|
|
|
|
return $this->prod_plugin_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescriptionAttribute()
|
|
|
|
{
|
|
|
|
// @todo If the user has selected a specific language.
|
|
|
|
return $this->description($this->getDefaultLanguage());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNameAttribute()
|
|
|
|
{
|
|
|
|
return $this->name(Auth::user()->language);
|
|
|
|
}
|
|
|
|
|
2018-08-01 07:09:38 +00:00
|
|
|
public function getProductIdAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('#%04s',$this->id);
|
|
|
|
}
|
|
|
|
|
2018-08-09 14:10:51 +00:00
|
|
|
public function scopeActive()
|
|
|
|
{
|
|
|
|
return $this->where('active',TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function description(Language $lo=NULL)
|
|
|
|
{
|
|
|
|
if (is_null($lo))
|
|
|
|
$lo = $this->getDefaultLanguage();
|
|
|
|
|
|
|
|
return $this->descriptions->where('language_id',$lo->id)->first()->description_short;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getDefaultLanguage()
|
|
|
|
{
|
|
|
|
return config('SITE_SETUP')->language;
|
|
|
|
}
|
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
/**
|
2018-08-09 14:10:51 +00:00
|
|
|
* Get the product name
|
2018-05-20 12:53:14 +00:00
|
|
|
*
|
|
|
|
* @param Language $lo
|
2018-08-01 07:09:38 +00:00
|
|
|
* @return string Product Name
|
2018-05-20 12:53:14 +00:00
|
|
|
*/
|
2018-08-09 14:10:51 +00:00
|
|
|
public function name(Language $lo=NULL)
|
2018-05-20 12:53:14 +00:00
|
|
|
{
|
2018-08-09 14:10:51 +00:00
|
|
|
if (is_null($lo))
|
|
|
|
$lo = $this->getDefaultLanguage();
|
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
return $this->descriptions->where('language_id',$lo->id)->first()->name;
|
|
|
|
}
|
|
|
|
}
|