Optimising product category and category names

This commit is contained in:
Deon George
2022-06-12 11:21:20 +10:00
parent 360c1e46a1
commit cc94426902
36 changed files with 269 additions and 156 deletions

View File

@@ -15,6 +15,8 @@ final class Broadband extends Type implements ProductItem
protected $table = 'product_broadband';
protected const category_name = 'Broadband';
// Information required during the order process
protected array $order_attributes = [
'options.address'=>[

View File

@@ -12,6 +12,8 @@ final class Domain extends Type implements ProductItem
{
protected $table = 'product_domain';
protected const category_name = 'Domain Name';
// The model that is referenced when this product is ordered
protected string $order_model = ServiceDomain::class;
@@ -57,11 +59,6 @@ final class Domain extends Type implements ProductItem
return '';
}
public function getTypeAttribute()
{
return 'Domain Name';
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -12,6 +12,8 @@ final class Email extends Type implements ProductItem
{
protected $table = 'product_email';
protected const category_name = 'Email Hosting';
// The model that is referenced when this product is ordered
protected string $order_model = ServiceEmail::class;
@@ -57,11 +59,6 @@ final class Email extends Type implements ProductItem
return '';
}
public function getTypeAttribute()
{
return 'Domain Name';
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -12,6 +12,8 @@ final class Generic extends Type implements ProductItem
{
protected $table = 'product_generic';
protected const category_name = 'Generic';
// The model that is referenced when this product is ordered
protected string $order_model = ServiceGeneric::class;
@@ -34,11 +36,6 @@ final class Generic extends Type implements ProductItem
return 0;
}
public function getTypeAttribute()
{
return 'Generic';
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -12,6 +12,8 @@ final class Host extends Type implements ProductItem
{
protected $table = 'product_host';
protected const category_name = 'Web Hosting';
// The model that is referenced when this product is ordered
protected string $order_model = ServiceHost::class;
@@ -34,11 +36,6 @@ final class Host extends Type implements ProductItem
return 12;
}
public function getTypeAttribute()
{
return 'Hosting';
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -12,6 +12,8 @@ final class Phone extends Type implements ProductItem
{
protected $table = 'product_phone';
protected const category_name = 'Telephone';
protected array $order_attributes = [
'options.phonenumber'=>[
'request'=>'options.phonenumber',
@@ -62,11 +64,6 @@ final class Phone extends Type implements ProductItem
return 12;
}
public function getTypeAttribute()
{
return 'PHONE';
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -12,6 +12,8 @@ final class SSL extends Type implements ProductItem
{
protected $table = 'product_ssl';
protected const category_name = 'SSL Certificate';
// The model that is referenced when this product is ordered
protected string $order_model = ServiceSSL::class;
@@ -61,11 +63,6 @@ final class SSL extends Type implements ProductItem
return $o;
}
public function getTypeAttribute()
{
return 'SSL Certificate';
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -26,4 +26,25 @@ abstract class Type extends Model
{
return $this->morphOne(Product::class, null,'model','model_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
*/
final public function getCategoryAttribute(): string
{
return strtolower((new \ReflectionClass($this))->getShortName());
}
/**
* Return a friendly name for this product, used for display
*
* @return string
*/
final public function getCategoryNameAttribute(): string
{
return static::category_name;
}
}