Skip to content
Open
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
62 changes: 48 additions & 14 deletions includes/Generator/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ public static function generate( $save = true ) {
$email = self::$faker->safeEmail();
} while ( email_exists( $email ) );

/*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' );
Expand Down Expand Up @@ -73,13 +61,37 @@ public static function generate( $save = true ) {
default:
break;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@masteradhoc While it may be a bit before we get to review this, the added code isn't formatted according to WP Coding Standards which we would need before merging.


/*PERSON*/
if(strlen($company['billing']['company_name']) >= 1 && (bool) wp_rand( 0, 1 )){
$person['billing']['firstname'] = '';
$person['billing']['lastname'] = '';
} else {
$person['billing']['firstname'] = self::$faker->firstName( self::$faker->randomElement( array( 'male', 'female' ) ) );
$person['billing']['lastname'] = self::$faker->lastName();
}

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

/*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']['country'] = Customer::getAllowedCountry();
$address['billing']['phone'] = self::$faker->e164PhoneNumber();
$address['billing']['email'] = $email;

Expand All @@ -90,7 +102,7 @@ public static function generate( $save = true ) {
$address['shipping']['city'] = self::$faker->city();
$address['shipping']['state'] = self::$faker->stateAbbr();
$address['shipping']['postcode'] = self::$faker->postcode();
$address['shipping']['country'] = self::$faker->countryCode();
$address['shipping']['country'] = Customer::getAllowedCountry();
} else {
$address['shipping']['address0'] = $address['billing']['address0'];
$address['shipping']['address1'] = $address['billing']['address1'];
Expand Down Expand Up @@ -144,6 +156,28 @@ public static function generate( $save = true ) {
return $customer;
}

/**
* returns allowed country based on the woocommerce settings
*/
public static function getAllowedCountry(){
$allowedCountries = get_option('woocommerce_allowed_countries');
$allowedOnes = get_option('woocommerce_specific_allowed_countries');
$restrictedOnes = get_option('woocommerce_all_except_countries');

if ($allowedCountries == 'specific'){
$country = self::$faker->randomElements( $allowedOnes, $count = 1 );
$country = $country[0];
} else if ($allowedCountries == 'all_except'){
do{
$country = self::$faker->countryCode();
} while (in_array($country,$restrictedOnes));
} else {
$country = self::$faker->countryCode();
}

return $country;
}


/**
* Disable sending WooCommerce emails when generating objects.
Expand Down