1212 */
1313class Customer extends Generator {
1414
15+
1516 /**
1617 * Return a new customer.
1718 *
18- * @param bool $save Save the object before returning or not.
19+ * @param bool $save Save the object before returning or not.
1920 * @return \WC_Customer Customer object with data populated.
2021 */
2122 public static function generate ( $ save = true ) {
@@ -30,50 +31,111 @@ public static function generate( $save = true ) {
3031 $ email = self ::$ faker ->safeEmail ();
3132 } while ( email_exists ( $ email ) );
3233
33- $ firstname = self ::$ faker ->firstName ( self ::$ faker ->randomElement ( array ( 'male ' , 'female ' ) ) );
34- $ lastname = self ::$ faker ->lastName ();
35- $ company = self ::$ faker ->company ();
36- $ address1 = self ::$ faker ->buildingNumber () . ' ' . self ::$ faker ->streetName ();
37- $ address2 = self ::$ faker ->streetAddress ();
38- $ city = self ::$ faker ->city ();
39- $ state = self ::$ faker ->stateAbbr ();
40- $ postcode = self ::$ faker ->postcode ();
41- $ countrycode = self ::$ faker ->countryCode ();
42- $ phone = self ::$ faker ->e164PhoneNumber ();
43- $ customer = new \WC_Customer ();
44-
45- $ customer ->set_props ( array (
46- 'date_created ' => null ,
47- 'date_modified ' => null ,
48- 'email ' => $ email ,
49- 'first_name ' => $ firstname ,
50- 'last_name ' => $ lastname ,
51- 'display_name ' => $ firstname ,
52- 'role ' => 'customer ' ,
53- 'username ' => $ username ,
54- 'password ' => self ::$ faker ->password (),
55- 'billing_first_name ' => $ firstname ,
56- 'billing_last_name ' => $ lastname ,
57- 'billing_company ' => $ company ,
58- 'billing_address_1 ' => $ address1 ,
59- 'billing_address_2 ' => $ address2 ,
60- 'billing_city ' => $ city ,
61- 'billing_state ' => $ state ,
62- 'billing_postcode ' => $ postcode ,
63- 'billing_country ' => $ countrycode ,
64- 'billing_email ' => $ email ,
65- 'billing_phone ' => $ phone ,
66- 'shipping_first_name ' => $ firstname ,
67- 'shipping_last_name ' => $ lastname ,
68- 'shipping_company ' => $ company ,
69- 'shipping_address_1 ' => $ address1 ,
70- 'shipping_address_2 ' => $ address2 ,
71- 'shipping_city ' => $ city ,
72- 'shipping_state ' => $ state ,
73- 'shipping_postcode ' => $ postcode ,
74- 'shipping_country ' => $ countrycode ,
75- 'is_paying_customer ' => false ,
76- ) );
34+ /*PERSON*/
35+ $ person ['billing ' ]['firstname ' ] = self ::$ faker ->firstName ( self ::$ faker ->randomElement ( array ( 'male ' , 'female ' ) ) );
36+ $ person ['billing ' ]['lastname ' ] = self ::$ faker ->lastName ();
37+
38+ // 50% chance
39+ if ( (bool ) wp_rand ( 0 , 1 ) ) {
40+ $ person ['shipping ' ]['firstname ' ] = self ::$ faker ->firstName ( self ::$ faker ->randomElement ( array ( 'male ' , 'female ' ) ) );
41+ $ person ['shipping ' ]['lastname ' ] = self ::$ faker ->lastName ();
42+ } else {
43+ $ person ['shipping ' ]['firstname ' ] = $ person ['billing ' ]['firstname ' ];
44+ $ person ['shipping ' ]['lastname ' ] = $ person ['billing ' ]['lastname ' ];
45+ }
46+
47+ /*COMPANY*/
48+ $ company_variations = array ( 'B2B ' , 'C2C ' , 'C2B ' , 'B2C ' );
49+ $ relationType = self ::$ faker ->randomElements ( $ company_variations , $ count = 1 );
50+
51+ switch ( $ relationType [0 ] ) {
52+ case 'B2B ' :
53+ $ company ['billing ' ]['company_name ' ] = self ::$ faker ->company ();
54+ if ( self ::$ faker ->randomFloat ( 0 , 0 , 1 ) == 1 ) {
55+ $ company ['shipping ' ]['company_name ' ] = self ::$ faker ->company ();
56+ } else {
57+ $ company ['shipping ' ]['company_name ' ] = $ company ['billing ' ]['company_name ' ];
58+ }
59+
60+ break ;
61+ case 'C2C ' :
62+ $ company ['billing ' ]['company_name ' ] = '' ;
63+ $ company ['shipping ' ]['company_name ' ] = '' ;
64+ break ;
65+ case 'B2C ' :
66+ $ company ['billing ' ]['company_name ' ] = self ::$ faker ->company ();
67+ $ company ['shipping ' ]['company_name ' ] = '' ;
68+ break ;
69+ case 'C2B ' :
70+ $ company ['billing ' ]['company_name ' ] = '' ;
71+ $ company ['shipping ' ]['company_name ' ] = self ::$ faker ->company ();
72+ break ;
73+ default :
74+ break ;
75+ }
76+ /*ADDRESS*/
77+ $ address ['billing ' ]['address0 ' ] = self ::$ faker ->buildingNumber () . ' ' . self ::$ faker ->streetName ();
78+ $ address ['billing ' ]['address1 ' ] = self ::$ faker ->streetAddress ();
79+ $ address ['billing ' ]['city ' ] = self ::$ faker ->city ();
80+ $ address ['billing ' ]['state ' ] = self ::$ faker ->stateAbbr ();
81+ $ address ['billing ' ]['postcode ' ] = self ::$ faker ->postcode ();
82+ $ address ['billing ' ]['country ' ] = self ::$ faker ->countryCode ();
83+ $ address ['billing ' ]['phone ' ] = self ::$ faker ->e164PhoneNumber ();
84+ $ address ['billing ' ]['email ' ] = $ email ;
85+
86+ // 50% chance
87+ if ( (bool ) wp_rand ( 0 , 1 ) ) {
88+ $ address ['shipping ' ]['address0 ' ] = self ::$ faker ->buildingNumber () . ' ' . self ::$ faker ->streetName ();
89+ $ address ['shipping ' ]['address1 ' ] = self ::$ faker ->streetAddress ();
90+ $ address ['shipping ' ]['city ' ] = self ::$ faker ->city ();
91+ $ address ['shipping ' ]['state ' ] = self ::$ faker ->stateAbbr ();
92+ $ address ['shipping ' ]['postcode ' ] = self ::$ faker ->postcode ();
93+ $ address ['shipping ' ]['country ' ] = self ::$ faker ->countryCode ();
94+ } else {
95+ $ address ['shipping ' ]['address0 ' ] = $ address ['billing ' ]['address0 ' ];
96+ $ address ['shipping ' ]['address1 ' ] = $ address ['billing ' ]['address1 ' ];
97+ $ address ['shipping ' ]['city ' ] = $ address ['billing ' ]['city ' ];
98+ $ address ['shipping ' ]['state ' ] = $ address ['billing ' ]['state ' ];
99+ $ address ['shipping ' ]['postcode ' ] = $ address ['billing ' ]['postcode ' ];
100+ $ address ['shipping ' ]['country ' ] = $ address ['billing ' ]['country ' ];
101+ }
102+
103+ $ customer = new \WC_Customer ();
104+
105+ $ customer ->set_props (
106+ array (
107+ 'date_created ' => null ,
108+ 'date_modified ' => null ,
109+ 'email ' => $ email ,
110+ 'first_name ' => $ person ['billing ' ]['firstname ' ],
111+ 'last_name ' => $ person ['billing ' ]['lastname ' ],
112+ 'display_name ' => $ person ['billing ' ]['firstname ' ],
113+ 'role ' => 'customer ' ,
114+ 'username ' => $ username ,
115+ 'password ' => self ::$ faker ->password (),
116+ 'billing_first_name ' => $ person ['billing ' ]['firstname ' ],
117+ 'billing_last_name ' => $ person ['billing ' ]['lastname ' ],
118+ 'billing_company ' => $ company ['billing ' ]['company_name ' ],
119+ 'billing_address_0 ' => $ address ['billing ' ]['address0 ' ],
120+ 'billing_address_1 ' => $ address ['billing ' ]['address1 ' ],
121+ 'billing_city ' => $ address ['billing ' ]['city ' ],
122+ 'billing_state ' => $ address ['billing ' ]['state ' ],
123+ 'billing_postcode ' => $ address ['billing ' ]['postcode ' ],
124+ 'billing_country ' => $ address ['billing ' ]['country ' ],
125+ 'billing_email ' => $ address ['billing ' ]['email ' ],
126+ 'billing_phone ' => $ address ['billing ' ]['phone ' ],
127+ 'shipping_first_name ' => $ person ['shipping ' ]['firstname ' ],
128+ 'shipping_last_name ' => $ person ['shipping ' ]['lastname ' ],
129+ 'shipping_company ' => $ company ['shipping ' ]['company_name ' ],
130+ 'shipping_address_0 ' => $ address ['shipping ' ]['address0 ' ],
131+ 'shipping_address_1 ' => $ address ['shipping ' ]['address1 ' ],
132+ 'shipping_city ' => $ address ['shipping ' ]['city ' ],
133+ 'shipping_state ' => $ address ['shipping ' ]['state ' ],
134+ 'shipping_postcode ' => $ address ['shipping ' ]['postcode ' ],
135+ 'shipping_country ' => $ address ['shipping ' ]['country ' ],
136+ 'is_paying_customer ' => false ,
137+ )
138+ );
77139
78140 if ( $ save ) {
79141 $ customer ->save ();
0 commit comments