Optimising product category and category names
This commit is contained in:
@@ -26,6 +26,8 @@ use App\Traits\{ProductDetails,SiteID};
|
||||
* Attributes for products:
|
||||
* + lid : Local ID for product (part number)
|
||||
* + sid : System ID for product (part number)
|
||||
* + category : Type of product supplied
|
||||
* + 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
|
||||
@@ -97,6 +99,7 @@ class Product extends Model implements IDs
|
||||
|
||||
/**
|
||||
* Return a child model with details of the service
|
||||
* This will return a product/* model.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
||||
*/
|
||||
@@ -176,6 +179,29 @@ class Product extends Model implements IDs
|
||||
return max($this->price_recur_default,$this->getSuppliedAttribute()->getBillingIntervalAttribute());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of service is provided. eg: Broadband, Phone.
|
||||
*
|
||||
* @return string
|
||||
* @todo Does type need to be a mandatory attribute on a model - then we can remove this condition
|
||||
*/
|
||||
public function getCategoryAttribute(): string
|
||||
{
|
||||
return $this->type ? $this->type->getCategoryAttribute() : 'generic';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @todo Does type need to be a mandatory attribute on a model - then we can remove this condition
|
||||
*/
|
||||
public function getCategoryNameAttribute(): string
|
||||
{
|
||||
return $this->type ? $this->type->getCategoryNameAttribute() : 'Generic';
|
||||
}
|
||||
|
||||
/**
|
||||
* How long must this product be purchased for as a service.
|
||||
*
|
||||
@@ -241,17 +267,6 @@ class Product extends Model implements IDs
|
||||
return $this->description->description_full;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get our product type
|
||||
*
|
||||
* @return string
|
||||
* @todo is the test of type and type->supplied necessary? (It seems some hosting entries have no type, are they old?)
|
||||
*/
|
||||
public function getProductTypeAttribute(): string
|
||||
{
|
||||
return ($this->type && $this->type->supplied) ? $this->getSuppliedAttribute()->getTypeAttribute() : 'Unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppliers
|
||||
*
|
||||
|
Reference in New Issue
Block a user