Don't save to the database if we are working with sessions, save to the session when save() is called instead.

This commit is contained in:
Justin Shreve 2016-08-04 11:39:34 -07:00
parent 1bc9da3e91
commit f4353f6aa9
2 changed files with 16 additions and 1 deletions

View File

@ -1012,10 +1012,16 @@ class WC_Customer extends WC_Legacy_Customer {
}
/**
* Save data (either create or update depending on if we are working on an existing customer).
* Save data. Create when creating a new user/class, update when editing
* an existing user, and save session when working on a logged out guest
* session.
* @since 2.7.0
*/
public function save() {
if ( $this->_from_session && ! $this->_is_user ) {
$this->save_session_if_changed();
return;
}
if ( ! $this->_is_user ) {
$this->create();
} else {

View File

@ -416,6 +416,15 @@ class CustomerCRUD extends \WC_Unit_Test_Case {
$session = new \WC_Customer();
$session->load_session();
$this->assertEquals( '124 South Street', $session->get_billing_address() );
$session = new \WC_Customer();
$session->load_session();
$session->set_billing_postcode( '32191' );
$session->save();
// should still be session ID, not a created row, since we are working with guests/sessions
$this->assertFalse( is_numeric( $session->get_id() ) );
$this->assertEquals( '32191' , $session->get_billing_postcode() );
}
/**