updateCustomer resolver cleaned up

This commit is contained in:
Geoff Taylor
2020-05-11 21:23:56 -04:00
committed by Geoff Taylor
parent 56507b663a
commit 6d63f8d00d
4 changed files with 23 additions and 20 deletions
+3 -1
View File
@@ -43,7 +43,9 @@ jobs:
name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }}
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Build "testing" Docker Image
run: |
@@ -219,7 +219,7 @@ class Checkout_Mutation {
* @return bool
*/
protected static function clear_customer_address( $type = 'billing' ) {
if ( 'billing' !== $type || 'shipping' !== $type ) {
if ( 'billing' !== $type && 'shipping' !== $type ) {
return false;
}
+16 -13
View File
@@ -109,14 +109,6 @@ class Customer_Update {
// Create customer object.
$customer = ! $session_only ? new WC_Customer( $payload['id'] ) : \WC()->customer;
// Set billing address.
if ( ! empty( $customer_args['billing'] ) ) {
foreach ( $customer_args['billing'] as $prop => $value ) {
$setter = 'set_billing_' . $prop;
$customer->{$setter}( $value );
}
}
// Copy billing address as shipping address.
if ( ! empty( $input['shippingSameAsBilling'] ) && $input['shippingSameAsBilling'] ) {
$customer_args['shipping'] = array_merge(
@@ -125,11 +117,22 @@ class Customer_Update {
);
}
// Set shipping address.
if ( ! empty( $customer_args['shipping'] ) ) {
foreach ( $customer_args['shipping'] as $prop => $value ) {
$setter = 'set_shipping_' . $prop;
$customer->{$setter}( $value );
// Update customer fields.
foreach ( $customer_args as $prop => $value ) {
// If field group like 'shipping' or 'billing'.
if ( ! empty( $value ) && \is_array( $value ) ) {
// Check if group field has set function and assigns new value.
foreach ( $value as $field => $field_value ) {
if ( is_callable( array( $customer, "set_{$prop}_{$field}") ) ) {
$customer->{"set_{$prop}_{$field}"}( $field_value );
}
}
// If field has set function and assigns new value.
} elseif ( is_callable( array( $customer, "set_{$prop}" ) ) ) {
$customer->{"set_{$prop}"}( $value );
}
}
@@ -177,7 +177,7 @@ class Dummy {
}
public function lastname() {
$list = explode(",","Smith,Johnson,Williams,Jones,Brown,Davis,Miller,Wilson,Moore,Taylor,Anderson,Thomas,Jackson,White,Harris,Martin,Thompson,Garcia,Martinez,Robinson,Clark,Rodriguez,Lewis,Lee,Walker,Hall,Allen,Young,Hernandez,King,Wright,Lopez,Hill,Scott,Green,Adams,Baker,Gonzalez,Nelson,Carter,Mitchell,Perez,Roberts,Turner,Phillips,Campbell,Parker,Evans,Edwards,Collins");
$list = explode(",","Smith,Johnson,Williams,Jones,Brown,Davis,Miller,Wilson,Moore,Taylor,Anderson,Thomas,Jackson,White,Harris,Martin,Thompson,Garcia,Martinez,Robinson,Clark,Rodriguez,Lewis,Lee,Walker,Hall,Allen,Young,Hernandez,King,Wright,Lopez,Hill,Scott,Green,Adams,Baker,Gonzalez,Nelson,Carter,Mitchell,Perez,Roberts,Turner,Phillips,Campbell,Parker,Evans,Edwards,Collins,Dexter,Dennis,Menace,Jesus,Bart,Homer,Dan,Bub,Sparkster,Yanni");
shuffle($list);
return(current($list));
}
@@ -189,11 +189,9 @@ class Dummy {
}
public function username() {
$n = rand(1,50);
$n = rand(1,300);
$f = substr($this->firstname(),0,1);
$l = $this->lastname();
if ($n <= 30) { $l .= $n; }
$l = $this->lastname() .$n;
return(strtolower($f.$l));