From 502fa930ba4ea3194d1daf3e6b6e1153801879f1 Mon Sep 17 00:00:00 2001 From: Chris Lam Date: Wed, 1 Feb 2017 11:58:54 +1300 Subject: [PATCH 1/9] Fixes #13035 - Added table alias so that the column names in the `ORDER BY` and `GROUP BY` clauses are not ambiguous --- includes/class-wc-tax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php index 23576e0c69c..73d956a3058 100644 --- a/includes/class-wc-tax.php +++ b/includes/class-wc-tax.php @@ -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 ); From 54e35648e27aa3a5140a927e7c1db8b4f50553c4 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 1 Feb 2017 10:11:19 +0100 Subject: [PATCH 2/9] Fixed legacy date format --- includes/abstracts/abstract-wc-legacy-order.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/abstracts/abstract-wc-legacy-order.php b/includes/abstracts/abstract-wc-legacy-order.php index 825b59528a5..5ecf926099a 100644 --- a/includes/abstracts/abstract-wc-legacy-order.php +++ b/includes/abstracts/abstract-wc-legacy-order.php @@ -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 ) { From 010a208e884f9cb7bf69568df1a27eac74db72a5 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Wed, 1 Feb 2017 12:44:51 -0800 Subject: [PATCH 3/9] Merge WC_Data::$extra_data in WC_Data::__construct Rather than requiring child classes to merge it as well as define it. If it's not defined in a child class, then the merge call will have no effect as it will be an the empty array set in WC_Data, if they do define it, WC_Data will now take care of it automatically rather than requiring manually merging it in the child class's constructor before it has any effect on that objects data. This helps reduce duplicate code by removing this from child classes, and in some cases, being able to remove the child constructor definitions entirely. It also avoids a gotcha for developers setting their own $extra_data values only to find they aren't being set on the $data property. --- includes/abstracts/abstract-wc-data.php | 3 +++ includes/class-wc-order-item.php | 1 - includes/class-wc-order-refund.php | 10 ---------- includes/class-wc-product-external.php | 9 --------- includes/class-wc-product-grouped.php | 9 --------- 5 files changed, 3 insertions(+), 29 deletions(-) diff --git a/includes/abstracts/abstract-wc-data.php b/includes/abstracts/abstract-wc-data.php index 1d8b23326f0..d1af89ef3ed 100644 --- a/includes/abstracts/abstract-wc-data.php +++ b/includes/abstracts/abstract-wc-data.php @@ -83,6 +83,9 @@ abstract class WC_Data { * @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; } diff --git a/includes/class-wc-order-item.php b/includes/class-wc-order-item.php index 51bb8b77a3a..6631b002bd8 100644 --- a/includes/class-wc-order-item.php +++ b/includes/class-wc-order-item.php @@ -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 ) { diff --git a/includes/class-wc-order-refund.php b/includes/class-wc-order-refund.php index 7ac150d7a89..db9e9823d9b 100644 --- a/includes/class-wc-order-refund.php +++ b/includes/class-wc-order-refund.php @@ -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 diff --git a/includes/class-wc-product-external.php b/includes/class-wc-product-external.php index 7ef27817ee9..1d81376a193 100644 --- a/includes/class-wc-product-external.php +++ b/includes/class-wc-product-external.php @@ -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 diff --git a/includes/class-wc-product-grouped.php b/includes/class-wc-product-grouped.php index 87bac32435f..d67279b65e8 100644 --- a/includes/class-wc-product-grouped.php +++ b/includes/class-wc-product-grouped.php @@ -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 From 8431b2ac861d171c0574b5dcdc649533aa578d64 Mon Sep 17 00:00:00 2001 From: Brent Shepherd Date: Fri, 3 Feb 2017 14:53:03 -0800 Subject: [PATCH 4/9] Remove 'edit' param on get_visible_children() The WC_Product_Variable::get_visible_children() method accepts no parameters. --- includes/class-wc-product-variable.php | 2 +- .../class-wc-product-variable-data-store-cpt.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/class-wc-product-variable.php b/includes/class-wc-product-variable.php index b431ac0b70b..bc17c3efead 100644 --- a/includes/class-wc-product-variable.php +++ b/includes/class-wc-product-variable.php @@ -455,7 +455,7 @@ class WC_Product_Variable extends WC_Product { $data_store->sync_stock_status( $product ); self::sync_attributes( $product ); // Legacy update of attributes. - do_action( 'woocommerce_variable_product_sync', $product->get_id(), $product->get_visible_children( 'edit' ), $save ); + do_action( 'woocommerce_variable_product_sync', $product->get_id(), $product->get_visible_children(), $save ); if ( $save ) { $product->save(); diff --git a/includes/data-stores/class-wc-product-variable-data-store-cpt.php b/includes/data-stores/class-wc-product-variable-data-store-cpt.php index 1c2d4e6d1b9..2962b9f771f 100644 --- a/includes/data-stores/class-wc-product-variable-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variable-data-store-cpt.php @@ -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' ); From 91cd8999898b8faf69d8bca0e1f598a30a0f362a Mon Sep 17 00:00:00 2001 From: Jaydeep Date: Mon, 6 Feb 2017 14:35:55 +0530 Subject: [PATCH 5/9] Fixed issue ref #13067 --- includes/admin/meta-boxes/class-wc-meta-box-order-data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/meta-boxes/class-wc-meta-box-order-data.php b/includes/admin/meta-boxes/class-wc-meta-box-order-data.php index f4246af4025..6e5a89b9cef 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-order-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-order-data.php @@ -263,7 +263,7 @@ class WC_Meta_Box_Order_Data { } ?>

