Improve updates of onsale/virtual

This commit is contained in:
Mike Jolley 2019-03-14 12:57:48 +00:00
parent 062d147b59
commit 1e83864667
1 changed files with 6 additions and 26 deletions

View File

@ -1456,24 +1456,13 @@ function wc_update_product_lookup_tables_column( $column ) {
case 'virtual': case 'virtual':
$column = esc_sql( $column ); $column = esc_sql( $column );
$wpdb->query(
"
UPDATE
{$wpdb->wc_product_meta_lookup} lookup_table
SET
lookup_table.`{$column}` = 0
"
);
$wpdb->query( $wpdb->query(
" "
UPDATE UPDATE
{$wpdb->wc_product_meta_lookup} lookup_table {$wpdb->wc_product_meta_lookup} lookup_table
LEFT JOIN {$wpdb->postmeta} meta1 ON lookup_table.product_id = meta1.post_id AND meta1.meta_key = '_virtual' LEFT JOIN {$wpdb->postmeta} meta1 ON lookup_table.product_id = meta1.post_id AND meta1.meta_key = '_virtual'
SET SET
lookup_table.`{$column}` = 1 lookup_table.`{$column}` = IF ( meta1.meta_value = 'yes', 1, 0 )
WHERE
meta1.meta_value = 'yes'
" "
); );
break; break;
@ -1481,15 +1470,6 @@ function wc_update_product_lookup_tables_column( $column ) {
$column = esc_sql( $column ); $column = esc_sql( $column );
$decimals = absint( wc_get_price_decimals() ); $decimals = absint( wc_get_price_decimals() );
$wpdb->query(
"
UPDATE
{$wpdb->wc_product_meta_lookup} lookup_table
SET
lookup_table.`{$column}` = 0
"
);
$wpdb->query( $wpdb->query(
$wpdb->prepare( $wpdb->prepare(
" "
@ -1498,11 +1478,11 @@ function wc_update_product_lookup_tables_column( $column ) {
LEFT JOIN {$wpdb->postmeta} meta1 ON lookup_table.product_id = meta1.post_id AND meta1.meta_key = '_price' LEFT JOIN {$wpdb->postmeta} meta1 ON lookup_table.product_id = meta1.post_id AND meta1.meta_key = '_price'
LEFT JOIN {$wpdb->postmeta} meta2 ON lookup_table.product_id = meta2.post_id AND meta2.meta_key = '_sale_price' LEFT JOIN {$wpdb->postmeta} meta2 ON lookup_table.product_id = meta2.post_id AND meta2.meta_key = '_sale_price'
SET SET
lookup_table.`{$column}` = 1 lookup_table.`{$column}` = IF (
WHERE 1=1 CAST( meta1.meta_value AS DECIMAL ) >= 0
AND CAST( meta1.meta_value AS DECIMAL ) >= 0
AND CAST( meta2.meta_value AS CHAR ) != '' AND CAST( meta2.meta_value AS CHAR ) != ''
AND CAST( meta1.meta_value AS DECIMAL( 10, %d ) ) = CAST( meta2.meta_value AS DECIMAL( 10, %d ) ) AND CAST( meta1.meta_value AS DECIMAL( 10, %d ) ) = CAST( meta2.meta_value AS DECIMAL( 10, %d ) )
, 1, 0 )
", ",
$decimals, $decimals,
$decimals $decimals