Skip to content

Commit 2bec9cb

Browse files
Merge pull request #80 from michi-dev/shipping-billing-addresses-feature
Shipping billing addresses feature
2 parents 7e9ff1e + d370d0f commit 2bec9cb

File tree

3 files changed

+113
-48
lines changed

3 files changed

+113
-48
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ wc-smooth-generator.zip
1010
phpcs.xml
1111

1212
# PHP xdebug
13-
.vscode/launch.json
13+
.vscode/launch.json

includes/Generator/Customer.php

Lines changed: 107 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
*/
1313
class 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();

includes/Generator/Order.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ public static function generate( $save = true, $assoc_args = array() ) {
4646
$order->set_billing_last_name( $customer->get_billing_last_name() );
4747
$order->set_billing_address_1( $customer->get_billing_address_1() );
4848
$order->set_billing_address_2( $customer->get_billing_address_2() );
49+
$order->set_billing_phone( $customer->get_billing_phone() );
4950
$order->set_billing_city( $customer->get_billing_city() );
5051
$order->set_billing_postcode( $customer->get_billing_postcode() );
5152
$order->set_billing_state( $customer->get_billing_state() );
5253
$order->set_billing_country( $customer->get_billing_country() );
54+
$order->set_billing_company( $customer->get_billing_company() );
5355
$order->set_shipping_first_name( $customer->get_shipping_first_name() );
5456
$order->set_shipping_last_name( $customer->get_shipping_last_name() );
5557
$order->set_shipping_address_1( $customer->get_shipping_address_1() );
@@ -58,7 +60,8 @@ public static function generate( $save = true, $assoc_args = array() ) {
5860
$order->set_shipping_postcode( $customer->get_shipping_postcode() );
5961
$order->set_shipping_state( $customer->get_shipping_state() );
6062
$order->set_shipping_country( $customer->get_shipping_country() );
61-
63+
$order->set_shipping_company( $customer->get_shipping_company() );
64+
6265
// 20% chance
6366
if ( rand( 0, 100 ) <= 20 ) {
6467
$country_code = $order->get_shipping_country();
@@ -81,7 +84,7 @@ public static function generate( $save = true, $assoc_args = array() ) {
8184
$fee->calculate_taxes( $calculate_tax_for );
8285
$order->add_item( $fee );
8386
}
84-
$order->set_status( self::get_status( $assoc_args ) );
87+
$order->set_status( self::get_status( $assoc_args ) );
8588
$order->calculate_totals( true );
8689

8790
$date = self::get_date_created( $assoc_args );

0 commit comments

Comments
 (0)