From 5a0b70f291966c777343e730ec1bf45dbddd8405 Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Mon, 6 Feb 2017 14:41:19 +0100 Subject: [PATCH 6/9] Fix empty string case for `WC_Order::get_total_shipping` --- includes/class-wc-shipping.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index de80a500b6a..c242de60d21 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -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(); } From b19be41994226d9c3aa438a5520f2a7748d5133a Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 6 Feb 2017 17:06:18 +0000 Subject: [PATCH 7/9] Added since to WC_Data docblocks Closes #13056 --- includes/abstracts/abstract-wc-data.php | 59 ++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/includes/abstracts/abstract-wc-data.php b/includes/abstracts/abstract-wc-data.php index d1af89ef3ed..6aa8e4a6d9d 100644 --- a/includes/abstracts/abstract-wc-data.php +++ b/includes/abstracts/abstract-wc-data.php @@ -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,18 +84,23 @@ 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 ) { @@ -92,7 +113,7 @@ abstract class WC_Data { /** * Get the data store. * - * @since 2.7.0 + * @since 2.7.0 * @return object */ public function get_data_store() { @@ -101,6 +122,8 @@ abstract class WC_Data { /** * Returns the unique ID for this object. + * + * @since 2.6.0 * @return int */ public function get_id() { @@ -110,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 */ @@ -125,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() { @@ -143,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() { @@ -151,6 +178,8 @@ abstract class WC_Data { /** * Returns all data for this object. + * + * @since 2.6.0 * @return array */ public function get_data() { @@ -160,7 +189,7 @@ abstract class WC_Data { /** * Returns array of expected data keys for this object. * - * @since 2.7.0 + * @since 2.7.0 * @return array */ public function get_data_keys() { @@ -170,7 +199,7 @@ abstract class WC_Data { /** * Returns all "extra" data keys for an object (for sub objects like product types). * - * @since 2.7.0 + * @since 2.7.0 * @return array */ public function get_extra_data_keys() { @@ -179,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 ) { @@ -187,6 +218,7 @@ abstract class WC_Data { /** * Get All Meta Data. + * * @since 2.6.0 * @return array */ @@ -197,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 @@ -225,6 +258,7 @@ abstract class WC_Data { /** * Set all meta data from array. + * * @since 2.6.0 * @param array $data Key/Value pairs */ @@ -246,6 +280,7 @@ abstract class WC_Data { /** * Add meta data. + * * @since 2.6.0 * @param string $key Meta key * @param string $value Meta value @@ -264,7 +299,8 @@ abstract class WC_Data { /** * Update meta data by key or ID, if provided. - * @since 2.6.0 + * + * @since 2.6.0 * @param string $key * @param string $value * @param int $meta_id @@ -284,6 +320,7 @@ abstract class WC_Data { /** * Delete meta data. + * * @since 2.6.0 * @param array $key Meta key */ @@ -298,6 +335,7 @@ abstract class WC_Data { /** * Delete meta data. + * * @since 2.6.0 * @param int $mid Meta ID */ @@ -374,6 +412,7 @@ abstract class WC_Data { /** * Update Meta Data in the database. + * * @since 2.6.0 */ public function save_meta_data() { @@ -402,6 +441,8 @@ abstract class WC_Data { /** * Set ID. + * + * @since 2.7.0 * @param int $id */ public function set_id( $id ) { @@ -410,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; @@ -419,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 ) { @@ -427,6 +472,8 @@ abstract class WC_Data { /** * Get object read property. + * + * @since 2.7.0 * @return boolean */ public function get_object_read() { @@ -437,7 +484,8 @@ abstract class WC_Data { * Set a collection of props in one go, collect any errors, and return the result. * 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 */ public function set_props( $props, $context = 'set' ) { @@ -544,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. From 23cc478bc925f77ad7de845bf1b92def71c8b540 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 6 Feb 2017 17:59:31 +0000 Subject: [PATCH 8/9] Exit after redirect to prevent incorrect headers being set by wp_die --- includes/class-wc-ajax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-ajax.php b/includes/class-wc-ajax.php index ca6cc854b8f..0a4955503ef 100644 --- a/includes/class-wc-ajax.php +++ b/includes/class-wc-ajax.php @@ -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; } /** From c61b4bf35c4b4fd44f3aa6e83b765755470b13a5 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 6 Feb 2017 18:11:54 +0000 Subject: [PATCH 9/9] wc_add_to_cart_message_html filter which passes in full array of products and qty Closes #12824 --- includes/wc-cart-functions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index ba159bfb1fe..3bd5fae9141 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -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( '%s %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 ) { return $message;