Set prices button from the variations notice is not updating the right amount of variations (#40876)

* Improve has_price filter so it can matches when the price record does not exist or it's empty/null

* Get the exact variation ids of those ones that do not have price

* Add changelog files

* Fix linter errors
This commit is contained in:
Maikel David Pérez Gómez 2023-10-19 13:14:08 -04:00 committed by GitHub
parent 613a63b0ef
commit 8827e42bd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 9 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Get the exact variation ids of those ones that do not have price

View File

@ -124,8 +124,11 @@ export function Edit( {
EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME
).getProductVariations< Pick< ProductVariation, 'id' >[] >( {
product_id: productId,
order: 'asc',
orderby: 'menu_order',
has_price: false,
_fields: [ 'id' ],
per_page: totalCountWithoutPrice,
} );
handlePrompt( {
onOk( value ) {
@ -187,8 +190,8 @@ export function Edit( {
update &&
update.find(
( variation ) =>
variation.regular_price ||
variation.sale_price
'regular_price' in variation ||
'sale_price' in variation
) )
) {
invalidateResolution(

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Improve has_price filter so it can matches when the price record does not exist or it's empty/null

View File

@ -906,13 +906,39 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
// Price filter.
if ( is_bool( $request['has_price'] ) ) {
$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
$args,
array(
'key' => '_price',
'compare' => $request['has_price'] ? 'EXISTS' : 'NOT EXISTS',
)
);
if ( $request['has_price'] ) {
$args['meta_query'] = $this->add_meta_query( // phpcs:ignore Standard.Category.SniffName.ErrorCode slow query ok.
$args,
array(
'relation' => 'AND',
array(
'key' => '_price',
'compare' => 'EXISTS',
),
array(
'key' => '_price',
'compare' => '!=',
'value' => null,
),
)
);
} else {
$args['meta_query'] = $this->add_meta_query( // phpcs:ignore Standard.Category.SniffName.ErrorCode slow query ok.
$args,
array(
'relation' => 'OR',
array(
'key' => '_price',
'compare' => 'NOT EXISTS',
),
array(
'key' => '_price',
'compare' => '=',
'value' => null,
),
)
);
}
}
// Filter product based on stock_status.