Changeset View
Changeset View
Standalone View
Standalone View
src/database/seeds/local/PackageSeeder.php
Show All 9 Lines | |||||
{ | { | ||||
/** | /** | ||||
* Run the database seeds. | * Run the database seeds. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function run() | public function run() | ||||
{ | { | ||||
$skuGroupware = Sku::firstOrCreate(['title' => 'groupware']); | $skuDomain = Sku::where(['title' => 'domain-hosting', 'tenant_id' => \config('app.tenant_id')])->first(); | ||||
$skuMailbox = Sku::firstOrCreate(['title' => 'mailbox']); | $skuGroupware = Sku::where(['title' => 'groupware', 'tenant_id' => \config('app.tenant_id')])->first(); | ||||
$skuStorage = Sku::firstOrCreate(['title' => 'storage']); | $skuMailbox = Sku::where(['title' => 'mailbox', 'tenant_id' => \config('app.tenant_id')])->first(); | ||||
$skuStorage = Sku::where(['title' => 'storage', 'tenant_id' => \config('app.tenant_id')])->first(); | |||||
$package = Package::create( | |||||
[ | |||||
'title' => 'kolab', | |||||
'name' => 'Groupware Account', | |||||
'description' => 'A fully functional groupware account.', | |||||
'discount_rate' => 0, | |||||
] | |||||
machniak: Redundant, not fillable. | |||||
); | |||||
$skus = [ | |||||
$skuMailbox, | |||||
$skuGroupware, | |||||
$skuStorage | |||||
]; | |||||
$package->skus()->saveMany($skus); | |||||
// This package contains 2 units of the storage SKU, which just so happens to also | |||||
// be the number of SKU free units. | |||||
$package->skus()->updateExistingPivot( | |||||
$skuStorage, | |||||
['qty' => 5], | |||||
false | |||||
); | |||||
$package = Package::create( | |||||
[ | |||||
'title' => 'lite', | |||||
'name' => 'Lite Account', | |||||
'description' => 'Just mail and no more.', | |||||
'discount_rate' => 0, | |||||
] | |||||
); | |||||
$skus = [ | |||||
$skuMailbox, | |||||
$skuStorage | |||||
]; | |||||
$package->skus()->saveMany($skus); | |||||
$package->skus()->updateExistingPivot( | |||||
$skuStorage, | |||||
['qty' => 5], | |||||
false | |||||
); | |||||
$package = Package::create( | |||||
[ | |||||
'title' => 'domain-hosting', | |||||
'name' => 'Domain Hosting', | |||||
'description' => 'Use your own, existing domain.', | |||||
'discount_rate' => 0, | |||||
] | |||||
); | |||||
$skus = [ | |||||
$skuDomain | |||||
]; | |||||
$package->skus()->saveMany($skus); | |||||
// We're running in reseller mode, add a sample discount | |||||
$tenants = \App\Tenant::where('id', '!=', \config('app.tenant_id'))->get(); | |||||
foreach ($tenants as $tenant) { | |||||
$skuDomain = Sku::where(['title' => 'domain-hosting', 'tenant_id' => $tenant->id])->first(); | |||||
$skuGroupware = Sku::where(['title' => 'groupware', 'tenant_id' => $tenant->id])->first(); | |||||
$skuMailbox = Sku::where(['title' => 'mailbox', 'tenant_id' => $tenant->id])->first(); | |||||
$skuStorage = Sku::where(['title' => 'storage', 'tenant_id' => $tenant->id])->first(); | |||||
$package = Package::create( | $package = Package::create( | ||||
[ | [ | ||||
'title' => 'kolab', | 'title' => 'kolab', | ||||
'name' => 'Groupware Account', | 'name' => 'Groupware Account', | ||||
'description' => 'A fully functional groupware account.', | 'description' => 'A fully functional groupware account.', | ||||
'discount_rate' => 0 | 'discount_rate' => 0 | ||||
] | ] | ||||
); | ); | ||||
$package->tenant_id = $tenant->id; | |||||
$package->save(); | |||||
$skus = [ | $skus = [ | ||||
$skuMailbox, | $skuMailbox, | ||||
$skuGroupware, | $skuGroupware, | ||||
$skuStorage | $skuStorage | ||||
]; | ]; | ||||
$package->skus()->saveMany($skus); | $package->skus()->saveMany($skus); | ||||
// This package contains 2 units of the storage SKU, which just so happens to also | // This package contains 2 units of the storage SKU, which just so happens to also | ||||
// be the number of SKU free units. | // be the number of SKU free units. | ||||
$package->skus()->updateExistingPivot( | $package->skus()->updateExistingPivot( | ||||
$skuStorage, | $skuStorage, | ||||
['qty' => 2], | ['qty' => 5], | ||||
false | false | ||||
); | ); | ||||
$package = Package::create( | $package = Package::create( | ||||
[ | [ | ||||
'title' => 'lite', | 'title' => 'lite', | ||||
'name' => 'Lite Account', | 'name' => 'Lite Account', | ||||
'description' => 'Just mail and no more.', | 'description' => 'Just mail and no more.', | ||||
'discount_rate' => 0 | 'discount_rate' => 0 | ||||
] | ] | ||||
); | ); | ||||
$package->tenant_id = $tenant->id; | |||||
$package->save(); | |||||
$skus = [ | $skus = [ | ||||
$skuMailbox, | $skuMailbox, | ||||
$skuStorage | $skuStorage | ||||
]; | ]; | ||||
$package->skus()->saveMany($skus); | $package->skus()->saveMany($skus); | ||||
$package->skus()->updateExistingPivot( | $package->skus()->updateExistingPivot( | ||||
Sku::firstOrCreate(['title' => 'storage']), | $skuStorage, | ||||
['qty' => 2], | ['qty' => 5], | ||||
false | false | ||||
); | ); | ||||
$package = Package::create( | $package = Package::create( | ||||
[ | [ | ||||
'title' => 'domain-hosting', | 'title' => 'domain-hosting', | ||||
'name' => 'Domain Hosting', | 'name' => 'Domain Hosting', | ||||
'description' => 'Use your own, existing domain.', | 'description' => 'Use your own, existing domain.', | ||||
'discount_rate' => 0 | 'discount_rate' => 0 | ||||
] | ] | ||||
); | ); | ||||
$package->tenant_id = $tenant->id; | |||||
$package->save(); | |||||
$skus = [ | $skus = [ | ||||
Sku::firstOrCreate(['title' => 'domain-hosting']) | $skuDomain | ||||
]; | ]; | ||||
$package->skus()->saveMany($skus); | $package->skus()->saveMany($skus); | ||||
} | } | ||||
} | } | ||||
} |
Redundant, not fillable.