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' | ||||
]; | ]; | ||||
public function cost() | public function cost() | ||||
machniak: My old method used entitleableClass() to make the code more universal. I.e. the calling code… | |||||
Done Inline ActionsIt should be the inverse, i.e. User->assignPackage($package), to preserve the narrative of a customer taking something off the shelf. vanmeeuwen: It should be the inverse, i.e. `User->assignPackage($package)`, to preserve the narrative of a… | |||||
{ | { | ||||
$costs = 0; | $costs = 0; | ||||
foreach ($this->skus as $sku) { | foreach ($this->skus as $sku) { | ||||
$costs += ($sku->pivot->qty - $sku->units_free) * $sku->cost; | $costs += ($sku->pivot->qty - $sku->units_free) * $sku->cost; | ||||
} | } | ||||
return $costs; | return $costs; | ||||
} | } | ||||
public function isDomain() | |||||
{ | |||||
foreach ($this->skus as $sku) { | |||||
if ($sku->hander_class::entitleableClass() == \App\Domain::class) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
public function skus() | public function skus() | ||||
{ | { | ||||
return $this->belongsToMany( | return $this->belongsToMany( | ||||
Not Done Inline ActionsI'm pretty sure this will make a new query on every iteration. We should move that out of the foreach loop, so the query is executed only once. machniak: I'm pretty sure this will make a new query on every iteration. We should move that out of the… | |||||
Done Inline ActionsI'll move it out. vanmeeuwen: I'll move it out. | |||||
'App\Sku', | 'App\Sku', | ||||
'package_skus' | 'package_skus' | ||||
)->using('App\PackageSku')->withPivot( | )->using('App\PackageSku')->withPivot( | ||||
['qty'] | ['qty'] | ||||
); | ); | ||||
} | } | ||||
} | } |
My old method used entitleableClass() to make the code more universal. I.e. the calling code didn't have to know with with arguments to call the method. I mean, look at SignupController, it calls $package->assign($user), which means it will assing the domain-hosting SKU to a user not the domain. This is a bug.