Product class optimisation
This commit is contained in:
parent
a5238bfbdc
commit
0ac35c3d43
@ -6,10 +6,6 @@ use Illuminate\Support\Collection;
|
|||||||
|
|
||||||
interface ProductItem
|
interface ProductItem
|
||||||
{
|
{
|
||||||
public function products();
|
|
||||||
|
|
||||||
public function supplied();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the traffic inclusion with the service
|
* Return the traffic inclusion with the service
|
||||||
*
|
*
|
||||||
|
@ -96,7 +96,9 @@ class Product extends Model implements IDs
|
|||||||
public function translate()
|
public function translate()
|
||||||
{
|
{
|
||||||
return $this->hasOne(ProductTranslate::class)
|
return $this->hasOne(ProductTranslate::class)
|
||||||
->where('language_id',(Auth::user() && Auth::user()->language_id) ? Auth::user()->language_id : config('site')->language_id);
|
->where('language_id',(Auth::user() && Auth::user()->language_id)
|
||||||
|
? Auth::user()->language_id
|
||||||
|
: config('site')->language_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -290,11 +292,12 @@ class Product extends Model implements IDs
|
|||||||
/**
|
/**
|
||||||
* Suppliers product
|
* Suppliers product
|
||||||
*
|
*
|
||||||
* @return Model|null
|
* @return Model
|
||||||
|
* @todo make internal as other values off this attribute are used, not the model itself
|
||||||
*/
|
*/
|
||||||
public function getSuppliedAttribute(): ?Model
|
public function getSuppliedAttribute(): Model
|
||||||
{
|
{
|
||||||
return $this->type->supplied ? $this->type->supplied : NULL;
|
return $this->type->supplied;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,17 +34,8 @@ final class Broadband extends Type implements ProductItem
|
|||||||
// The model that is referenced when this product is ordered
|
// The model that is referenced when this product is ordered
|
||||||
protected string $order_model = ServiceBroadband::class;
|
protected string $order_model = ServiceBroadband::class;
|
||||||
|
|
||||||
/* RELATIONS */
|
// The model that the supplier supplies
|
||||||
|
const SupplierModel = SupplierBroadband::class;
|
||||||
/**
|
|
||||||
* The offering supplied with this product
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
||||||
*/
|
|
||||||
public function supplied()
|
|
||||||
{
|
|
||||||
return $this->hasOne(SupplierBroadband::class,'id','supplier_item_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* INTERFACES */
|
/* INTERFACES */
|
||||||
|
|
||||||
|
@ -31,17 +31,8 @@ final class Domain extends Type implements ProductItem
|
|||||||
// The model that is referenced when this product is ordered
|
// The model that is referenced when this product is ordered
|
||||||
protected string $order_model = ServiceDomain::class;
|
protected string $order_model = ServiceDomain::class;
|
||||||
|
|
||||||
/* RELATIONS */
|
// The model that the supplier supplies
|
||||||
|
const SupplierModel = SupplierDomain::class;
|
||||||
/**
|
|
||||||
* The offering supplied with this product
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
||||||
*/
|
|
||||||
public function supplied()
|
|
||||||
{
|
|
||||||
return $this->hasOne(SupplierDomain::class,'id','supplier_item_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* INTERFACES */
|
/* INTERFACES */
|
||||||
|
|
||||||
|
@ -15,17 +15,8 @@ final class Email extends Type implements ProductItem
|
|||||||
// The model that is referenced when this product is ordered
|
// The model that is referenced when this product is ordered
|
||||||
protected string $order_model = ServiceEmail::class;
|
protected string $order_model = ServiceEmail::class;
|
||||||
|
|
||||||
/* RELATIONS */
|
// The model that the supplier supplies
|
||||||
|
const SupplierModel = SupplierEmail::class;
|
||||||
/**
|
|
||||||
* The offering supplied with this product
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
||||||
*/
|
|
||||||
public function supplied()
|
|
||||||
{
|
|
||||||
return $this->hasOne(SupplierEmail::class,'id','supplier_item_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* INTERFACES */
|
/* INTERFACES */
|
||||||
|
|
||||||
|
@ -15,17 +15,8 @@ final class Generic extends Type implements ProductItem
|
|||||||
// The model that is referenced when this product is ordered
|
// The model that is referenced when this product is ordered
|
||||||
protected string $order_model = ServiceGeneric::class;
|
protected string $order_model = ServiceGeneric::class;
|
||||||
|
|
||||||
/* RELATIONS */
|
// The model that the supplier supplies
|
||||||
|
const SupplierModel = SupplierGeneric::class;
|
||||||
/**
|
|
||||||
* The offering supplied with this product
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
||||||
*/
|
|
||||||
public function supplied()
|
|
||||||
{
|
|
||||||
return $this->hasOne(SupplierGeneric::class,'id','supplier_item_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* INTERFACES */
|
/* INTERFACES */
|
||||||
|
|
||||||
|
@ -15,17 +15,8 @@ final class Host extends Type implements ProductItem
|
|||||||
// The model that is referenced when this product is ordered
|
// The model that is referenced when this product is ordered
|
||||||
protected string $order_model = ServiceHost::class;
|
protected string $order_model = ServiceHost::class;
|
||||||
|
|
||||||
/* RELATIONS */
|
// The model that the supplier supplies
|
||||||
|
const SupplierModel = SupplierHost::class;
|
||||||
/**
|
|
||||||
* The offering supplied with this product
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
||||||
*/
|
|
||||||
public function supplied()
|
|
||||||
{
|
|
||||||
return $this->hasOne(SupplierHost::class,'id','supplier_item_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* INTERFACES */
|
/* INTERFACES */
|
||||||
|
|
||||||
|
@ -42,17 +42,8 @@ final class Phone extends Type implements ProductItem
|
|||||||
// The model that is referenced when this product is ordered
|
// The model that is referenced when this product is ordered
|
||||||
protected string $order_model = ServicePhone::class;
|
protected string $order_model = ServicePhone::class;
|
||||||
|
|
||||||
/* RELATIONS */
|
// The model that the supplier supplies
|
||||||
|
const SupplierModel = SupplierPhone::class;
|
||||||
/**
|
|
||||||
* The offering supplied with this product
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
||||||
*/
|
|
||||||
public function supplied()
|
|
||||||
{
|
|
||||||
return $this->hasOne(SupplierPhone::class,'id','supplier_item_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* INTERFACES */
|
/* INTERFACES */
|
||||||
|
|
||||||
|
@ -15,17 +15,8 @@ final class SSL extends Type implements ProductItem
|
|||||||
// The model that is referenced when this product is ordered
|
// The model that is referenced when this product is ordered
|
||||||
protected string $order_model = ServiceSSL::class;
|
protected string $order_model = ServiceSSL::class;
|
||||||
|
|
||||||
/* RELATIONS */
|
// The model that the supplier supplies
|
||||||
|
const SupplierModel = SupplierSSL::class;
|
||||||
/**
|
|
||||||
* The offering supplied with this product
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
||||||
*/
|
|
||||||
public function supplied()
|
|
||||||
{
|
|
||||||
return $this->hasOne(SupplierSSL::class,'id','supplier_item_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* INTERFACES */
|
/* INTERFACES */
|
||||||
|
|
||||||
|
@ -27,6 +27,16 @@ abstract class Type extends Model
|
|||||||
return $this->morphMany(Product::class, null,'model','model_id');
|
return $this->morphMany(Product::class, null,'model','model_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The offering supplied with this product
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||||
|
*/
|
||||||
|
public function supplied()
|
||||||
|
{
|
||||||
|
return $this->hasOne(static::SupplierModel,'id','supplier_item_id');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will return the category of the product (eg: domain, hosting, etc) which is the basis for all
|
* This will return the category of the product (eg: domain, hosting, etc) which is the basis for all
|
||||||
* other logic of these types.
|
* other logic of these types.
|
||||||
|
Loading…
Reference in New Issue
Block a user