PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / database / Seeder / CustomerSeeder.php

CustomerSeeder.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at database/Seeder/CustomerSeeder.php

74 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\Database\Seeder;
4
5 use FluentCart\Faker\Factory;
6 use FluentCart\App\Models\Customer;
7
8 class CustomerSeeder
9 {
10 public static function seed($count, $assoc_args = [])
11 {
12 $faker = Factory::create();
13 $customerLists = [];
14
15 if (defined('WP_CLI') && WP_CLI) {
16 $progress = \WP_CLI\Utils\make_progress_bar('%CSeeding Customer', $count);
17 }
18
19 $countryCodes = [
20 'US' => ['New York', 'Los Angeles', 'Chicago', 'Houston'],
21 'CA' => ['Toronto', 'Vancouver', 'Montreal', 'Calgary'],
22 'GB' => ['London', 'Manchester', 'Birmingham', 'Liverpool'],
23 'AU' => ['Sydney', 'Melbourne', 'Brisbane', 'Perth'],
24 'DE' => ['Berlin', 'Munich', 'Hamburg', 'Frankfurt'],
25 'FR' => ['Paris', 'Marseille', 'Lyon', 'Toulouse'],
26 'IT' => ['Rome', 'Milan', 'Naples', 'Turin'],
27 'ES' => ['Madrid', 'Barcelona', 'Seville', 'Valencia'],
28 'BR' => ['São Paulo', 'Rio de Janeiro', 'Salvador', 'Brasília'],
29 'JP' => ['Tokyo', 'Osaka', 'Kyoto', 'Sapporo'],
30 'BD' => ['Sylhet', 'Moulvi Bazar', 'Sreemangal', 'Noakhali']
31 ];
32
33 for ($i = 0; $i < $count; $i++) {
34 $gender = $faker->randomElement(['male', 'female']);
35 $country = $faker->randomElement(array_keys($countryCodes));
36 $city = $faker->randomElement($countryCodes[$country]);
37
38 $customerLists[] = [
39 'email' => $faker->email(),
40 'first_name' => $faker->firstName($gender),
41 'last_name' => $faker->lastName($gender),
42 'notes' => $faker->text(30),
43 'country' => $country,
44 'city' => $city,
45 'state' => $faker->state(),
46 'postcode' => $faker->postcode(),
47 'created_at' => $faker->dateTimeBetween('-700 days', 'now')
48 ];
49
50 if (defined('WP_CLI') && WP_CLI) {
51 if ($i !== $count - 1) {
52 $progress->tick();
53 }
54 } else {
55 /* translators: 1: Customer number */
56 echo wp_kses_post( sprintf(
57 /* translators: %d: customer ID */
58 __('Inserting Customer %1$s<br>', 'fluent-cart'),
59 esc_html($i + 1)
60 ) );
61 }
62 }
63
64 Customer::query()->insert($customerLists);
65
66 if (defined('WP_CLI') && WP_CLI) {
67 $progress->tick();
68 $progress->finish();
69 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
70 echo \WP_CLI::colorize('%n');
71 }
72 }
73 }
74