Changeset View
Changeset View
Standalone View
Standalone View
src/app/PlanPackage.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use Illuminate\Database\Eloquent\Relations\Pivot; | use Illuminate\Database\Eloquent\Relations\Pivot; | ||||
/** | |||||
* Link Packages to Plans. | |||||
* | |||||
* @property integer $qty_min | |||||
* @property \App\Package $package | |||||
*/ | |||||
class PlanPackage extends Pivot | class PlanPackage extends Pivot | ||||
{ | { | ||||
protected $fillable = [ | protected $fillable = [ | ||||
'plan_id', | 'plan_id', | ||||
'package_id', | 'package_id', | ||||
'qty', | 'qty', | ||||
'qty_max', | 'qty_max', | ||||
'qty_min', | 'qty_min', | ||||
'discount_qty', | 'discount_qty', | ||||
'discount_rate' | 'discount_rate' | ||||
]; | ]; | ||||
protected $casts = [ | protected $casts = [ | ||||
'qty' => 'integer', | 'qty' => 'integer', | ||||
'qty_max' => 'integer', | 'qty_max' => 'integer', | ||||
'qty_min' => 'integer', | 'qty_min' => 'integer', | ||||
'discount_qty' => 'integer', | 'discount_qty' => 'integer', | ||||
'discount_rate' => 'integer' | 'discount_rate' => 'integer' | ||||
]; | ]; | ||||
/** | |||||
* Calculate the costs for this plan. | |||||
* | |||||
* @return integer | |||||
*/ | |||||
public function cost() | public function cost() | ||||
{ | { | ||||
$costs = 0; | $costs = 0; | ||||
if ($this->qty_min > 0) { | if ($this->qty_min > 0) { | ||||
foreach ($this->package->skus() as $sku) { | foreach ($this->package->skus() as $sku) { | ||||
$costs += $sku->cost; | $costs += $sku->cost; | ||||
} | } | ||||
} | } | ||||
return $costs; | return $costs; | ||||
} | } | ||||
} | } |