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. * ID for this object.
*
* @since 2.7.0
* @var int * @var int
*/ */
protected $id = 0; protected $id = 0;
/** /**
* Core data for this object. Name value pairs (name + default value). * Core data for this object. Name value pairs (name + default value).
*
* @since 2.7.0
* @var array * @var array
*/ */
protected $data = array(); protected $data = array();
/** /**
* Core data changes for this object. * Core data changes for this object.
*
* @since 2.7.0
* @var array * @var array
*/ */
protected $changes = array(); protected $changes = array();
/** /**
* This is false until the object is read from the DB. * This is false until the object is read from the DB.
*
* @since 2.7.0
* @var bool * @var bool
*/ */
protected $object_read = false; protected $object_read = false;
/** /**
* This is the name of this object type. * This is the name of this object type.
*
* @since 2.7.0
* @var string * @var string
*/ */
protected $object_type = 'data'; protected $object_type = 'data';
@ -49,18 +59,24 @@ abstract class WC_Data {
* Extra data for this object. Name value pairs (name + default value). * Extra data for this object. Name value pairs (name + default value).
* Used as a standard way for sub classes (like product types) to add * Used as a standard way for sub classes (like product types) to add
* additional information to an inherited class. * additional information to an inherited class.
*
* @since 2.7.0
* @var array * @var array
*/ */
protected $extra_data = array(); protected $extra_data = array();
/** /**
* Set to _data on construct so we can track and reset data if needed. * Set to _data on construct so we can track and reset data if needed.
*
* @since 2.7.0
* @var array * @var array
*/ */
protected $default_data = array(); protected $default_data = array();
/** /**
* Contains a reference to the data store for this class. * Contains a reference to the data store for this class.
*
* @since 2.7.0
* @var object * @var object
*/ */
protected $data_store; protected $data_store;
@ -68,28 +84,36 @@ abstract class WC_Data {
/** /**
* Stores meta in cache for future reads. * Stores meta in cache for future reads.
* A group must be set to to enable caching. * A group must be set to to enable caching.
*
* @since 2.7.0
* @var string * @var string
*/ */
protected $cache_group = ''; protected $cache_group = '';
/** /**
* Stores additonal meta data. * Stores additonal meta data.
*
* @since 2.7.0
* @var array * @var array
*/ */
protected $meta_data = null; protected $meta_data = null;
/** /**
* Default constructor. * Default constructor.
*
* @param int|object|array $read ID to load from the DB (optional) or already queried data. * @param int|object|array $read ID to load from the DB (optional) or already queried data.
*/ */
public function __construct( $read = 0 ) { public function __construct( $read = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
$this->default_data = $this->data; $this->default_data = $this->data;
} }
/** /**
* Get the data store. * Get the data store.
* *
* @since 2.7.0 * @since 2.7.0
* @return object * @return object
*/ */
public function get_data_store() { public function get_data_store() {
@ -98,6 +122,8 @@ abstract class WC_Data {
/** /**
* Returns the unique ID for this object. * Returns the unique ID for this object.
*
* @since 2.6.0
* @return int * @return int
*/ */
public function get_id() { public function get_id() {
@ -107,6 +133,7 @@ abstract class WC_Data {
/** /**
* Delete an object, set the ID to 0, and return result. * Delete an object, set the ID to 0, and return result.
* *
* @since 2.6.0
* @param bool $force_delete * @param bool $force_delete
* @return bool result * @return bool result
*/ */
@ -122,6 +149,7 @@ abstract class WC_Data {
/** /**
* Save should create or update based on object existance. * Save should create or update based on object existance.
* *
* @since 2.6.0
* @return int * @return int
*/ */
public function save() { public function save() {
@ -140,6 +168,8 @@ abstract class WC_Data {
/** /**
* Change data to JSON format. * Change data to JSON format.
*
* @since 2.6.0
* @return string Data in JSON format. * @return string Data in JSON format.
*/ */
public function __toString() { public function __toString() {
@ -148,6 +178,8 @@ abstract class WC_Data {
/** /**
* Returns all data for this object. * Returns all data for this object.
*
* @since 2.6.0
* @return array * @return array
*/ */
public function get_data() { public function get_data() {
@ -157,7 +189,7 @@ abstract class WC_Data {
/** /**
* Returns array of expected data keys for this object. * Returns array of expected data keys for this object.
* *
* @since 2.7.0 * @since 2.7.0
* @return array * @return array
*/ */
public function get_data_keys() { public function get_data_keys() {
@ -167,7 +199,7 @@ abstract class WC_Data {
/** /**
* Returns all "extra" data keys for an object (for sub objects like product types). * Returns all "extra" data keys for an object (for sub objects like product types).
* *
* @since 2.7.0 * @since 2.7.0
* @return array * @return array
*/ */
public function get_extra_data_keys() { public function get_extra_data_keys() {
@ -176,6 +208,8 @@ abstract class WC_Data {
/** /**
* Filter null meta values from array. * Filter null meta values from array.
*
* @since 2.7.0
* @return bool * @return bool
*/ */
protected function filter_null_meta( $meta ) { protected function filter_null_meta( $meta ) {
@ -184,6 +218,7 @@ abstract class WC_Data {
/** /**
* Get All Meta Data. * Get All Meta Data.
*
* @since 2.6.0 * @since 2.6.0
* @return array * @return array
*/ */
@ -194,6 +229,7 @@ abstract class WC_Data {
/** /**
* Get Meta Data by Key. * Get Meta Data by Key.
*
* @since 2.6.0 * @since 2.6.0
* @param string $key * @param string $key
* @param bool $single return first found meta with key, or all with $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. * Set all meta data from array.
*
* @since 2.6.0 * @since 2.6.0
* @param array $data Key/Value pairs * @param array $data Key/Value pairs
*/ */
@ -243,6 +280,7 @@ abstract class WC_Data {
/** /**
* Add meta data. * Add meta data.
*
* @since 2.6.0 * @since 2.6.0
* @param string $key Meta key * @param string $key Meta key
* @param string $value Meta value * @param string $value Meta value
@ -261,7 +299,8 @@ abstract class WC_Data {
/** /**
* Update meta data by key or ID, if provided. * Update meta data by key or ID, if provided.
* @since 2.6.0 *
* @since 2.6.0
* @param string $key * @param string $key
* @param string $value * @param string $value
* @param int $meta_id * @param int $meta_id
@ -281,6 +320,7 @@ abstract class WC_Data {
/** /**
* Delete meta data. * Delete meta data.
*
* @since 2.6.0 * @since 2.6.0
* @param array $key Meta key * @param array $key Meta key
*/ */
@ -295,6 +335,7 @@ abstract class WC_Data {
/** /**
* Delete meta data. * Delete meta data.
*
* @since 2.6.0 * @since 2.6.0
* @param int $mid Meta ID * @param int $mid Meta ID
*/ */
@ -371,6 +412,7 @@ abstract class WC_Data {
/** /**
* Update Meta Data in the database. * Update Meta Data in the database.
*
* @since 2.6.0 * @since 2.6.0
*/ */
public function save_meta_data() { public function save_meta_data() {
@ -399,6 +441,8 @@ abstract class WC_Data {
/** /**
* Set ID. * Set ID.
*
* @since 2.7.0
* @param int $id * @param int $id
*/ */
public function set_id( $id ) { public function set_id( $id ) {
@ -407,6 +451,8 @@ abstract class WC_Data {
/** /**
* Set all props to default values. * Set all props to default values.
*
* @since 2.7.0
*/ */
public function set_defaults() { public function set_defaults() {
$this->data = $this->default_data; $this->data = $this->default_data;
@ -416,6 +462,8 @@ abstract class WC_Data {
/** /**
* Set object read property. * Set object read property.
*
* @since 2.7.0
* @param boolean $read * @param boolean $read
*/ */
public function set_object_read( $read = true ) { public function set_object_read( $read = true ) {
@ -424,6 +472,8 @@ abstract class WC_Data {
/** /**
* Get object read property. * Get object read property.
*
* @since 2.7.0
* @return boolean * @return boolean
*/ */
public function get_object_read() { public function get_object_read() {
@ -434,7 +484,8 @@ abstract class WC_Data {
* Set a collection of props in one go, collect any errors, and return the result. * Set a collection of props in one go, collect any errors, and return the result.
* Only sets using public methods. * Only sets using public methods.
* *
* @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. * @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 * @return WP_Error|bool
*/ */
public function set_props( $props, $context = 'set' ) { public function set_props( $props, $context = 'set' ) {
@ -541,6 +592,7 @@ abstract class WC_Data {
* When invalid data is found, throw an exception unless reading from the DB. * When invalid data is found, throw an exception unless reading from the DB.
* *
* @throws WC_Data_Exception * @throws WC_Data_Exception
* @since 2.7.0
* @param string $code Error code. * @param string $code Error code.
* @param string $message Error message. * @param string $message Error message.
* @param int $http_status_code HTTP status code. * @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' ); wc_doing_it_wrong( $key, 'Order properties should not be accessed directly.', '2.7' );
if ( 'completed_date' === $key ) { 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 ) { } elseif ( 'paid_date' === $key ) {
return $this->get_date_paid(); return $this->get_date_paid();
} elseif ( 'modified_date' === $key ) { } 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 ) { } elseif ( 'order_date' === $key ) {
return $this->get_date_created(); return date( 'Y-m-d H:i:s', $this->get_date_created() );
} elseif ( 'id' === $key ) { } elseif ( 'id' === $key ) {
return $this->get_id(); return $this->get_id();
} elseif ( 'post' === $key ) { } 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"> <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> </select>
</p> </p>
<?php do_action( 'woocommerce_admin_order_data_after_order_details', $order ); ?> <?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_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_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 * @param int|object|array $item ID to load from the DB, or WC_Order_Item Object
*/ */
public function __construct( $item = 0 ) { public function __construct( $item = 0 ) {
$this->data = array_merge( $this->data, $this->extra_data );
parent::__construct( $item ); parent::__construct( $item );
if ( $item instanceof WC_Order_Item ) { if ( $item instanceof WC_Order_Item ) {

View File

@ -38,16 +38,6 @@ class WC_Order_Refund extends WC_Abstract_Order {
'refunded_by' => 0, '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.) * Get internal type (post type.)
* @return string * @return string

View File

@ -26,15 +26,6 @@ class WC_Product_External extends WC_Product {
'button_text' => '', '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. * Get internal type.
* @return string * @return string

View File

@ -25,15 +25,6 @@ class WC_Product_Grouped extends WC_Product {
'children' => array(), '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. * Get internal type.
* @return string * @return string

View File

@ -238,7 +238,7 @@ class WC_Shipping {
* @param array $packages multi-dimensional array of cart items to calc shipping for * @param array $packages multi-dimensional array of cart items to calc shipping for
*/ */
public function calculate_shipping( $packages = array() ) { public function calculate_shipping( $packages = array() ) {
$this->shipping_total = null; $this->shipping_total = 0;
$this->shipping_taxes = array(); $this->shipping_taxes = array();
$this->packages = array(); $this->packages = array();
@ -393,7 +393,7 @@ class WC_Shipping {
*/ */
public function reset_shipping() { public function reset_shipping() {
unset( WC()->session->chosen_shipping_methods ); unset( WC()->session->chosen_shipping_methods );
$this->shipping_total = null; $this->shipping_total = 0;
$this->shipping_taxes = array(); $this->shipping_taxes = array();
$this->packages = 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 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 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 ) . " WHERE 1=1 AND " . implode( ' AND ', $criteria ) . "
GROUP BY tax_rate_id GROUP BY tax_rates.tax_rate_id
ORDER BY tax_rate_priority ORDER BY tax_rates.tax_rate_priority
" ); " );
$found_rates = self::sort_rates( $found_rates ); $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 ) { public function child_has_weight( $product ) {
global $wpdb; 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; 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 ) { public function child_has_dimensions( $product ) {
global $wpdb; 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; 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 ) { public function child_is_in_stock( $product ) {
global $wpdb; 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; $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; 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 ) { public function sync_price( &$product ) {
global $wpdb; 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(); $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' ); delete_post_meta( $product->get_id(), '_price' );

View File

@ -82,7 +82,6 @@ function wc_get_raw_referer() {
/** /**
* Add to cart messages. * Add to cart messages.
* *
* @access public
* @param int|array $products * @param int|array $products
* @param bool $show_qty Should qty's be shown? Added in 2.6.0 * @param bool $show_qty Should qty's be shown? Added in 2.6.0
* @param bool $return Return message rather than add it. * @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 ) ); $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 ) );
} }
$message = apply_filters( 'wc_add_to_cart_message', $message, $product_id ); 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 ) { if ( $return ) {
return $message; return $message;