Merge pull request #25428 from woocommerce/update/product-lookuo-table-tax-columns

Add product lookup table tax columns
This commit is contained in:
Peter Fabian 2020-02-04 14:20:50 +01:00 committed by GitHub
commit 52e335ae5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 5 deletions

View File

@ -140,6 +140,10 @@ class WC_Install {
'wc_update_390_change_geolocation_database_update_cron',
'wc_update_390_db_version',
),
'4.0.0' => array(
'wc_update_product_lookup_tables',
'wc_update_400_db_version',
),
);
/**
@ -422,7 +426,7 @@ class WC_Install {
* @return array
*/
public static function cron_schedules( $schedules ) {
$schedules['monthly'] = array(
$schedules['monthly'] = array(
'interval' => 2635200,
'display' => __( 'Monthly', 'woocommerce' ),
);
@ -903,6 +907,8 @@ CREATE TABLE {$wpdb->prefix}wc_product_meta_lookup (
`rating_count` bigint(20) NULL default 0,
`average_rating` decimal(3,2) NULL default 0.00,
`total_sales` bigint(20) NULL default 0,
`tax_status` varchar(100) NULL default 'taxable',
`tax_class` varchar(100) NULL default '',
PRIMARY KEY (`product_id`),
KEY `virtual` (`virtual`),
KEY `downloadable` (`downloadable`),

View File

@ -644,7 +644,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
}
}
if ( array_intersect( $this->updated_props, array( 'sku', 'regular_price', 'sale_price', 'date_on_sale_from', 'date_on_sale_to', 'total_sales', 'average_rating', 'stock_quantity', 'stock_status', 'manage_stock', 'downloadable', 'virtual' ) ) ) {
if ( array_intersect( $this->updated_props, array( 'sku', 'regular_price', 'sale_price', 'date_on_sale_from', 'date_on_sale_to', 'total_sales', 'average_rating', 'stock_quantity', 'stock_status', 'manage_stock', 'downloadable', 'virtual', 'tax_status', 'tax_class' ) ) ) {
$this->update_lookup_table( $product->get_id(), 'wc_product_meta_lookup' );
}
@ -2033,6 +2033,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
'rating_count' => array_sum( (array) get_post_meta( $id, '_wc_rating_count', true ) ),
'average_rating' => get_post_meta( $id, '_wc_average_rating', true ),
'total_sales' => get_post_meta( $id, 'total_sales', true ),
'tax_status' => get_post_meta( $id, '_tax_status', true ),
'tax_class' => get_post_meta( $id, '_tax_class', true ),
);
}
return array();

View File

@ -1365,7 +1365,9 @@ function wc_update_product_lookup_tables() {
'total_sales',
'downloadable',
'virtual',
'onsale', // When last column is updated, woocommerce_product_lookup_table_is_generating is updated.
'onsale',
'tax_class',
'tax_status', // When last column is updated, woocommerce_product_lookup_table_is_generating is updated.
);
foreach ( $columns as $index => $column ) {
@ -1457,6 +1459,8 @@ function wc_update_product_lookup_tables_column( $column ) {
case 'stock_status':
case 'average_rating':
case 'total_sales':
case 'tax_class':
case 'tax_status':
if ( 'total_sales' === $column ) {
$meta_key = 'total_sales';
} elseif ( 'average_rating' === $column ) {
@ -1523,10 +1527,13 @@ function wc_update_product_lookup_tables_column( $column ) {
)
);
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
delete_option( 'woocommerce_product_lookup_table_is_generating' ); // Complete.
break;
}
// Final column - mark complete.
if ( 'tax_status' === $column ) {
delete_option( 'woocommerce_product_lookup_table_is_generating' );
}
}
add_action( 'wc_update_product_lookup_tables_column', 'wc_update_product_lookup_tables_column' );

View File

@ -2081,3 +2081,10 @@ function wc_update_390_change_geolocation_database_update_cron() {
function wc_update_390_db_version() {
WC_Install::update_db_version( '3.9.0' );
}
/**
* Update DB version.
*/
function wc_update_400_db_version() {
WC_Install::update_db_version( '4.0.0' );
}