Changeset View
Changeset View
Standalone View
Standalone View
src/app/Group.php
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public function assignToWallet(Wallet $wallet): Group | ||||
if (empty($this->id)) { | if (empty($this->id)) { | ||||
throw new \Exception("Group not yet exists"); | throw new \Exception("Group not yet exists"); | ||||
} | } | ||||
if ($this->entitlement()->count()) { | if ($this->entitlement()->count()) { | ||||
throw new \Exception("Group already assigned to a wallet"); | throw new \Exception("Group already assigned to a wallet"); | ||||
} | } | ||||
$sku = \App\Sku::where('title', 'group')->first(); | $sku = \App\Sku::withObjectTenantContext($this)->where('title', 'group')->first(); | ||||
$exists = $wallet->entitlements()->where('sku_id', $sku->id)->count(); | $exists = $wallet->entitlements()->where('sku_id', $sku->id)->count(); | ||||
\App\Entitlement::create([ | \App\Entitlement::create([ | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'sku_id' => $sku->id, | 'sku_id' => $sku->id, | ||||
'cost' => $exists >= $sku->units_free ? $sku->cost : 0, | 'cost' => $exists >= $sku->units_free ? $sku->cost : 0, | ||||
'fee' => $exists >= $sku->units_free ? $sku->fee : 0, | 'fee' => $exists >= $sku->units_free ? $sku->fee : 0, | ||||
'entitleable_id' => $this->id, | 'entitleable_id' => $this->id, | ||||
▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines |