Merge branch 'master' into variable_product_sync_filters

Conflicts:
	includes/class-wc-product-variable.php
This commit is contained in:
Brent Shepherd 2017-02-07 13:43:02 -08:00
commit dcec16f749
12 changed files with 77 additions and 50 deletions

View File

@ -17,30 +17,40 @@ abstract class WC_Data {
/**
* ID for this object.
*
* @since 2.7.0
* @var int
*/
protected $id = 0;
/**
* Core data for this object. Name value pairs (name + default value).
*
* @since 2.7.0
* @var array
*/
protected $data = array();
/**
* Core data changes for this object.
*
* @since 2.7.0
* @var array
*/
protected $changes = array();
/**
* This is false until the object is read from the DB.
*
* @since 2.7.0
* @var bool
*/
protected $object_read = false;
/**
* This is the name of this object type.
*
* @since 2.7.0
* @var string
*/
protected $object_type = 'data';
@ -49,18 +59,24 @@ abstract class WC_Data {
* Extra data for this object. Name value pairs (name + default value).
* Used as a standard way for sub classes (like product types) to add
* additional information to an inherited class.
*
* @since 2.7.0
* @var array
*/
protected $extra_data = array();
/**
* Set to _data on construct so we can track and reset data if needed.
*
* @since 2.7.0
* @var array
*/
protected $default_data = array();
/**
* Contains a reference to the data store for this class.
*
* @since 2.7.0
* @var object
*/
protected $data_store;
@ -68,21 +84,29 @@ abstract class WC_Data {
/**
* Stores meta in cache for future reads.
* A group must be set to to enable caching.
*
* @since 2.7.0
* @var string
*/
protected $cache_group = '';
/**
* Stores additonal meta data.
*
* @since 2.7.0
* @var array
*/
protected $meta_data = null;
/**
* Default constructor.
*
* @param int|object|array $read ID to load from the DB (optional) or already queried data.
*/
public function __construct( $read = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
$this->default_data = $this->data;
}
@ -98,6 +122,8 @@ abstract class WC_Data {
/**
* Returns the unique ID for this object.
*
* @since 2.6.0
* @return int
*/
public function get_id() {
@ -107,6 +133,7 @@ abstract class WC_Data {
/**
* Delete an object, set the ID to 0, and return result.
*
* @since 2.6.0
* @param bool $force_delete
* @return bool result
*/
@ -122,6 +149,7 @@ abstract class WC_Data {
/**
* Save should create or update based on object existance.
*
* @since 2.6.0
* @return int
*/
public function save() {
@ -140,6 +168,8 @@ abstract class WC_Data {
/**
* Change data to JSON format.
*
* @since 2.6.0
* @return string Data in JSON format.
*/
public function __toString() {
@ -148,6 +178,8 @@ abstract class WC_Data {
/**
* Returns all data for this object.
*
* @since 2.6.0
* @return array
*/
public function get_data() {
@ -176,6 +208,8 @@ abstract class WC_Data {
/**
* Filter null meta values from array.
*
* @since 2.7.0
* @return bool
*/
protected function filter_null_meta( $meta ) {
@ -184,6 +218,7 @@ abstract class WC_Data {
/**
* Get All Meta Data.
*
* @since 2.6.0
* @return array
*/
@ -194,6 +229,7 @@ abstract class WC_Data {
/**
* Get Meta Data by Key.
*
* @since 2.6.0
* @param string $key
* @param bool $single return first found meta with key, or all with $key
@ -222,6 +258,7 @@ abstract class WC_Data {
/**
* Set all meta data from array.
*
* @since 2.6.0
* @param array $data Key/Value pairs
*/
@ -243,6 +280,7 @@ abstract class WC_Data {
/**
* Add meta data.
*
* @since 2.6.0
* @param string $key Meta key
* @param string $value Meta value
@ -261,6 +299,7 @@ abstract class WC_Data {
/**
* Update meta data by key or ID, if provided.
*
* @since 2.6.0
* @param string $key
* @param string $value
@ -281,6 +320,7 @@ abstract class WC_Data {
/**
* Delete meta data.
*
* @since 2.6.0
* @param array $key Meta key
*/
@ -295,6 +335,7 @@ abstract class WC_Data {
/**
* Delete meta data.
*
* @since 2.6.0
* @param int $mid Meta ID
*/
@ -371,6 +412,7 @@ abstract class WC_Data {
/**
* Update Meta Data in the database.
*
* @since 2.6.0
*/
public function save_meta_data() {
@ -399,6 +441,8 @@ abstract class WC_Data {
/**
* Set ID.
*
* @since 2.7.0
* @param int $id
*/
public function set_id( $id ) {
@ -407,6 +451,8 @@ abstract class WC_Data {
/**
* Set all props to default values.
*
* @since 2.7.0
*/
public function set_defaults() {
$this->data = $this->default_data;
@ -416,6 +462,8 @@ abstract class WC_Data {
/**
* Set object read property.
*
* @since 2.7.0
* @param boolean $read
*/
public function set_object_read( $read = true ) {
@ -424,6 +472,8 @@ abstract class WC_Data {
/**
* Get object read property.
*
* @since 2.7.0
* @return boolean
*/
public function get_object_read() {
@ -434,6 +484,7 @@ abstract class WC_Data {
* Set a collection of props in one go, collect any errors, and return the result.
* Only sets using public methods.
*
* @since 2.7.0
* @param array $props Key value pairs to set. Key is the prop and should map to a setter function name.
* @return WP_Error|bool
*/
@ -541,6 +592,7 @@ abstract class WC_Data {
* When invalid data is found, throw an exception unless reading from the DB.
*
* @throws WC_Data_Exception
* @since 2.7.0
* @param string $code Error code.
* @param string $message Error message.
* @param int $http_status_code HTTP status code.

View File

@ -402,13 +402,13 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '2.7' );
if ( 'completed_date' === $key ) {
return $this->get_date_completed();
return date( 'Y-m-d H:i:s', $this->get_date_completed() );
} elseif ( 'paid_date' === $key ) {
return $this->get_date_paid();
} elseif ( 'modified_date' === $key ) {
return $this->get_date_modified();
return date( 'Y-m-d H:i:s', $this->get_date_modified() );
} elseif ( 'order_date' === $key ) {
return $this->get_date_created();
return date( 'Y-m-d H:i:s', $this->get_date_created() );
} elseif ( 'id' === $key ) {
return $this->get_id();
} elseif ( 'post' === $key ) {

View File

@ -263,7 +263,7 @@ class WC_Meta_Box_Order_Data {
}
?>
<select class="wc-customer-search" id="customer_user" name="customer_user" data-placeholder="<?php esc_attr_e( 'Guest', 'woocommerce' ); ?>" data-allow_clear="true">
<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( $user_string ); ?><option>
<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo htmlspecialchars( $user_string ); ?></option>
</select>
</p>
<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?>

View File

@ -429,7 +429,7 @@ class WC_AJAX {
}
wp_safe_redirect( wp_get_referer() ? remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), wp_get_referer() ) : admin_url( 'edit.php?post_type=product' ) );
wp_die();
exit;
}
/**
@ -447,7 +447,7 @@ class WC_AJAX {
}
wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'edit.php?post_type=shop_order' ) );
wp_die();
exit;
}
/**

View File

@ -57,7 +57,6 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
* @param int|object|array $item ID to load from the DB, or WC_Order_Item Object
*/
public function __construct( $item = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $item );
if ( $item instanceof WC_Order_Item ) {

View File

@ -38,16 +38,6 @@ class WC_Order_Refund extends WC_Abstract_Order {
'refunded_by' => 0,
);
/**
* Extend the abstract _data properties and then read the order object.
*
* @param int|object|WC_Order $read Order to init.
*/
public function __construct( $read = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $read );
}
/**
* Get internal type (post type.)
* @return string

View File

@ -26,15 +26,6 @@ class WC_Product_External extends WC_Product {
'button_text' => '',
);
/**
* Merges external product data into the parent object.
* @param int|WC_Product|object $product Product to init.
*/
public function __construct( $product = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $product );
}
/**
* Get internal type.
* @return string

View File

@ -25,15 +25,6 @@ class WC_Product_Grouped extends WC_Product {
'children' => array(),
);
/**
* Merges grouped product data into the parent object.
* @param int|WC_Product|object $product Product to init.
*/
public function __construct( $product = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $product );
}
/**
* Get internal type.
* @return string

View File

@ -238,7 +238,7 @@ class WC_Shipping {
* @param array $packages multi-dimensional array of cart items to calc shipping for
*/
public function calculate_shipping( $packages = array() ) {
$this->shipping_total = null;
$this->shipping_total = 0;
$this->shipping_taxes = array();
$this->packages = array();
@ -393,7 +393,7 @@ class WC_Shipping {
*/
public function reset_shipping() {
unset( WC()->session->chosen_shipping_methods );
$this->shipping_total = null;
$this->shipping_total = 0;
$this->shipping_taxes = array();
$this->packages = array();
}

View File

@ -410,8 +410,8 @@ class WC_Tax {
LEFT OUTER JOIN {$wpdb->prefix}woocommerce_tax_rate_locations as locations ON tax_rates.tax_rate_id = locations.tax_rate_id
LEFT OUTER JOIN {$wpdb->prefix}woocommerce_tax_rate_locations as locations2 ON tax_rates.tax_rate_id = locations2.tax_rate_id
WHERE 1=1 AND " . implode( ' AND ', $criteria ) . "
GROUP BY tax_rate_id
ORDER BY tax_rate_priority
GROUP BY tax_rates.tax_rate_id
ORDER BY tax_rates.tax_rate_priority
" );
$found_rates = self::sort_rates( $found_rates );

View File

@ -267,7 +267,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*/
public function child_has_weight( $product ) {
global $wpdb;
$children = $product->get_visible_children( 'edit' );
$children = $product->get_visible_children();
return $children ? $wpdb->get_var( "SELECT 1 FROM $wpdb->postmeta WHERE meta_key = '_weight' AND meta_value > 0 AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : false;
}
@ -280,7 +280,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*/
public function child_has_dimensions( $product ) {
global $wpdb;
$children = $product->get_visible_children( 'edit' );
$children = $product->get_visible_children();
return $children ? $wpdb->get_var( "SELECT 1 FROM $wpdb->postmeta WHERE meta_key IN ( '_length', '_width', '_height' ) AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : false;
}
@ -293,7 +293,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
*/
public function child_is_in_stock( $product ) {
global $wpdb;
$children = $product->get_visible_children( 'edit' );
$children = $product->get_visible_children();
$oufofstock_children = $children ? $wpdb->get_var( "SELECT COUNT( post_id ) FROM $wpdb->postmeta WHERE meta_key = '_stock_status' AND meta_value = 'instock' AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) : 0;
return $children > $oufofstock_children;
}
@ -361,7 +361,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
public function sync_price( &$product ) {
global $wpdb;
$children = $product->get_visible_children( 'edit' );
$children = $product->get_visible_children();
$prices = $children ? array_unique( $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_price' AND post_id IN ( " . implode( ',', array_map( 'absint', $children ) ) . " )" ) ) : array();
delete_post_meta( $product->get_id(), '_price' );

View File

@ -82,7 +82,6 @@ function wc_get_raw_referer() {
/**
* Add to cart messages.
*
* @access public
* @param int|array $products
* @param bool $show_qty Should qty's be shown? Added in 2.6.0
* @param bool $return Return message rather than add it.
@ -116,7 +115,12 @@ function wc_add_to_cart_message( $products, $show_qty = false, $return = false )
$message = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( wc_get_page_permalink( 'cart' ) ), esc_html__( 'View cart', 'woocommerce' ), esc_html( $added_text ) );
}
if ( has_filter( 'wc_add_to_cart_message' ) ) {
wc_deprecated_function( 'The wc_add_to_cart_message filter', '2.7', 'wc_add_to_cart_message_html' );
$message = apply_filters( 'wc_add_to_cart_message', $message, $product_id );
}
$message = apply_filters( 'wc_add_to_cart_message_html', $message, $products );
if ( $return ) {
return $message;