Skip to content

Commit 7b094c8

Browse files
nathanssthealexandrelara
authored andcommitted
Prevent adding global_unique_id to old schema versions (#49472)
* Update changelog from PR that added new field to product lookup table * Update db_version variable and use it to prevent adding global_unique_id when the lookup table was not yet updated * Add woocommerce_schema_version to get_default_option_permissions * Add changelog * Remove schema version from default_option_permissions
1 parent d0b3f3a commit 7b094c8

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Significance: minor
1+
Significance: major
22
Type: add
33

4-
Adds global_unique_id field to product and product variations
4+
Add column `global_unique_id` to `wc_product_meta_lookup` table
5+
Add global_unique_id field to product and product variations
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Comment: Update db_version variable and use it to prevent adding global_unique_id when the lookup table was not yet updated

plugins/woocommerce/includes/class-woocommerce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ final class WooCommerce {
5353
*
5454
* @var string
5555
*/
56-
public $db_version = '430';
56+
public $db_version = '920';
5757

5858
/**
5959
* The single instance of the class.

plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,23 +2237,26 @@ protected function get_data_for_lookup_table( $id, $table ) {
22372237
$stock = 'yes' === $manage_stock ? wc_stock_amount( get_post_meta( $id, '_stock', true ) ) : null;
22382238
$price = wc_format_decimal( get_post_meta( $id, '_price', true ) );
22392239
$sale_price = wc_format_decimal( get_post_meta( $id, '_sale_price', true ) );
2240-
return array(
2241-
'product_id' => absint( $id ),
2242-
'sku' => get_post_meta( $id, '_sku', true ),
2243-
'global_unique_id' => get_post_meta( $id, '_global_unique_id', true ),
2244-
'virtual' => 'yes' === get_post_meta( $id, '_virtual', true ) ? 1 : 0,
2245-
'downloadable' => 'yes' === get_post_meta( $id, '_downloadable', true ) ? 1 : 0,
2246-
'min_price' => reset( $price_meta ),
2247-
'max_price' => end( $price_meta ),
2248-
'onsale' => $sale_price && $price === $sale_price ? 1 : 0,
2249-
'stock_quantity' => $stock,
2250-
'stock_status' => get_post_meta( $id, '_stock_status', true ),
2251-
'rating_count' => array_sum( array_map( 'intval', (array) get_post_meta( $id, '_wc_rating_count', true ) ) ),
2252-
'average_rating' => get_post_meta( $id, '_wc_average_rating', true ),
2253-
'total_sales' => get_post_meta( $id, 'total_sales', true ),
2254-
'tax_status' => get_post_meta( $id, '_tax_status', true ),
2255-
'tax_class' => get_post_meta( $id, '_tax_class', true ),
2240+
$product_data = array(
2241+
'product_id' => absint( $id ),
2242+
'sku' => get_post_meta( $id, '_sku', true ),
2243+
'virtual' => 'yes' === get_post_meta( $id, '_virtual', true ) ? 1 : 0,
2244+
'downloadable' => 'yes' === get_post_meta( $id, '_downloadable', true ) ? 1 : 0,
2245+
'min_price' => reset( $price_meta ),
2246+
'max_price' => end( $price_meta ),
2247+
'onsale' => $sale_price && $price === $sale_price ? 1 : 0,
2248+
'stock_quantity' => $stock,
2249+
'stock_status' => get_post_meta( $id, '_stock_status', true ),
2250+
'rating_count' => array_sum( array_map( 'intval', (array) get_post_meta( $id, '_wc_rating_count', true ) ) ),
2251+
'average_rating' => get_post_meta( $id, '_wc_average_rating', true ),
2252+
'total_sales' => get_post_meta( $id, 'total_sales', true ),
2253+
'tax_status' => get_post_meta( $id, '_tax_status', true ),
2254+
'tax_class' => get_post_meta( $id, '_tax_class', true ),
22562255
);
2256+
if ( get_option( 'woocommerce_schema_version', 0 ) >= 920 ) {
2257+
$product_data['global_unique_id'] = get_post_meta( $id, '_global_unique_id', true );
2258+
}
2259+
return $product_data;
22572260
}
22582261
return array();
22592262
}

0 commit comments

Comments
 (0)