Changeset View
Changeset View
Standalone View
Standalone View
src/app/PackageSku.php
Show All 26 Lines | class PackageSku extends Pivot | ||||
]; | ]; | ||||
/** @var array<string, string> The attributes that should be cast */ | /** @var array<string, string> The attributes that should be cast */ | ||||
protected $casts = [ | protected $casts = [ | ||||
'cost' => 'integer', | 'cost' => 'integer', | ||||
'qty' => 'integer' | 'qty' => 'integer' | ||||
]; | ]; | ||||
/** @var array<int, string> The attributes that can be not set */ | |||||
protected $nullable = [ | |||||
'cost', | |||||
]; | |||||
/** @var string Database table name */ | |||||
protected $table = 'package_skus'; | |||||
/** @var bool Indicates if the model should be timestamped. */ | |||||
public $timestamps = false; | |||||
/** | /** | ||||
* Under this package, how much does this SKU cost? | * Under this package, how much does this SKU cost? | ||||
* | * | ||||
* @return int The costs of this SKU under this package in cents. | * @return int The costs of this SKU under this package in cents. | ||||
*/ | */ | ||||
public function cost() | public function cost(): int | ||||
{ | { | ||||
$units = $this->qty - $this->sku->units_free; | $units = $this->qty - $this->sku->units_free; | ||||
if ($units < 0) { | if ($units < 0) { | ||||
$units = 0; | return 0; | ||||
} | } | ||||
// one way is to set a very nice looking price in the package_sku->cost | // one way is to set a very nice looking price in the package_sku->cost | ||||
// this should not be modified by a discount_rate or else there is no purpose to choose | // this should not be modified by a discount_rate or else there is no purpose to choose | ||||
// that nicely looking pricepoint | // that nicely looking pricepoint | ||||
// | // | ||||
// the other way is to take the sku list price, but sell the package with a percentage | // the other way is to take the sku list price, but sell the package with a percentage | ||||
// discount; this way a nice list price of 1399 with a 15% discount ends up with an "ugly" | // discount; this way a nice list price of 1399 with a 15% discount ends up with an "ugly" | ||||
// 1189.15 that needs to be rounded and ends up 1189 | // 1189.15 that needs to be rounded and ends up 1189 | ||||
// | // | ||||
// additional discounts could come from discount vouchers | // additional discounts could come from discount vouchers | ||||
if ($this->cost > 0) { | |||||
// Side-note: Package's discount_rate is on a higher level, so conceptually | |||||
mollekopf: I think the confusing aspect is that we have entitlements.cost, sku.cost, sku_package.cost and… | |||||
// I wouldn't be surprised if one would expect it to apply to package_sku.cost. | |||||
if ($this->cost !== null) { | |||||
$ppu = $this->cost; | $ppu = $this->cost; | ||||
} else { | } else { | ||||
$ppu = $this->sku->cost * ((100 - $this->package->discount_rate) / 100); | $ppu = round($this->sku->cost * ((100 - $this->package->discount_rate) / 100)); | ||||
} | } | ||||
return $units * $ppu; | return $units * $ppu; | ||||
} | } | ||||
/** | /** | ||||
* Under this package, what fee this SKU has? | * Under this package, what fee this SKU has? | ||||
* | * | ||||
Show All 33 Lines |
I think the confusing aspect is that we have entitlements.cost, sku.cost, sku_package.cost and it's not clear what is authoritative. The reason that we have those values is so the cost get's locked in when e.g. an entitlement is taken out, and doesn't change if sku prices are adjusted, but I think it would be good if the those relationsships would be documented someplace, which is also where we should document how discounts are applied.