Changeset View
Changeset View
Standalone View
Standalone View
src/app/Package.php
Show All 28 Lines | class Package extends Model | ||||
public $timestamps = false; | public $timestamps = false; | ||||
protected $fillable = [ | protected $fillable = [ | ||||
'title', | 'title', | ||||
'description', | 'description', | ||||
'discount_rate' | 'discount_rate' | ||||
]; | ]; | ||||
/** | |||||
* The costs of this package at its pre-defined, existing configuration. | |||||
* | |||||
* @return int The costs in cents. | |||||
*/ | |||||
public function cost() | public function cost() | ||||
{ | { | ||||
$costs = 0; | $costs = 0; | ||||
foreach ($this->skus as $sku) { | foreach ($this->skus as $sku) { | ||||
$costs += ($sku->pivot->qty - $sku->units_free) * $sku->cost; | $units = $sku->pivot->qty - $sku->units_free; | ||||
if ($units < 0) { | |||||
\Log::debug("Package {$this->id} is misconfigured for more free units than qty."); | |||||
$units = 0; | |||||
} | |||||
$ppu = $sku->cost * ((100 - $this->discount_rate) / 100); | |||||
$costs += $units * $ppu; | |||||
} | } | ||||
return $costs; | return $costs; | ||||
} | } | ||||
public function isDomain() | public function isDomain() | ||||
{ | { | ||||
foreach ($this->skus as $sku) { | foreach ($this->skus as $sku) { | ||||
Show All 18 Lines |