Changeset View
Changeset View
Standalone View
Standalone View
src/app/Package.php
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | class Package extends Model | ||||
* | * | ||||
* @return int The costs in cents. | * @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) { | ||||
// Note: This cost already takes package's discount_rate | |||||
$costs += $sku->pivot->cost(); | $costs += $sku->pivot->cost(); | ||||
} | } | ||||
return $costs; | return $costs; | ||||
} | } | ||||
/** | /** | ||||
* Checks whether the package contains a domain SKU. | * Checks whether the package contains a domain SKU. | ||||
Show All 13 Lines | class Package extends Model | ||||
* SKUs of this package. | * SKUs of this package. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||||
*/ | */ | ||||
public function skus() | public function skus() | ||||
{ | { | ||||
return $this->belongsToMany(Sku::class, 'package_skus') | return $this->belongsToMany(Sku::class, 'package_skus') | ||||
->using(PackageSku::class) | ->using(PackageSku::class) | ||||
->withPivot(['qty']); | ->withPivot(['qty', 'cost']); | ||||
} | } | ||||
} | } |