start transfering things to billing_ prefix

This commit is contained in:
Justin Shreve 2016-03-17 12:39:29 -07:00
parent 15e37ab66a
commit e65ab6adec
5 changed files with 120 additions and 119 deletions

View File

@ -58,10 +58,10 @@ class WC_Cache_Helper {
$customer = new WC_Customer();
$customer->load_session();
$location = array();
$location['country'] = $customer->get_country();
$location['state'] = $customer->get_state();
$location['postcode'] = $customer->get_postcode();
$location['city'] = $customer->get_city();
$location['country'] = $customer->get_billing_country();
$location['state'] = $customer->get_billing_state();
$location['postcode'] = $customer->get_billing_postcode();
$location['city'] = $customer->get_billing_city();
return substr( md5( implode( '', $location ) ), 0, 12 );
}

View File

@ -806,11 +806,11 @@ class WC_Checkout {
switch ( $input ) {
case 'billing_country' :
return apply_filters( 'default_checkout_country', WC()->customer->get_country() ? WC()->customer->get_country() : WC()->countries->get_base_country(), 'billing' );
return apply_filters( 'default_checkout_country', WC()->customer->get_billing_country() ? WC()->customer->get_billing_country() : WC()->countries->get_base_country(), 'billing' );
case 'billing_state' :
return apply_filters( 'default_checkout_state', WC()->customer->get_calculated_shipping() ? WC()->customer->get_state() : '', 'billing' );
return apply_filters( 'default_checkout_state', WC()->customer->get_calculated_shipping() ? WC()->customer->get_billing_state() : '', 'billing' );
case 'billing_postcode' :
return apply_filters( 'default_checkout_postcode', WC()->customer->get_postcode() ? WC()->customer->get_postcode() : '', 'billing' );
return apply_filters( 'default_checkout_postcode', WC()->customer->get_billing_postcode() ? WC()->customer->get_billing_postcode() : '', 'billing' );
case 'shipping_country' :
return apply_filters( 'default_checkout_country', WC()->customer->get_shipping_country() ? WC()->customer->get_shipping_country() : WC()->countries->get_base_country(), 'shipping' );
case 'shipping_state' :

View File

@ -34,12 +34,12 @@ class WC_Customer extends WC_Legacy_Customer {
'password' => '', // write only
'date_created' => '', // read only
'date_modified' => '', // read only
'postcode' => '',
'city' => '',
'address_1' => '',
'address_2' => '',
'state' => '',
'country' => '',
'billing_postcode' => '',
'billing_city' => '',
'billing_address_1' => '',
'billing_address_2' => '',
'billing_state' => '',
'billing_country' => '',
'shipping_postcode' => '',
'shipping_city' => '',
'shipping_address_1' => '',
@ -56,8 +56,8 @@ class WC_Customer extends WC_Legacy_Customer {
* @var array
*/
protected $_session_keys = array(
'postcode', 'city', 'address_1', 'address', 'address_2', 'state', 'country',
'shipping_postcode', 'shipping_city', 'shipping_address_1', 'shipping_address',
'billing_postcode', 'billing_city', 'billing_address_1', 'billing_address', 'billing_address_2',
'billing_state', 'billing_country', 'shipping_postcode', 'shipping_city', 'shipping_address_1', 'shipping_address',
'shipping_address_2', 'shipping_state', 'shipping_country', 'is_vat_exempt', 'calculated_shipping',
);
@ -282,56 +282,56 @@ class WC_Customer extends WC_Legacy_Customer {
* Gets customer postcode.
* @return string
*/
public function get_postcode() {
return wc_format_postcode( $this->_data['postcode'], $this->get_country() );
public function get_billing_postcode() {
return wc_format_postcode( $this->_data['billing_postcode'], $this->get_billing_country() );
}
/**
* Get customer city.
* @return string
*/
public function get_city() {
return $this->_data['city'];
public function get_billing_city() {
return $this->_data['billing_city'];
}
/**
* Get customer address.
* @return string
*/
public function get_address() {
return $this->_data['address_1'];
public function get_billing_address() {
return $this->_data['billing_address_1'];
}
/**
* Get customer address.
* @return string
*/
public function get_address_1() {
return $this->get_address();
public function get_billing_address_1() {
return $this->get_billing_address();
}
/**
* Get customer's second address.
* @return string
*/
public function get_address_2() {
return $this->_data['address_2'];
public function get_billing_address_2() {
return $this->_data['billing_address_2'];
}
/**
* Get customer state.
* @return string
*/
public function get_state() {
return $this->_data['state'];
public function get_billing_state() {
return $this->_data['billing_state'];
}
/**
* Get customer country.
* @return string
*/
public function get_country() {
return $this->_data['country'];
public function get_billing_country() {
return $this->_data['billing_country'];
}
/**
@ -425,10 +425,10 @@ class WC_Customer extends WC_Legacy_Customer {
$postcode = WC()->countries->get_base_postcode();
$city = WC()->countries->get_base_city();
} elseif ( 'billing' === $tax_based_on ) {
$country = $this->get_country();
$state = $this->get_state();
$postcode = $this->get_postcode();
$city = $this->get_city();
$country = $this->get_billing_country();
$state = $this->get_billing_state();
$postcode = $this->get_billing_postcode();
$city = $this->get_billing_city();
} else {
$country = $this->get_shipping_country();
$state = $this->get_shipping_state();
@ -581,12 +581,12 @@ class WC_Customer extends WC_Legacy_Customer {
* Set customer address to match shop base address.
* @since 2.7.0
*/
public function set_address_to_base() {
public function set_billing_address_to_base() {
$base = wc_get_customer_default_location();
$this->_data['country'] = $base['country'];
$this->_data['state'] = $base['state'];
$this->_data['postcode'] = '';
$this->_data['city'] = '';
$this->_data['billing_country'] = $base['country'];
$this->_data['billing_state'] = $base['state'];
$this->_data['billing_postcode'] = '';
$this->_data['billing_city'] = '';
}
/**
@ -622,67 +622,67 @@ class WC_Customer extends WC_Legacy_Customer {
* @param string $postcode
* @param string $city
*/
public function set_location( $country, $state, $postcode = '', $city = '' ) {
$this->_data['country'] = $country;
$this->_data['state'] = $state;
$this->_data['postcode'] = $postcode;
$this->_data['city'] = $city;
public function set_billing_location( $country, $state, $postcode = '', $city = '' ) {
$this->_data['billing_country'] = $country;
$this->_data['billing_state'] = $state;
$this->_data['billing_postcode'] = $postcode;
$this->_data['billing_city'] = $city;
}
/**
* Set customer country.
* @param mixed $country
*/
public function set_country( $country ) {
$this->_data['country'] = $country;
public function set_billing_country( $country ) {
$this->_data['billing_country'] = $country;
}
/**
* Set customer state.
* @param mixed $state
*/
public function set_state( $state ) {
$this->_data['state'] = $state;
public function set_billing_state( $state ) {
$this->_data['billing_state'] = $state;
}
/**
* Sets customer postcode.
* @param mixed $postcode
*/
public function set_postcode( $postcode ) {
$this->_data['postcode'] = $postcode;
public function set_billing_postcode( $postcode ) {
$this->_data['billing_postcode'] = $postcode;
}
/**
* Sets customer city.
* @param mixed $city
*/
public function set_city( $city ) {
$this->_data['city'] = $city;
public function set_billing_city( $city ) {
$this->_data['billing_city'] = $city;
}
/**
* Set customer address.
* @param mixed $address
*/
public function set_address( $address ) {
$this->_data['address_1'] = $address;
public function set_billing_address( $address ) {
$this->_data['billing_address_1'] = $address;
}
/**
* Set customer address.
* @param mixed $address
*/
public function set_address_1( $address ) {
$this->set_address( $address );
public function set_billing_address_1( $address ) {
$this->set_billing_address( $address );
}
/**
* Set customer's second address.
* @param mixed $address
*/
public function set_address_2( $address ) {
$this->_data['address_2'] = $address;
public function set_billing_address_2( $address ) {
$this->_data['billing_address_2'] = $address;
}
/**
@ -810,12 +810,12 @@ class WC_Customer extends WC_Legacy_Customer {
unset( $this->_data['password'] );
if ( $customer_id ) {
$this->_data['id'] = $customer_id;
update_user_meta( $this->get_id(), 'billing_postcode', $this->get_postcode() );
update_user_meta( $this->get_id(), 'billing_city', $this->get_city() );
update_user_meta( $this->get_id(), 'billing_address_1', $this->get_address() );
update_user_meta( $this->get_id(), 'billing_address_2', $this->get_address_2() );
update_user_meta( $this->get_id(), 'billing_state', $this->get_state() );
update_user_meta( $this->get_id(), 'billing_country', $this->get_country() );
update_user_meta( $this->get_id(), 'billing_postcode', $this->get_billing_postcode() );
update_user_meta( $this->get_id(), 'billing_city', $this->get_billing_city() );
update_user_meta( $this->get_id(), 'billing_address_1', $this->get_billing_address() );
update_user_meta( $this->get_id(), 'billing_address_2', $this->get_billing_address_2() );
update_user_meta( $this->get_id(), 'billing_state', $this->get_billing_state() );
update_user_meta( $this->get_id(), 'billing_country', $this->get_billing_country() );
update_user_meta( $this->get_id(), 'shipping_postcode', $this->get_shipping_postcode() );
update_user_meta( $this->get_id(), 'shipping_city', $this->get_shipping_city() );
update_user_meta( $this->get_id(), 'shipping_address_1', $this->get_shipping_address() );
@ -848,8 +848,12 @@ class WC_Customer extends WC_Legacy_Customer {
if ( ! empty( $data ) ) {
$pull_from_db = false;
foreach ( $this->_session_keys as $session_key ) {
if ( ! empty( $data[ $session_key ] ) && is_callable( array( $this, "set_{$session_key}" ) ) ) {
$this->{"set_{$session_key}"}( $data[ $session_key ] );
$function_key = $session_key;
if ( 'billing_' === substr( $session_key, 0, 8 ) ) {
$session_key = str_replace( 'billing_', '', $session_key );
}
if ( ! empty( $data[ $session_key ] ) && is_callable( array( $this, "set_{$function_key}" ) ) ) {
$this->{"set_{$function_key}"}( $data[ $session_key ] );
}
}
}
@ -865,16 +869,11 @@ class WC_Customer extends WC_Legacy_Customer {
}
foreach ( array_keys( $this->_data ) as $key ) {
if ( ! $pull_from_db && ! empty( $data[ $key ] ) ) {
continue;
}
if ( in_array( $key, array( 'postcode', 'city', 'address_1', 'address_2', 'state', 'country' ) ) ) {
$meta_value = get_user_meta( $id, 'billing_' . $key, true );
} else {
$meta_value = get_user_meta( $id, $key, true );
}
$meta_value = get_user_meta( $id, $key, true );
if ( $meta_value && is_callable( array( $this, "set_{$key}" ) ) ) {
$this->{"set_{$key}"}( $meta_value );
}
@ -944,23 +943,24 @@ class WC_Customer extends WC_Legacy_Customer {
$default = wc_get_customer_default_location();
// Set some defaults if some of our values are still not set.
if ( empty( $this->get_country() ) ) {
$this->set_country( $default['country'] );
if ( empty( $this->get_billing_country() ) ) {
$this->set_billing_country( $default['country'] );
}
if ( empty( $this->get_shipping_country() ) ) {
$this->set_shipping_country( $this->get_country() );
$this->set_shipping_country( $this->get_billing_country() );
}
if ( empty( $this->get_state() ) ) {
$this->set_state( $default['state'] );
if ( empty( $this->get_billing_state() ) ) {
$this->set_billing_state( $default['state'] );
}
if ( empty( $this->get_shipping_state() ) ) {
$this->set_shipping_state( $this->get_state() );
$this->set_shipping_state( $this->get_billing_state() );
}
unset( $this->_data['password'] ); // password is write only, never ever read it
error_log( print_r ( $this, 1 ) );
}
/**
@ -977,12 +977,12 @@ class WC_Customer extends WC_Legacy_Customer {
unset( $this->_data['password'] );
}
update_user_meta( $this->get_id(), 'billing_postcode', $this->get_postcode() );
update_user_meta( $this->get_id(), 'billing_city', $this->get_city() );
update_user_meta( $this->get_id(), 'billing_address_1', $this->get_address() );
update_user_meta( $this->get_id(), 'billing_address_2', $this->get_address_2() );
update_user_meta( $this->get_id(), 'billing_state', $this->get_state() );
update_user_meta( $this->get_id(), 'billing_country', $this->get_country() );
update_user_meta( $this->get_id(), 'billing_postcode', $this->get_billing_postcode() );
update_user_meta( $this->get_id(), 'billing_city', $this->get_billing_city() );
update_user_meta( $this->get_id(), 'billing_address_1', $this->get_billing_address() );
update_user_meta( $this->get_id(), 'billing_address_2', $this->get_billing_address_2() );
update_user_meta( $this->get_id(), 'billing_state', $this->get_billing_state() );
update_user_meta( $this->get_id(), 'billing_country', $this->get_billing_country() );
update_user_meta( $this->get_id(), 'shipping_postcode', $this->get_shipping_postcode() );
update_user_meta( $this->get_id(), 'shipping_city', $this->get_shipping_city() );
update_user_meta( $this->get_id(), 'shipping_address_1', $this->get_shipping_address() );

View File

@ -44,12 +44,13 @@ class WC_Helper_Customer {
*/
public static function create_customer() {
$customer = new WC_Customer();
$customer->set_country( 'US' );
$customer->set_state( 'PA' );
$customer->set_postcode( '19123' );
$customer->set_city( 'Philadelphia' );
$customer->set_address( '123 South Street' );
$customer->set_address_2( 'Apt 1' );
$customer->set_billing_country( 'US' );
$customer->set_first_name( 'Justin' );
$customer->set_billing_state( 'PA' );
$customer->set_billing_postcode( '19123' );
$customer->set_billing_city( 'Philadelphia' );
$customer->set_billing_address( '123 South Street' );
$customer->set_billing_address_2( 'Apt 1' );
$customer->set_shipping_country( 'US' );
$customer->set_shipping_state( 'PA' );
$customer->set_shipping_postcode( '19123' );

View File

@ -33,16 +33,16 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
$customer = \WC_Helper_Customer::create_customer();
$customer_id = $customer->get_id();
$this->assertEquals( 'test@woo.local', $customer->get_email() );
$this->assertEquals( 'Apt 1', $customer->get_address_2() );
$this->assertEquals( 'Apt 1', $customer->get_billing_address_2() );
$customer->set_email( 'test@wc.local' );
$customer->set_first_name( 'Justin' );
$customer->set_address_2( 'Apt 5' );
$customer->set_billing_address_2( 'Apt 5' );
$customer->update();
$customer = new \WC_Customer( $customer_id ); // so we can read fresh copies from the DB
$this->assertEquals( 'test@wc.local', $customer->get_email() );
$this->assertEquals( 'Justin', $customer->get_first_name() );
$this->assertEquals( 'Apt 5', $customer->get_address_2() );
$this->assertEquals( 'Apt 5', $customer->get_billing_address_2() );
}
@ -135,13 +135,13 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
$customer = \WC_Helper_Customer::create_customer();
$this->assertEquals( $customer->get_id(), $customer->id );
$this->assertEquals( $customer->get_country(), $customer->country );
$this->assertEquals( $customer->get_state(), $customer->state );
$this->assertEquals( $customer->get_postcode(), $customer->postcode );
$this->assertEquals( $customer->get_city(), $customer->city );
$this->assertEquals( $customer->get_address(), $customer->address );
$this->assertEquals( $customer->get_address(), $customer->address_1 );
$this->assertEquals( $customer->get_address_2(), $customer->address_2 );
$this->assertEquals( $customer->get_billing_country(), $customer->country );
$this->assertEquals( $customer->get_billing_state(), $customer->state );
$this->assertEquals( $customer->get_billing_postcode(), $customer->postcode );
$this->assertEquals( $customer->get_billing_city(), $customer->city );
$this->assertEquals( $customer->get_billing_address(), $customer->address );
$this->assertEquals( $customer->get_billing_address(), $customer->address_1 );
$this->assertEquals( $customer->get_billing_address_2(), $customer->address_2 );
$this->assertEquals( $customer->get_shipping_country(), $customer->shipping_country );
$this->assertEquals( $customer->get_shipping_state(), $customer->shipping_state );
$this->assertEquals( $customer->get_shipping_postcode(), $customer->shipping_postcode );
@ -173,9 +173,9 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
$standard_getters_and_setters = array(
'username' => 'test', 'email' => 'test@woo.local', 'first_name' => 'Bob', 'last_name' => 'tester',
'role' => 'customer', 'last_order_id' => 5, 'last_order_date' => $time, 'orders_count' => 2,
'total_spent' => 10.57, 'date_created' => $time, 'date_modified' => $time, 'postcode' => 11010,
'city' => 'New York', 'address' => '123 Main St.', 'address_1' => '123 Main St.', 'address_2' => 'Apt 2', 'state' => 'NY',
'country' => 'US', 'shipping_state' => 'NY', 'shipping_postcode' => 11011, 'shipping_city' =>
'total_spent' => 10.57, 'date_created' => $time, 'date_modified' => $time, 'billing_postcode' => 11010,
'billing_city' => 'New York', 'billing_address' => '123 Main St.', 'billing_address_1' => '123 Main St.', 'billing_address_2' => 'Apt 2', 'billing_state' => 'NY',
'billing_country' => 'US', 'shipping_state' => 'NY', 'shipping_postcode' => 11011, 'shipping_city' =>
'New York', 'shipping_address' => '123 Main St.', 'shipping_address_1' => '123 Main St.',
'shipping_address_2' => 'Apt 2', 'is_vat_exempt' => true, 'calculated_shipping' => true,
'is_paying_customer' => true
@ -261,7 +261,7 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
$last = get_user_meta( $customer_id, 'last_update', true );
sleep(1);
$this->assertEquals( $last, $customer->get_date_modified() );
$customer->set_address( '1234 Some St.' );
$customer->set_billing_address( '1234 Some St.' );
$customer->save();
$update = get_user_meta( $customer_id, 'last_update', true );
$this->assertEquals( $update, $customer->get_date_modified() );
@ -336,12 +336,12 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
*/
public function test_customer_set_address_to_base() {
$customer = \WC_Helper_Customer::create_customer();
$customer->set_address_to_base();
$customer->set_billing_address_to_base();
$base = wc_get_customer_default_location();
$this->assertEquals( $base['country'], $customer->get_country() );
$this->assertEquals( $base['state'], $customer->get_state() );
$this->assertEmpty( $customer->get_postcode() );
$this->assertEmpty( $customer->get_city() );
$this->assertEquals( $base['country'], $customer->get_billing_country() );
$this->assertEquals( $base['state'], $customer->get_billing_state() );
$this->assertEmpty( $customer->get_billing_postcode() );
$this->assertEmpty( $customer->get_billing_city() );
}
/**
@ -364,11 +364,11 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
*/
public function test_customer_set_location() {
$customer = \WC_Helper_Customer::create_customer();
$customer->set_location( 'US', 'OH', '12345', 'Cleveland' );
$this->assertEquals( 'US', $customer->get_country() );
$this->assertEquals( 'OH', $customer->get_state() );
$this->assertEquals( '12345', $customer->get_postcode() );
$this->assertEquals( 'Cleveland', $customer->get_city() );
$customer->set_billing_location( 'US', 'OH', '12345', 'Cleveland' );
$this->assertEquals( 'US', $customer->get_billing_country() );
$this->assertEquals( 'OH', $customer->get_billing_state() );
$this->assertEquals( '12345', $customer->get_billing_postcode() );
$this->assertEquals( 'Cleveland', $customer->get_billing_city() );
}
/**
@ -392,7 +392,7 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
$customer = \WC_Helper_Customer::create_customer();
$this->assertTrue( $customer->is_customer_outside_base() );
update_option( 'woocommerce_tax_based_on', 'base' );
$customer->set_address_to_base();
$customer->set_billing_address_to_base();
$this->assertFalse( $customer->is_customer_outside_base() );
}
@ -406,16 +406,16 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
$this->assertNotEmpty( $session->get_id() );
$this->assertFalse( is_numeric( $session->get_id() ) );
$this->assertEquals( '19123', $session->get_postcode() );
$this->assertEquals( '123 South Street', $session->get_address() );
$this->assertEquals( 'Philadelphia', $session->get_city() );
$this->assertEquals( '19123', $session->get_billing_postcode() );
$this->assertEquals( '123 South Street', $session->get_billing_address() );
$this->assertEquals( 'Philadelphia', $session->get_billing_city() );
$session->set_address( '124 South Street' );
$session->set_billing_address( '124 South Street' );
$session->save_to_session();
$session = new \WC_Customer();
$session->load_session();
$this->assertEquals( '124 South Street', $session->get_address() );
$this->assertEquals( '124 South Street', $session->get_billing_address() );
}
/**