Skip to content

Commit

Permalink
Merge branch 'master' into crud-orders
Browse files Browse the repository at this point in the history
# Conflicts:
#	includes/abstracts/abstract-wc-order.php
#	includes/admin/meta-boxes/class-wc-meta-box-order-data.php
  • Loading branch information
mikejolley committed Mar 4, 2016
2 parents 8a1d102 + 7580f18 commit 1b3a737
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 120 deletions.
63 changes: 32 additions & 31 deletions assets/js/admin/wc-enhanced-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,32 @@ jQuery( function( $ ) {
return m;
},
ajax: {
url: wc_enhanced_select_params.ajax_url,
dataType: 'json',
quietMillis: 250,
data: function( term ) {
return {
url: wc_enhanced_select_params.ajax_url,
dataType: 'json',
quietMillis: 250,
data: function( term ) {
return {
term: term,
action: $( this ).data( 'action' ) || 'woocommerce_json_search_products_and_variations',
security: wc_enhanced_select_params.search_products_nonce,
exclude: $( this ).data( 'exclude' ),
include: $( this ).data( 'include' ),
limit: $( this ).data( 'limit' )
};
},
results: function( data ) {
var terms = [];
if ( data ) {
};
},
results: function( data ) {
var terms = [];
if ( data ) {
$.each( data, function( id, text ) {
terms.push( { id: id, text: text } );
});
}
return {
results: terms
};
},
cache: true
}
return {
results: terms
};
},
cache: true
}
};

