Correct table names and updater
This commit is contained in:
parent
ac51d1f1df
commit
7b6558e1df
|
@ -650,6 +650,8 @@ class WC_Install {
|
||||||
$collate = $wpdb->get_charset_collate();
|
$collate = $wpdb->get_charset_collate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$price_decimals = max( 2, absint( wc_get_price_decimals() ) );
|
||||||
|
|
||||||
$tables = "
|
$tables = "
|
||||||
CREATE TABLE {$wpdb->prefix}woocommerce_sessions (
|
CREATE TABLE {$wpdb->prefix}woocommerce_sessions (
|
||||||
session_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
session_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
@ -825,14 +827,14 @@ CREATE TABLE {$wpdb->prefix}wc_download_log (
|
||||||
) $collate;
|
) $collate;
|
||||||
CREATE TABLE {$wpdb->prefix}wc_product_sorting (
|
CREATE TABLE {$wpdb->prefix}wc_product_sorting (
|
||||||
`product_id` bigint(20) NOT NULL,
|
`product_id` bigint(20) NOT NULL,
|
||||||
`price` double NULL default NULL,
|
`price` decimal(10,{$price_decimals}) NULL default NULL,
|
||||||
`min_price` double NULL default NULL,
|
`min_price` decimal(10,{$price_decimals}) NULL default NULL,
|
||||||
`max_price` double NULL default NULL,
|
`max_price` decimal(10,{$price_decimals}) NULL default NULL,
|
||||||
`average_rating` float NULL default 0,
|
`average_rating` decimal(10,2) NULL default 0,
|
||||||
`total_sales` double NULL default 0,
|
`total_sales` bigint(20) NULL default 0,
|
||||||
PRIMARY KEY (`product_id`),
|
PRIMARY KEY (`product_id`),
|
||||||
KEY product_id_price (`product_id`,`max_price`,`min_price`)
|
KEY product_id_price (`product_id`,`max_price`,`min_price`),
|
||||||
KEY product_id_average_rating (`product_id`,`average_rating`)
|
KEY product_id_average_rating (`product_id`,`average_rating`),
|
||||||
KEY product_id_total_sales (`product_id`,`total_sales`)
|
KEY product_id_total_sales (`product_id`,`total_sales`)
|
||||||
) $collate;
|
) $collate;
|
||||||
";
|
";
|
||||||
|
|
|
@ -500,7 +500,7 @@ class WC_Query {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom query used to filter products by price from the wc_product_sorting table.
|
* Custom query used to filter products by price.
|
||||||
*
|
*
|
||||||
* @since 3.6.0
|
* @since 3.6.0
|
||||||
*
|
*
|
||||||
|
@ -610,7 +610,7 @@ class WC_Query {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if ( ! strstr( $sql, 'wc_product_sorting' ) ) {
|
if ( ! strstr( $sql, 'wc_product_sorting' ) ) {
|
||||||
$sql .= " LEFT JOIN {$wpdb->prefix}wc_product_sorting wc_product_sorting ON $wpdb->posts.ID = wc_product_sorting.product_id ";
|
$sql .= " LEFT JOIN {$wpdb->wc_product_sorting} wc_product_sorting ON $wpdb->posts.ID = wc_product_sorting.product_id ";
|
||||||
}
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
|
@ -648,14 +648,19 @@ final class WooCommerce {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WooCommerce Payment Token Meta API and Term/Order item Meta - set table names.
|
* Set tablenames inside WPDB object.
|
||||||
*/
|
*/
|
||||||
public function wpdb_table_fix() {
|
public function wpdb_table_fix() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta';
|
$wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta';
|
||||||
$wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta';
|
|
||||||
$wpdb->tables[] = 'woocommerce_payment_tokenmeta';
|
$wpdb->tables[] = 'woocommerce_payment_tokenmeta';
|
||||||
$wpdb->tables[] = 'woocommerce_order_itemmeta';
|
|
||||||
|
$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';
|
||||||
|
|
||||||
if ( get_option( 'db_version' ) < 34370 ) {
|
if ( get_option( 'db_version' ) < 34370 ) {
|
||||||
$wpdb->woocommerce_termmeta = $wpdb->prefix . 'woocommerce_termmeta';
|
$wpdb->woocommerce_termmeta = $wpdb->prefix . 'woocommerce_termmeta';
|
||||||
|
|
|
@ -534,7 +534,7 @@ class WC_Data_Store_WP {
|
||||||
|
|
||||||
if ( ! empty( $update_data ) && $update_data !== $existing_data ) {
|
if ( ! empty( $update_data ) && $update_data !== $existing_data ) {
|
||||||
$wpdb->replace(
|
$wpdb->replace(
|
||||||
$wpdb->prefix . $table,
|
$wpdb->$table,
|
||||||
$update_data
|
$update_data
|
||||||
);
|
);
|
||||||
wp_cache_set( 'lookup_table', $update_data, 'object_' . $id );
|
wp_cache_set( 'lookup_table', $update_data, 'object_' . $id );
|
||||||
|
|
|
@ -1274,22 +1274,19 @@ function wc_update_product_lookup_tables() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$result = $wpdb->query(
|
$result = $wpdb->query(
|
||||||
$wpdb->prepare(
|
"
|
||||||
"
|
INSERT IGNORE INTO {$wpdb->wc_product_sorting} (`product_id`, `price`, `min_price`, `max_price`, `average_rating`, `total_sales`)
|
||||||
INSERT IGNORE INTO {$wpdb->prefix}wc_product_sorting (`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
|
||||||
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
|
||||||
FROM {$wpdb->posts} posts
|
LEFT JOIN {$wpdb->postmeta} meta1 ON posts.ID = meta1.post_id
|
||||||
LEFT JOIN {$wpdb->postmeta} meta1 ON posts.ID = meta1.post_id
|
LEFT JOIN {$wpdb->postmeta} meta2 ON posts.ID = meta2.post_id
|
||||||
LEFT JOIN {$wpdb->postmeta} meta2 ON posts.ID = meta2.post_id
|
LEFT JOIN {$wpdb->postmeta} meta3 ON posts.ID = meta3.post_id
|
||||||
LEFT JOIN {$wpdb->postmeta} meta3 ON posts.ID = meta3.post_id
|
WHERE posts.post_type = 'product'
|
||||||
WHERE posts.post_type = 'product'
|
AND meta1.meta_key = '_price'
|
||||||
AND meta1.meta_key = '_price'
|
AND meta1.meta_value <> ''
|
||||||
AND meta1.meta_value <> ''
|
AND meta2.meta_key = '_wc_average_rating'
|
||||||
AND meta2.meta_key = '_wc_average_rating'
|
AND meta3.meta_key = 'total_sales'
|
||||||
AND meta3.meta_key = 'total_sales'
|
GROUP BY posts.ID
|
||||||
GROUP BY posts.ID
|
"
|
||||||
",
|
|
||||||
$default_category
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT min( min_price ) as min_price, MAX( max_price ) as max_price
|
SELECT min( min_price ) as min_price, MAX( max_price ) as max_price
|
||||||
FROM {$wpdb->prefix}wc_product_sorting
|
FROM {$wpdb->wc_product_sorting}
|
||||||
WHERE product_id IN (
|
WHERE product_id IN (
|
||||||
SELECT ID FROM {$wpdb->posts}
|
SELECT ID FROM {$wpdb->posts}
|
||||||
" . $tax_query_sql['join'] . $meta_query_sql['join'] . "
|
" . $tax_query_sql['join'] . $meta_query_sql['join'] . "
|
||||||
|
|
Loading…
Reference in New Issue