Skip to content

Commit d29923f

Browse files
committed
database seeders
1 parent 25635ba commit d29923f

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

backend/database/seeders/DatabaseSeeder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function run(): void
3030
ShippingZoneSeeder::class,
3131
ShippingMethodSeeder::class,
3232
ShippingRateSeeder::class,
33+
// BundleSeeder::class, // Temporarily disabled due to total_price constraint issue
3334
SeoDataSeeder::class,
3435
]);
3536
}

backend/database/seeders/ShippingMethodSeeder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public function run(): void
3838
];
3939

4040
foreach ($methods as $method) {
41-
ShippingMethod::create($method);
41+
ShippingMethod::firstOrCreate(
42+
['code' => $method['code']],
43+
$method
44+
);
4245
}
4346

4447
$this->command->info('Created ' . count($methods) . ' shipping methods');

backend/database/seeders/ShippingRateSeeder.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ public function run(): void
3838
continue;
3939
}
4040

41-
ShippingRate::create([
42-
'shipping_zone_id' => $zone->id,
43-
'shipping_method_id' => $method->id,
44-
'min_weight' => $tier['min'],
45-
'max_weight' => $tier['max'],
46-
'price' => $tier['price'] * 100, // Convert to cents
47-
'currency' => 'AUD',
48-
'is_active' => true,
49-
]);
41+
ShippingRate::firstOrCreate(
42+
[
43+
'shipping_zone_id' => $zone->id,
44+
'shipping_method_id' => $method->id,
45+
'min_weight' => $tier['min'],
46+
'max_weight' => $tier['max'],
47+
],
48+
[
49+
'price' => $tier['price'] * 100, // Convert to cents
50+
'currency' => 'AUD',
51+
'is_active' => true,
52+
]
53+
);
5054

5155
$createdRates++;
5256
}

backend/database/seeders/ShippingZoneSeeder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public function run(): void
5959
];
6060

6161
foreach ($zones as $zone) {
62-
ShippingZone::create($zone);
62+
ShippingZone::firstOrCreate(
63+
['postcode_pattern' => $zone['postcode_pattern']],
64+
$zone
65+
);
6366
}
6467

6568
$this->command->info('Created ' . count($zones) . ' Australian shipping zones');

0 commit comments

Comments
 (0)