Merge pull request #1 from woothemes/master

Merge woothemes latest.
This commit is contained in:
Luke Carbis 2014-05-21 09:12:21 +10:00
commit cdb1e6149d
5 changed files with 74 additions and 36 deletions

View File

@ -555,21 +555,22 @@ class WC_Settings_Tax extends WC_Settings_Page {
if ( $state == '*' ) if ( $state == '*' )
$state = ''; $state = '';
$wpdb->insert( $tax_rate = array(
$wpdb->prefix . "woocommerce_tax_rates", 'tax_rate_country' => $country,
array( 'tax_rate_state' => $state,
'tax_rate_country' => $country, 'tax_rate' => $rate,
'tax_rate_state' => $state, 'tax_rate_name' => $name,
'tax_rate' => $rate, 'tax_rate_priority' => $priority,
'tax_rate_name' => $name, 'tax_rate_compound' => $compound,
'tax_rate_priority' => $priority, 'tax_rate_shipping' => $shipping,
'tax_rate_compound' => $compound, 'tax_rate_order' => $i,
'tax_rate_shipping' => $shipping, 'tax_rate_class' => sanitize_title( $current_class )
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
)
); );
do_action( 'woocommerce_tax_rate_added', $tax_rate );
$wpdb->insert( $wpdb->prefix . "woocommerce_tax_rates", $tax_rate );
$tax_rate_id = $wpdb->insert_id; $tax_rate_id = $wpdb->insert_id;
if ( ! empty( $postcode ) ) { if ( ! empty( $postcode ) ) {
@ -625,8 +626,11 @@ class WC_Settings_Tax extends WC_Settings_Page {
$tax_rate_id = absint( $key ); $tax_rate_id = absint( $key );
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) { if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
do_action( 'woocommerce_tax_rate_deleted', $tax_rate_id );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) ); $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
continue; continue;
} }
@ -648,21 +652,25 @@ class WC_Settings_Tax extends WC_Settings_Page {
if ( $state == '*' ) if ( $state == '*' )
$state = ''; $state = '';
$tax_rate = array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
);
do_action( 'woocommerce_tax_rate_updated', $tax_rate );
$wpdb->update( $wpdb->update(
$wpdb->prefix . "woocommerce_tax_rates", $wpdb->prefix . "woocommerce_tax_rates",
$tax_rate,
array( array(
'tax_rate_country' => $country, 'tax_rate_id' => $tax_rate_id
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
),
array(
'tax_rate_id' => $tax_rate_id
) )
); );

View File

@ -644,7 +644,7 @@ class WC_Checkout {
WC()->session->set( 'reload_checkout', true ); WC()->session->set( 'reload_checkout', true );
// Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering // Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering
WC()->cart->calculate_totals(); WC()->cart->calculate_totals();
// Add customer info from other billing fields // Add customer info from other billing fields
if ( $this->posted['billing_first_name'] && apply_filters( 'woocommerce_checkout_update_customer_data', true, $this ) ) { if ( $this->posted['billing_first_name'] && apply_filters( 'woocommerce_checkout_update_customer_data', true, $this ) ) {

View File

@ -69,6 +69,10 @@ class WC_Session_Handler extends WC_Session {
add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_cookie' ), 10 ); add_action( 'woocommerce_set_cart_cookies', array( $this, 'set_customer_session_cookie' ), 10 );
add_action( 'woocommerce_cleanup_sessions', array( $this, 'cleanup_sessions' ), 10 ); add_action( 'woocommerce_cleanup_sessions', array( $this, 'cleanup_sessions' ), 10 );
add_action( 'shutdown', array( $this, 'save_data' ), 20 ); add_action( 'shutdown', array( $this, 'save_data' ), 20 );
add_action( 'clear_auth_cookie', array( $this, 'destroy_session' ) );
if ( ! is_user_logged_in() ) {
add_action( 'woocommerce_thankyou', array( $this, 'destroy_session' ) );
}
} }
/** /**
@ -111,16 +115,20 @@ class WC_Session_Handler extends WC_Session {
} }
/** /**
* generate_customer_id function. * Generate a unique customer ID for guests, or return user ID if logged in.
*
* Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID.
* *
* @access public * @access public
* @return mixed * @return int|string
*/ */
public function generate_customer_id() { public function generate_customer_id() {
if ( is_user_logged_in() ) { if ( is_user_logged_in() ) {
return get_current_user_id(); return get_current_user_id();
} else { } else {
return wp_generate_password( 32, false ); require_once( ABSPATH . 'wp-includes/class-phpass.php');
$hasher = new PasswordHash( 8, false );
return md5( $hasher->get_random_bytes( 32 ) );
} }
} }
@ -180,6 +188,29 @@ class WC_Session_Handler extends WC_Session {
} }
} }
/**
* Destroy all session data
*/
public function destroy_session() {
// Clear cookie
wc_setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, apply_filters( 'wc_session_use_secure_cookie', false ) );
// Delete session
$session_option = '_wc_session_' . $this->_customer_id;
$session_expiry_option = '_wc_session_expires_' . $this->_customer_id;
delete_option( $session_option );
delete_option( $session_expiry_option );
// Clear cart
wc_empty_cart();
// Clear data
$this->_data = array();
$this->_dirty = false;
$this->_customer_id = $this->generate_customer_id();
}
/** /**
* cleanup_sessions function. * cleanup_sessions function.
* *

View File

@ -34,13 +34,11 @@ add_filter( 'woocommerce_add_to_cart_validation', 'wc_protected_product_add_to_c
* @return void * @return void
*/ */
function wc_empty_cart() { function wc_empty_cart() {
if ( ! isset( WC()->cart ) || WC()->cart == '' ) if ( ! isset( WC()->cart ) || WC()->cart == '' ) {
WC()->cart = new WC_Cart(); WC()->cart = new WC_Cart();
}
WC()->cart->empty_cart( false ); WC()->cart->empty_cart( false );
} }
add_action( 'wp_logout', 'wc_empty_cart' );
/** /**
* Load the cart upon login * Load the cart upon login

View File

@ -136,6 +136,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - Added the possibility to translate the edit-address endpoint slug. * Tweak - Added the possibility to translate the edit-address endpoint slug.
* Tweak - Removed all the_content filter in favor to wpautop() and do_shortcode(). * Tweak - Removed all the_content filter in favor to wpautop() and do_shortcode().
* Tweak - Send IPN email notifications to new order email. * Tweak - Send IPN email notifications to new order email.
* Tweak - Clear and wipe session data on logout and end of checkout for guests.
* Dev - Introduce `woocommerce_valid_order_statuses_for_payment_complete` filter. * Dev - Introduce `woocommerce_valid_order_statuses_for_payment_complete` filter.
* Dev - Introduce `woocommerce_thankyou_order_received_text` filter. * Dev - Introduce `woocommerce_thankyou_order_received_text` filter.
* Dev - Introduce `woocommerce_product_backorders_allowed` filter. * Dev - Introduce `woocommerce_product_backorders_allowed` filter.