Changeset View
Changeset View
Standalone View
Standalone View
src/app/Plan.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
use Spatie\Translatable\HasTranslations; | |||||
/** | /** | ||||
* The eloquent definition of a Plan. | * The eloquent definition of a Plan. | ||||
* | * | ||||
* A Plan is a grouping of packages, such as a "Family Plan". | * A Plan is a grouping of packages, such as a "Family Plan". | ||||
* | * | ||||
* A "Family Plan" as such may exist of "2 or more Kolab packages", | * A "Family Plan" as such may exist of "2 or more Kolab packages", | ||||
* and apply a discount for the third and further Kolab packages. | * and apply a discount for the third and further Kolab packages. | ||||
* | |||||
* @property \App\Package[] $packages | |||||
*/ | */ | ||||
class Plan extends Model | class Plan extends Model | ||||
{ | { | ||||
use \Spatie\Translatable\HasTranslations; | use HasTranslations; | ||||
public $incrementing = false; | public $incrementing = false; | ||||
protected $keyType = 'string'; | protected $keyType = 'string'; | ||||
public $timestamps = false; | public $timestamps = false; | ||||
protected $fillable = [ | protected $fillable = [ | ||||
'title', | 'title', | ||||
'name', | 'name', | ||||
Show All 27 Lines | public function cost() | ||||
foreach ($this->packages as $package) { | foreach ($this->packages as $package) { | ||||
$costs += $package->pivot->cost(); | $costs += $package->pivot->cost(); | ||||
} | } | ||||
return $costs; | return $costs; | ||||
} | } | ||||
/** | |||||
* The relationship to packages. | |||||
* | |||||
* The plan contains one or more packages. Each package may have its minimum number (for | |||||
* billing) or its maximum (to allow topping out "enterprise" customers on a "small business" | |||||
* plan). | |||||
* | |||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | |||||
*/ | |||||
public function packages() | public function packages() | ||||
{ | { | ||||
return $this->belongsToMany( | return $this->belongsToMany( | ||||
'App\Package', | 'App\Package', | ||||
'plan_packages' | 'plan_packages' | ||||
)->using('App\PlanPackage')->withPivot( | )->using('App\PlanPackage')->withPivot( | ||||
[ | [ | ||||
'qty', | |||||
'qty_min', | 'qty_min', | ||||
'qty_max', | 'qty_max', | ||||
'discount_qty', | 'discount_qty', | ||||
'discount_rate' | 'discount_rate' | ||||
] | ] | ||||
); | ); | ||||
} | } | ||||
/** | /** | ||||
* Checks if the plan has domain SKU assigned | * Checks if the plan has any type of domain SKU assigned. | ||||
* | |||||
* @return bool | |||||
*/ | */ | ||||
public function hasDomain(): bool | public function hasDomain(): bool | ||||
{ | { | ||||
foreach ($this->packages as $package) { | foreach ($this->packages as $package) { | ||||
foreach ($package->skus as $sku) { | if ($package->isDomain()) { | ||||
if ($sku->handler_class::entitleableClass() == \App\Domain::class) { | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
} | |||||
return false; | return false; | ||||
} | } | ||||
} | } |