if ( $( this ).data( 'multiple' ) === true ) {
Expand Down Expand Up @@ -158,30 +158,31 @@ jQuery( function( $ ) {
return m;
},
ajax: {
url: wc_enhanced_select_params.ajax_url,
dataType: 'json',
quietMillis: 250,
data: function( term ) {
return {
url: wc_enhanced_select_params.ajax_url,
dataType: 'json',
quietMillis: 250,
data: function( term ) {
return {
term: term,
action: 'woocommerce_json_search_customers',
security: wc_enhanced_select_params.search_customers_nonce
};
},
results: function( data ) {
var terms = [];
if ( data ) {
security: wc_enhanced_select_params.search_customers_nonce,
exclude: $( this ).data( 'exclude' )
};
},
results: function( data ) {
var terms = [];
if ( data ) {
$.each( data, function( id, text ) {
terms.push({
id: id,
text: text
});
});
}
return { results: terms };
},
cache: true
}
return { results: terms };
},
cache: true
}
};
if ( $( this ).data( 'multiple' ) === true ) {
select2_args.multiple = true;
Expand Down
5 changes: 5 additions & 0 deletions includes/abstracts/abstract-wc-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ public function set_status( $new_status ) {
$old_status = $this->get_status();
$new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;

// If the old status is unknown (e.g. draft) assume its pending for action usage.
if ( ! in_array( 'wc-' . $old_status, array_keys( wc_get_order_statuses() ) ) ) {
$old_status = 'pending';
}

if ( in_array( 'wc-' . $new_status, array_keys( wc_get_order_statuses() ) ) && $new_status !== $old_status ) {
$this->_data['status'] = 'wc-' . $new_status;
} else {
Expand Down
28 changes: 14 additions & 14 deletions includes/admin/class-wc-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
exit;
}

if ( ! class_exists( 'WC_Admin_Settings' ) ) :

/**
* WC_Admin_Settings.
* WC_Admin_Settings Class.
*/
class WC_Admin_Settings {

Expand Down Expand Up @@ -388,7 +388,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
<?php
}
?>
</select> <?php echo $description; ?>
</select> <?php echo $description; ?>
</td>
</tr><?php
break;
Expand Down Expand Up @@ -477,7 +477,7 @@ class="<?php echo esc_attr( $value['class'] ); ?>"
name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
type="checkbox"
class="<?php echo esc_attr(isset($value['class']) ? $value['class'] : ''); ?>"
class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
value="1"
<?php checked( $option_value, 'yes'); ?>
<?php echo implode( ' ', $custom_attributes ); ?>
Expand Down Expand Up @@ -602,7 +602,7 @@ class="<?php echo esc_attr(isset($value['class']) ? $value['class'] : ''); ?>"
}
}
?>
</select> <?php echo ( $description ) ? $description : ''; ?> </br><a class="select_all button" href="#"><?php _e( 'Select all', 'woocommerce' ); ?></a> <a class="select_none button" href="#"><?php _e( 'Select none', 'woocommerce' ); ?></a>
</select> <?php echo ( $description ) ? $description : ''; ?> <br /><a class="select_all button" href="#"><?php _e( 'Select all', 'woocommerce' ); ?></a> <a class="select_none button" href="#"><?php _e( 'Select none', 'woocommerce' ); ?></a>
</td>
</tr><?php
break;
Expand All @@ -620,8 +620,8 @@ class="<?php echo esc_attr(isset($value['class']) ? $value['class'] : ''); ?>"
* given form field. Plugins can call this when implementing their own custom
* settings types.
*
* @param array $value The form field value array
* @returns array The description and tip as a 2 element array
* @param array $value The form field value array
* @return array The description and tip as a 2 element array
*/
public static function get_field_description( $value ) {
$description = '';
Expand Down Expand Up @@ -661,24 +661,24 @@ public static function get_field_description( $value ) {
*
* Loops though the woocommerce options array and outputs each field.
*
* @param array $options Opens array to output
* @param array $options Options array to output
* @return bool
*/
public static function save_fields( $options ) {
if ( empty( $_POST ) ) {
return false;
}

// Options to update will be stored here and saved later
// Options to update will be stored here and saved later.
$update_options = array();

// Loop options and get values to save
// Loop options and get values to save.
foreach ( $options as $option ) {
if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
continue;
}

// Get posted value
// Get posted value.
if ( strstr( $option['id'], '[' ) ) {
parse_str( $option['id'], $option_name_array );
$option_name = current( array_keys( $option_name_array ) );
Expand All @@ -690,7 +690,7 @@ public static function save_fields( $options ) {
$raw_value = isset( $_POST[ $option['id'] ] ) ? wp_unslash( $_POST[ $option['id'] ] ) : null;
}

// Format the value based on option type
// Format the value based on option type.
switch ( $option['type'] ) {
case 'checkbox' :
$value = is_null( $raw_value ) ? 'no' : 'yes';
Expand Down Expand Up @@ -759,13 +759,13 @@ public static function save_fields( $options ) {
}

/**
* Fire an action before saved..
* Fire an action before saved.
* @deprecated 2.4.0 - doesn't allow manipulation of values!
*/
do_action( 'woocommerce_update_option', $option );
}

// Save all options in our array
// Save all options in our array.
foreach ( $update_options as $name => $value ) {
update_option( $name, $value );
}
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-wc-admin-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function delete_term( $term_id ) {

$term_id = absint( $term_id );

if ( $term_id ) {
if ( $term_id && get_option( 'db_version' ) < 34370 ) {
$wpdb->delete( $wpdb->woocommerce_termmeta, array( 'woocommerce_term_id' => $term_id ), array( '%d' ) );
}
}
Expand Down
4 changes: 4 additions & 0 deletions includes/admin/meta-boxes/class-wc-meta-box-order-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ public static function save( $post_id, $post ) {

self::init_address_fields();

// Ensure gateways are loaded in case they need to insert data into the emails
WC()->payment_gateways();
WC()->shipping();

$order = wc_get_order( $post_id );
$order->set_customer_id( absint( $_POST['customer_user'] ) );
$order->set_transaction_id( wc_clean( $_POST['_transaction_id'] ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ function attributes_cmp( $a, $b ) {

if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $post_id, '_price', '' === $regular_price ? '' : wc_format_decimal( $regular_price ) );
update_post_meta( $post_id, '_sale_price', '' );
update_post_meta( $post_id, '_sale_price_dates_from', '' );
update_post_meta( $post_id, '_sale_price_dates_to', '' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function get_main_chart() {
$chart_data[ $category->term_id ]['category'] = $category->name;
$chart_data[ $category->term_id ]['data'] = $category_chart_data;

$index ++;
$index++;
}
?>
<div class="chart-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@

<h2><?php echo esc_html( $shipping_method->get_method_title() ); ?> <?php wc_back_link( __( 'Return to Shipping Methods', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping&zone_id=' . absint( $zone->get_zone_id() ) ) ); ?></h2>
<?php $shipping_method->admin_options(); ?>
<p class="submit"><input type="submit" class="button button-primary" name="save_method" value="<?php _e( 'Save changes', 'woocommerce' ); ?>" /></p>
<?php if ( ! isset( $GLOBALS['hide_save_button'] ) ) : ?>
<p class="submit"><input type="submit" class="button button-primary" name="save_method" value="<?php _e( 'Save changes', 'woocommerce' ); ?>" /></p>
<?php endif; ?>
<?php wp_nonce_field( 'woocommerce_save_method', 'woocommerce_save_method_nonce' ); ?>
4 changes: 3 additions & 1 deletion includes/api/class-wc-api-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,9 @@ public function delete_product_category( $id ) {
}

// When a term is deleted, delete its meta.
$wpdb->delete( $wpdb->woocommerce_termmeta, array( 'woocommerce_term_id' => $id ), array( '%d' ) );
if ( get_option( 'db_version' ) < 34370 ) {
$wpdb->delete( $wpdb->woocommerce_termmeta, array( 'woocommerce_term_id' => $id ), array( '%d' ) );
}

do_action( 'woocommerce_api_delete_product_category', $id, $this );

Expand Down
15 changes: 11 additions & 4 deletions includes/class-wc-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -1793,12 +1793,17 @@ public static function json_search_customers() {
die( -1 );
}

$term = wc_clean( stripslashes( $_GET['term'] ) );
$term = wc_clean( stripslashes( $_GET['term'] ) );
$exclude = array();

if ( empty( $term ) ) {
die();
}

if ( ! empty( $_GET['exclude'] ) ) {
$exclude = array_map( 'intval', explode( ',', $_GET['exclude'] ) );
}

$found_customers = array();

add_action( 'pre_user_query', array( __CLASS__, 'json_search_customer_name' ) );
Expand All @@ -1816,7 +1821,9 @@ public static function json_search_customers() {

if ( ! empty( $customers ) ) {
foreach ( $customers as $customer ) {
$found_customers[ $customer->ID ] = $customer->display_name . ' (#' . $customer->ID . ' &ndash; ' . sanitize_email( $customer->user_email ) . ')';
if ( ! in_array( $customer->ID, $exclude ) ) {
$found_customers[ $customer->ID ] = $customer->display_name . ' (#' . $customer->ID . ' &ndash; ' . sanitize_email( $customer->user_email ) . ')';
}
}
}

Expand Down Expand Up @@ -1974,7 +1981,7 @@ public static function refund_line_items() {
}

$order_id = absint( $_POST['order_id'] );
$refund_amount = wc_format_decimal( sanitize_text_field( $_POST['refund_amount'] ) );
$refund_amount = wc_format_decimal( sanitize_text_field( $_POST['refund_amount'] ), wc_get_price_decimals() );
$refund_reason = sanitize_text_field( $_POST['refund_reason'] );
$line_item_qtys = json_decode( sanitize_text_field( stripslashes( $_POST['line_item_qtys'] ) ), true );
$line_item_totals = json_decode( sanitize_text_field( stripslashes( $_POST['line_item_totals'] ) ), true );
Expand All @@ -1988,7 +1995,7 @@ public static function refund_line_items() {
// Validate that the refund can occur
$order = wc_get_order( $order_id );
$order_items = $order->get_items();
$max_refund = wc_format_decimal( $order->get_total() - $order->get_total_refunded() );
$max_refund = wc_format_decimal( $order->get_total() - $order->get_total_refunded(), wc_get_price_decimals() );

if ( ! $refund_amount || $max_refund < $refund_amount || 0 > $refund_amount ) {
throw new exception( __( 'Invalid refund amount', 'woocommerce' ) );
Expand Down
28 changes: 18 additions & 10 deletions includes/class-wc-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private static function get_schema() {
*/
$max_index_length = 191;

return "
$tables = "
CREATE TABLE {$wpdb->prefix}woocommerce_sessions (
session_id bigint(20) NOT NULL AUTO_INCREMENT,
session_key char(32) NOT NULL,
Expand Down Expand Up @@ -402,15 +402,6 @@ private static function get_schema() {
PRIMARY KEY (attribute_id),
KEY attribute_name (attribute_name($max_index_length))
) $collate;
CREATE TABLE {$wpdb->prefix}woocommerce_termmeta (
meta_id bigint(20) NOT NULL auto_increment,
woocommerce_term_id bigint(20) NOT NULL,
meta_key varchar(255) default NULL,
meta_value longtext NULL,
PRIMARY KEY (meta_id),
KEY woocommerce_term_id (woocommerce_term_id),
KEY meta_key (meta_key($max_index_length))
) $collate;
CREATE TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions (
permission_id bigint(20) NOT NULL auto_increment,
download_id varchar(32) NOT NULL,
Expand Down Expand Up @@ -495,6 +486,23 @@ private static function get_schema() {
PRIMARY KEY (instance_id)
) $collate;
";

// Term meta is only needed for old installs.
if ( ! function_exists( 'get_term_meta' ) ) {
$tables .= "
CREATE TABLE {$wpdb->prefix}woocommerce_termmeta (
meta_id bigint(20) NOT NULL auto_increment,
woocommerce_term_id bigint(20) NOT NULL,
meta_key varchar(255) default NULL,
meta_value longtext NULL,
PRIMARY KEY (meta_id),
KEY woocommerce_term_id (woocommerce_term_id),
KEY meta_key (meta_key($max_index_length))
) $collate;
";
}

return $tables;
}

/**
Expand Down
Loading

0 comments on commit 1b3a737

Please sign in to comment.