| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Database\Seeder; |
| 4 |
|
| 5 |
use FluentCart\App\Models\AppliedCoupon; |
| 6 |
use FluentCart\Faker\Factory; |
| 7 |
|
| 8 |
class AppliedCouponsSeeder |
| 9 |
{ |
| 10 |
public static function seed($count) |
| 11 |
{ |
| 12 |
$faker = Factory::create(); |
| 13 |
|
| 14 |
$appliedCouponsLists = []; |
| 15 |
|
| 16 |
if (defined('WP_CLI') && WP_CLI) { |
| 17 |
$progress = \WP_CLI\Utils\make_progress_bar('%CSeeding AppliedCoupons', $count); |
| 18 |
} |
| 19 |
for ($i = 0; $i <= $count - 1; $i++) { |
| 20 |
if($i%2==0){ |
| 21 |
$code = 'TEST101'; |
| 22 |
} |
| 23 |
else { |
| 24 |
$code = 'TEST102'; |
| 25 |
} |
| 26 |
$appliedCouponsLists[] = [ |
| 27 |
'title' => $faker->text(200), |
| 28 |
'code' => $code, |
| 29 |
'status' => $faker->text(20), |
| 30 |
'type' => $faker->text(20), |
| 31 |
]; |
| 32 |
|
| 33 |
if (defined('WP_CLI') && WP_CLI) { |
| 34 |
if ($i !== $count - 1) { |
| 35 |
$progress->tick(); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
} |
| 40 |
AppliedCoupon::insert($appliedCouponsLists); |
| 41 |
if (defined('WP_CLI') && WP_CLI) { |
| 42 |
$progress->tick(); |
| 43 |
$progress->finish(); |
| 44 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 45 |
echo \WP_CLI::colorize('%n'); |
| 46 |
} |
| 47 |
} |
| 48 |
} |