Rework on product name/description and translate

This commit is contained in:
Deon George
2022-10-18 23:23:45 +11:00
parent bfd17b0686
commit b719efb58c
15 changed files with 148 additions and 62 deletions

View File

@@ -31,9 +31,10 @@ use App\Traits\{ProductDetails,SiteID};
* + category_name : Type of product supplied (Friendly Name for display, not for internal logic)
* + supplied : Supplier product provided for this offering
* + supplier : Supplier for this offering
* + name : Brief Name for our product // @todo we should change this to be consistent with service
* + name_short : Product ID for our Product
* + name_long : Long Name for our product
* + name : Brief Name for our product with name_detail
* + name_short : Product ID for our Product (description.name => name_short)
* + name_detail : Details of our product (description.description_short => name_detail)
* + description : Product description (description.description_full => description_full)
* + billing_interval : Default Billing Interval
* + billing_interval_string: Default Billing Interval in human-readable form
* + setup_charge : Charge to setup this product
@@ -73,21 +74,10 @@ class Product extends Model implements IDs
'pricing'=>'collection',
];
protected $with = ['description'];
protected $with = ['translate'];
/* RELATIONS */
/**
* Get the product name in the users language, and if the user isnt logged in, the sites language
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function description()
{
return $this->hasOne(ProductTranslate::class)
->where('language_id',(Auth::user() && Auth::user()->language_id) ? Auth::user()->language_id : config('site')->language_id);
}
/**
* Which services are configured with this product
*
@@ -98,6 +88,17 @@ class Product extends Model implements IDs
return $this->hasMany(Service::class);
}
/**
* Get the product name in the users language, and if the user isnt logged in, the sites language
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function translate()
{
return $this->hasOne(ProductTranslate::class)
->where('language_id',(Auth::user() && Auth::user()->language_id) ? Auth::user()->language_id : config('site')->language_id);
}
/**
* Return a child model with details of the service
* This will return a product/* model.
@@ -211,6 +212,16 @@ class Product extends Model implements IDs
return $this->type->getContractTermAttribute();
}
/**
* This product full description
*
* @return string
*/
public function getDescriptionAttribute(): string
{
return (($x=$this->translate) && $x->description) ? $x->description : 'No Description';
}
/**
* Get the minimum cost of this product
*
@@ -243,7 +254,17 @@ class Product extends Model implements IDs
*/
public function getNameAttribute(): string
{
return $this->description ? $this->description->description_short : 'Unknown PRODUCT';
return $this->getNameShortAttribute().(($x=$this->getNameDetailAttribute()) ? ': '.$x : '');
}
/**
* Our products Long Name
*
* @return string
*/
public function getNameDetailAttribute(): string
{
return $this->translate ? $this->translate->name_detail : 'Unknown Name';
}
/**
@@ -253,23 +274,13 @@ class Product extends Model implements IDs
*/
public function getNameShortAttribute(): string
{
return $this->description ? $this->description->name : 'Unknown PID';
}
/**
* This product full description
*
* @return string
*/
public function getNameLongAttribute(): string
{
return $this->description->description_full;
return $this->translate ? $this->translate->name_short : 'Unknown PID';
}
/**
* Suppliers
*
* @return Model
* @return Model|null
*/
public function getSupplierAttribute(): ?Model
{
@@ -279,7 +290,7 @@ class Product extends Model implements IDs
/**
* Suppliers product
*
* @return Model
* @return Model|null
*/
public function getSuppliedAttribute(): ?Model
{