Renamed table to wc_product_meta_lookup
This commit is contained in:
parent
519b29d734
commit
3309276e82
|
@ -825,13 +825,14 @@ CREATE TABLE {$wpdb->prefix}wc_download_log (
|
|||
KEY permission_id (permission_id),
|
||||
KEY timestamp (timestamp)
|
||||
) $collate;
|
||||
CREATE TABLE {$wpdb->prefix}wc_product_sorting (
|
||||
CREATE TABLE {$wpdb->prefix}wc_product_meta_lookup (
|
||||
`product_id` bigint(20) NOT NULL,
|
||||
`price` decimal(10,{$price_decimals}) NULL default NULL,
|
||||
`min_price` decimal(10,{$price_decimals}) NULL default NULL,
|
||||
`max_price` decimal(10,{$price_decimals}) NULL default NULL,
|
||||
`average_rating` decimal(10,2) NULL default 0,
|
||||
`total_sales` bigint(20) NULL default 0,
|
||||
`stock` bigint(20) NULL default NULL,
|
||||
PRIMARY KEY (`product_id`),
|
||||
KEY product_id_price (`product_id`,`max_price`,`min_price`),
|
||||
KEY product_id_average_rating (`product_id`,`average_rating`),
|
||||
|
@ -870,7 +871,7 @@ CREATE TABLE {$wpdb->prefix}woocommerce_termmeta (
|
|||
|
||||
$tables = array(
|
||||
"{$wpdb->prefix}wc_download_log",
|
||||
"{$wpdb->prefix}wc_product_sorting",
|
||||
"{$wpdb->prefix}wc_product_meta_lookup",
|
||||
"{$wpdb->prefix}wc_webhooks",
|
||||
"{$wpdb->prefix}woocommerce_api_keys",
|
||||
"{$wpdb->prefix}woocommerce_attribute_taxonomies",
|
||||
|
|
|
@ -543,7 +543,7 @@ class WC_Query {
|
|||
|
||||
$args['join'] = $this->append_product_sorting_table_join( $args['join'] );
|
||||
$args['where'] .= $wpdb->prepare(
|
||||
' AND wc_product_sorting.min_price >= %f AND wc_product_sorting.max_price <= %f ',
|
||||
' AND wc_product_meta_lookup.min_price >= %f AND wc_product_meta_lookup.max_price <= %f ',
|
||||
$min,
|
||||
$max
|
||||
);
|
||||
|
@ -558,7 +558,7 @@ class WC_Query {
|
|||
*/
|
||||
public function order_by_price_asc_post_clauses( $args ) {
|
||||
$args['join'] = $this->append_product_sorting_table_join( $args['join'] );
|
||||
$args['orderby'] = ' wc_product_sorting.min_price ASC, wc_product_sorting.product_id ASC ';
|
||||
$args['orderby'] = ' wc_product_meta_lookup.min_price ASC, wc_product_meta_lookup.product_id ASC ';
|
||||
return $args;
|
||||
}
|
||||
|
||||
|
@ -570,7 +570,7 @@ class WC_Query {
|
|||
*/
|
||||
public function order_by_price_desc_post_clauses( $args ) {
|
||||
$args['join'] = $this->append_product_sorting_table_join( $args['join'] );
|
||||
$args['orderby'] = ' wc_product_sorting.max_price DESC, wc_product_sorting.product_id DESC ';
|
||||
$args['orderby'] = ' wc_product_meta_lookup.max_price DESC, wc_product_meta_lookup.product_id DESC ';
|
||||
return $args;
|
||||
}
|
||||
|
||||
|
@ -584,7 +584,7 @@ class WC_Query {
|
|||
*/
|
||||
public function order_by_popularity_post_clauses( $args ) {
|
||||
$args['join'] = $this->append_product_sorting_table_join( $args['join'] );
|
||||
$args['orderby'] = ' wc_product_sorting.total_sales DESC, wc_product_sorting.product_id DESC ';
|
||||
$args['orderby'] = ' wc_product_meta_lookup.total_sales DESC, wc_product_meta_lookup.product_id DESC ';
|
||||
return $args;
|
||||
}
|
||||
|
||||
|
@ -596,12 +596,12 @@ class WC_Query {
|
|||
*/
|
||||
public function order_by_rating_post_clauses( $args ) {
|
||||
$args['join'] = $this->append_product_sorting_table_join( $args['join'] );
|
||||
$args['orderby'] = ' wc_product_sorting.average_rating DESC, wc_product_sorting.product_id DESC ';
|
||||
$args['orderby'] = ' wc_product_meta_lookup.average_rating DESC, wc_product_meta_lookup.product_id DESC ';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join wc_product_sorting to posts if not already joined.
|
||||
* Join wc_product_meta_lookup to posts if not already joined.
|
||||
*
|
||||
* @param string $sql SQL join.
|
||||
* @return string
|
||||
|
@ -609,8 +609,8 @@ class WC_Query {
|
|||
private function append_product_sorting_table_join( $sql ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! strstr( $sql, 'wc_product_sorting' ) ) {
|
||||
$sql .= " LEFT JOIN {$wpdb->wc_product_sorting} wc_product_sorting ON $wpdb->posts.ID = wc_product_sorting.product_id ";
|
||||
if ( ! strstr( $sql, 'wc_product_meta_lookup' ) ) {
|
||||
$sql .= " LEFT JOIN {$wpdb->wc_product_meta_lookup} wc_product_meta_lookup ON $wpdb->posts.ID = wc_product_meta_lookup.product_id ";
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
|
|
@ -659,8 +659,8 @@ final class WooCommerce {
|
|||
$wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta';
|
||||
$wpdb->tables[] = 'woocommerce_order_itemmeta';
|
||||
|
||||
$wpdb->wc_product_sorting = $wpdb->prefix . 'wc_product_sorting';
|
||||
$wpdb->tables[] = 'wc_product_sorting';
|
||||
$wpdb->wc_product_meta_lookup = $wpdb->prefix . 'wc_product_meta_lookup';
|
||||
$wpdb->tables[] = 'wc_product_meta_lookup';
|
||||
|
||||
if ( get_option( 'db_version' ) < 34370 ) {
|
||||
$wpdb->woocommerce_termmeta = $wpdb->prefix . 'woocommerce_termmeta';
|
||||
|
|
|
@ -625,7 +625,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
}
|
||||
|
||||
if ( array_intersect( $this->updated_props, array( 'regular_price', 'sale_price', 'date_on_sale_from', 'date_on_sale_to', 'total_sales', 'average_rating' ) ) ) {
|
||||
$this->update_lookup_table( $product->get_id(), 'wc_product_sorting' );
|
||||
$this->update_lookup_table( $product->get_id(), 'wc_product_meta_lookup' );
|
||||
}
|
||||
|
||||
// Trigger action so 3rd parties can deal with updated props.
|
||||
|
@ -1319,7 +1319,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
|
||||
wp_cache_delete( $product_id, 'post_meta' );
|
||||
|
||||
$this->update_lookup_table( $product_id, 'wc_product_sorting' );
|
||||
$this->update_lookup_table( $product_id, 'wc_product_meta_lookup' );
|
||||
|
||||
/**
|
||||
* Fire an action for this direct update so it can be detected by other code.
|
||||
|
@ -1855,7 +1855,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
* @return array
|
||||
*/
|
||||
protected function get_data_for_lookup_table( $id, $table ) {
|
||||
if ( 'wc_product_sorting' === $table ) {
|
||||
if ( 'wc_product_meta_lookup' === $table ) {
|
||||
$price_meta = (array) get_post_meta( $id, '_price', false );
|
||||
return array(
|
||||
'product_id' => absint( $id ),
|
||||
|
|
|
@ -87,7 +87,7 @@ class WC_Product_Grouped_Data_Store_CPT extends WC_Product_Data_Store_CPT implem
|
|||
add_post_meta( $product->get_id(), '_price', max( $child_prices ) );
|
||||
}
|
||||
|
||||
$this->update_lookup_table( $product->get_id(), 'wc_product_sorting' );
|
||||
$this->update_lookup_table( $product->get_id(), 'wc_product_meta_lookup' );
|
||||
|
||||
/**
|
||||
* Fire an action for this direct update so it can be detected by other code.
|
||||
|
|
|
@ -594,7 +594,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
}
|
||||
}
|
||||
|
||||
$this->update_lookup_table( $product->get_id(), 'wc_product_sorting' );
|
||||
$this->update_lookup_table( $product->get_id(), 'wc_product_meta_lookup' );
|
||||
|
||||
/**
|
||||
* Fire an action for this direct update so it can be detected by other code.
|
||||
|
|
|
@ -1275,7 +1275,7 @@ function wc_update_product_lookup_tables() {
|
|||
|
||||
$result = $wpdb->query(
|
||||
"
|
||||
INSERT IGNORE INTO {$wpdb->wc_product_sorting} (`product_id`, `price`, `min_price`, `max_price`, `average_rating`, `total_sales`)
|
||||
INSERT IGNORE INTO {$wpdb->wc_product_meta_lookup} (`product_id`, `price`, `min_price`, `max_price`, `average_rating`, `total_sales`)
|
||||
SELECT posts.ID, MIN(meta1.meta_value), MIN(meta1.meta_value), MAX(meta1.meta_value), meta2.meta_value, meta3.meta_value
|
||||
FROM {$wpdb->posts} posts
|
||||
LEFT JOIN {$wpdb->postmeta} meta1 ON posts.ID = meta1.post_id
|
||||
|
|
|
@ -151,7 +151,7 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
|
||||
$sql = "
|
||||
SELECT min( min_price ) as min_price, MAX( max_price ) as max_price
|
||||
FROM {$wpdb->wc_product_sorting}
|
||||
FROM {$wpdb->wc_product_meta_lookup}
|
||||
WHERE product_id IN (
|
||||
SELECT ID FROM {$wpdb->posts}
|
||||
" . $tax_query_sql['join'] . $meta_query_sql['join'] . "
|
||||
|
|
Loading…
Reference in New Issue