From 090487f071311c1bf3275748bd7dc805bc19144a Mon Sep 17 00:00:00 2001 From: michi-dev Date: Mon, 30 Jan 2023 11:44:01 +0100 Subject: [PATCH 1/4] companies without person --- includes/Generator/Customer.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/includes/Generator/Customer.php b/includes/Generator/Customer.php index e3f5b47..1816908 100644 --- a/includes/Generator/Customer.php +++ b/includes/Generator/Customer.php @@ -57,6 +57,16 @@ public static function generate( $save = true ) { $company['shipping']['company_name'] = $company['billing']['company_name']; } + if (( (bool) wp_rand( 0, 1 ) )){ + $person['billing']['firstname'] = ''; + $person['billing']['lastname'] = ''; + } + + if (( (bool) wp_rand( 0, 1 ) )){ + $person['shipping']['firstname'] = ''; + $person['shipping']['lastname'] = ''; + } + break; case 'C2C': $company['billing']['company_name'] = ''; @@ -65,6 +75,12 @@ public static function generate( $save = true ) { case 'B2C': $company['billing']['company_name'] = self::$faker->company(); $company['shipping']['company_name'] = ''; + + if (( (bool) wp_rand( 0, 1 ) )){ + $person['billing']['firstname'] = ''; + $person['billing']['lastname'] = ''; + } + break; case 'C2B': $company['billing']['company_name'] = ''; @@ -159,3 +175,4 @@ public static function disable_emails() { } } } +?> \ No newline at end of file From 4feec7a218ed90b61ac7907e9a4d6b46ab7d2d04 Mon Sep 17 00:00:00 2001 From: michi-dev Date: Mon, 30 Jan 2023 13:55:35 +0100 Subject: [PATCH 2/4] better version of feature --- includes/Generator/Customer.php | 55 +++++++++++++++------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/includes/Generator/Customer.php b/includes/Generator/Customer.php index 1816908..814b1ce 100644 --- a/includes/Generator/Customer.php +++ b/includes/Generator/Customer.php @@ -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' ); @@ -57,16 +45,6 @@ public static function generate( $save = true ) { $company['shipping']['company_name'] = $company['billing']['company_name']; } - if (( (bool) wp_rand( 0, 1 ) )){ - $person['billing']['firstname'] = ''; - $person['billing']['lastname'] = ''; - } - - if (( (bool) wp_rand( 0, 1 ) )){ - $person['shipping']['firstname'] = ''; - $person['shipping']['lastname'] = ''; - } - break; case 'C2C': $company['billing']['company_name'] = ''; @@ -74,13 +52,7 @@ public static function generate( $save = true ) { break; case 'B2C': $company['billing']['company_name'] = self::$faker->company(); - $company['shipping']['company_name'] = ''; - - if (( (bool) wp_rand( 0, 1 ) )){ - $person['billing']['firstname'] = ''; - $person['billing']['lastname'] = ''; - } - + $company['shipping']['company_name'] = ''; break; case 'C2B': $company['billing']['company_name'] = ''; @@ -89,6 +61,30 @@ public static function generate( $save = true ) { default: break; } + + + /*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(); @@ -175,4 +171,3 @@ public static function disable_emails() { } } } -?> \ No newline at end of file From 0927e2799bd3a71d2f1c918f8159ea9a00a7cfd9 Mon Sep 17 00:00:00 2001 From: michi-dev Date: Mon, 30 Jan 2023 13:59:38 +0100 Subject: [PATCH 3/4] removing useless spaces --- includes/Generator/Customer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Generator/Customer.php b/includes/Generator/Customer.php index 814b1ce..88ea43b 100644 --- a/includes/Generator/Customer.php +++ b/includes/Generator/Customer.php @@ -52,7 +52,7 @@ public static function generate( $save = true ) { break; case 'B2C': $company['billing']['company_name'] = self::$faker->company(); - $company['shipping']['company_name'] = ''; + $company['shipping']['company_name'] = ''; break; case 'C2B': $company['billing']['company_name'] = ''; From 8672feadbc7f7daf4fc7f3c8d325f82109482a16 Mon Sep 17 00:00:00 2001 From: michi-dev Date: Mon, 30 Jan 2023 15:36:07 +0100 Subject: [PATCH 4/4] only countries, wich are specified in the settings --- includes/Generator/Customer.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/includes/Generator/Customer.php b/includes/Generator/Customer.php index 88ea43b..c0355c0 100644 --- a/includes/Generator/Customer.php +++ b/includes/Generator/Customer.php @@ -91,7 +91,7 @@ public static function generate( $save = true ) { $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; @@ -102,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']; @@ -156,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.