Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ wc-smooth-generator.zip
phpcs.xml

# PHP xdebug
.vscode/launch.json
.vscode/launch.json
152 changes: 107 additions & 45 deletions includes/Generator/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
*/
class Customer extends Generator {


/**
* Return a new customer.
*
* @param bool $save Save the object before returning or not.
* @param bool $save Save the object before returning or not.
* @return \WC_Customer Customer object with data populated.
*/
public static function generate( $save = true ) {
Expand All @@ -30,50 +31,111 @@ public static function generate( $save = true ) {
$email = self::$faker->safeEmail();
} while ( email_exists( $email ) );

$firstname = self::$faker->firstName( self::$faker->randomElement( array( 'male', 'female' ) ) );
$lastname = self::$faker->lastName();
$company = self::$faker->company();
$address1 = self::$faker->buildingNumber() . ' ' . self::$faker->streetName();
$address2 = self::$faker->streetAddress();
$city = self::$faker->city();
$state = self::$faker->stateAbbr();
$postcode = self::$faker->postcode();
$countrycode = self::$faker->countryCode();
$phone = self::$faker->e164PhoneNumber();
$customer = new \WC_Customer();

$customer->set_props( array(
'date_created' => null,
'date_modified' => null,
'email' => $email,
'first_name' => $firstname,
'last_name' => $lastname,
'display_name' => $firstname,
'role' => 'customer',
'username' => $username,
'password' => self::$faker->password(),
'billing_first_name' => $firstname,
'billing_last_name' => $lastname,
'billing_company' => $company,
'billing_address_1' => $address1,
'billing_address_2' => $address2,
'billing_city' => $city,
'billing_state' => $state,
'billing_postcode' => $postcode,
'billing_country' => $countrycode,
'billing_email' => $email,
'billing_phone' => $phone,
'shipping_first_name' => $firstname,
'shipping_last_name' => $lastname,
'shipping_company' => $company,
'shipping_address_1' => $address1,
'shipping_address_2' => $address2,
'shipping_city' => $city,
'shipping_state' => $state,
'shipping_postcode' => $postcode,
'shipping_country' => $countrycode,
'is_paying_customer' => false,
) );
/*PERSON*/
$person['billing']['firstname'] = self::$faker->firstName( self::$faker->randomElement( array( 'male', 'female' ) ) );
$person['billing']['lastname'] = self::$faker->lastName();

// 50% chance
if ( (bool) wp_rand( 0, 1 ) ) {
$person['shipping']['firstname'] = self::$faker->firstName( self::$faker->randomElement( array( 'male', 'female' ) ) );
$person['shipping']['lastname'] = self::$faker->lastName();
} else {
$person['shipping']['firstname'] = $person['billing']['firstname'];
$person['shipping']['lastname'] = $person['billing']['lastname'];
}

/*COMPANY*/
$company_variations = array( 'B2B', 'C2C', 'C2B', 'B2C' );
$relationType = self::$faker->randomElements( $company_variations, $count = 1 );

switch ( $relationType[0] ) {
case 'B2B':
$company['billing']['company_name'] = self::$faker->company();
if ( self::$faker->randomFloat( 0, 0, 1 ) == 1 ) {
$company['shipping']['company_name'] = self::$faker->company();
} else {
$company['shipping']['company_name'] = $company['billing']['company_name'];
}

break;
case 'C2C':
$company['billing']['company_name'] = '';
$company['shipping']['company_name'] = '';
break;
case 'B2C':
$company['billing']['company_name'] = self::$faker->company();
$company['shipping']['company_name'] = '';
break;
case 'C2B':
$company['billing']['company_name'] = '';
$company['shipping']['company_name'] = self::$faker->company();
break;
default:
break;
}
/*ADDRESS*/
$address['billing']['address0'] = self::$faker->buildingNumber() . ' ' . self::$faker->streetName();
$address['billing']['address1'] = self::$faker->streetAddress();
$address['billing']['city'] = self::$faker->city();
$address['billing']['state'] = self::$faker->stateAbbr();
$address['billing']['postcode'] = self::$faker->postcode();
$address['billing']['country'] = self::$faker->countryCode();
$address['billing']['phone'] = self::$faker->e164PhoneNumber();
$address['billing']['email'] = $email;

// 50% chance
if ( (bool) wp_rand( 0, 1 ) ) {
$address['shipping']['address0'] = self::$faker->buildingNumber() . ' ' . self::$faker->streetName();
$address['shipping']['address1'] = self::$faker->streetAddress();
$address['shipping']['city'] = self::$faker->city();
$address['shipping']['state'] = self::$faker->stateAbbr();
$address['shipping']['postcode'] = self::$faker->postcode();
$address['shipping']['country'] = self::$faker->countryCode();
} else {
$address['shipping']['address0'] = $address['billing']['address0'];
$address['shipping']['address1'] = $address['billing']['address1'];
$address['shipping']['city'] = $address['billing']['city'];
$address['shipping']['state'] = $address['billing']['state'];
$address['shipping']['postcode'] = $address['billing']['postcode'];
$address['shipping']['country'] = $address['billing']['country'];
}

$customer = new \WC_Customer();

$customer->set_props(
array(
'date_created' => null,
'date_modified' => null,
'email' => $email,
'first_name' => $person['billing']['firstname'],
'last_name' => $person['billing']['lastname'],
'display_name' => $person['billing']['firstname'],
'role' => 'customer',
'username' => $username,
'password' => self::$faker->password(),
'billing_first_name' => $person['billing']['firstname'],
'billing_last_name' => $person['billing']['lastname'],
'billing_company' => $company['billing']['company_name'],
'billing_address_0' => $address['billing']['address0'],
'billing_address_1' => $address['billing']['address1'],
'billing_city' => $address['billing']['city'],
'billing_state' => $address['billing']['state'],
'billing_postcode' => $address['billing']['postcode'],
'billing_country' => $address['billing']['country'],
'billing_email' => $address['billing']['email'],
'billing_phone' => $address['billing']['phone'],
'shipping_first_name' => $person['shipping']['firstname'],
'shipping_last_name' => $person['shipping']['lastname'],
'shipping_company' => $company['shipping']['company_name'],
'shipping_address_0' => $address['shipping']['address0'],
'shipping_address_1' => $address['shipping']['address1'],
'shipping_city' => $address['shipping']['city'],
'shipping_state' => $address['shipping']['state'],
'shipping_postcode' => $address['shipping']['postcode'],
'shipping_country' => $address['shipping']['country'],
'is_paying_customer' => false,
)
);

if ( $save ) {
$customer->save();
Expand Down
7 changes: 5 additions & 2 deletions includes/Generator/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ public static function generate( $save = true, $assoc_args = array() ) {
$order->set_billing_last_name( $customer->get_billing_last_name() );
$order->set_billing_address_1( $customer->get_billing_address_1() );
$order->set_billing_address_2( $customer->get_billing_address_2() );
$order->set_billing_phone( $customer->get_billing_phone() );
$order->set_billing_city( $customer->get_billing_city() );
$order->set_billing_postcode( $customer->get_billing_postcode() );
$order->set_billing_state( $customer->get_billing_state() );
$order->set_billing_country( $customer->get_billing_country() );
$order->set_billing_company( $customer->get_billing_company() );
$order->set_shipping_first_name( $customer->get_shipping_first_name() );
$order->set_shipping_last_name( $customer->get_shipping_last_name() );
$order->set_shipping_address_1( $customer->get_shipping_address_1() );
Expand All @@ -58,7 +60,8 @@ public static function generate( $save = true, $assoc_args = array() ) {
$order->set_shipping_postcode( $customer->get_shipping_postcode() );
$order->set_shipping_state( $customer->get_shipping_state() );
$order->set_shipping_country( $customer->get_shipping_country() );

$order->set_shipping_company( $customer->get_shipping_company() );

// 20% chance
if ( rand( 0, 100 ) <= 20 ) {
$country_code = $order->get_shipping_country();
Expand All @@ -81,7 +84,7 @@ public static function generate( $save = true, $assoc_args = array() ) {
$fee->calculate_taxes( $calculate_tax_for );
$order->add_item( $fee );
}
$order->set_status( self::get_status( $assoc_args ) );
$order->set_status( self::get_status( $assoc_args ) );
$order->calculate_totals( true );

$date = self::get_date_created( $assoc_args );
Expand Down