Request variations only when the product has variations (#46963)

* Make variations api request conditional

* Add changelog
This commit is contained in:
Fernando Marichal 2024-05-03 12:37:22 -03:00 committed by GitHub
parent f0765081fe
commit e21a78f8f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: dev
Request variations only when the product has variations #46963

View File

@ -49,6 +49,11 @@ export function Edit( {
'product',
'status'
);
const [ productHasOptions ] = useEntityProp< string >(
'postType',
'product',
'has_options'
);
const [ productAttributes ] =
useProductEntityProp< Product[ 'attributes' ] >( 'attributes' );
@ -78,13 +83,14 @@ export function Edit( {
);
return {
totalCountWithoutPrice:
getProductVariationsTotalCount< number >(
totalCountWithoutPriceRequestParams
),
totalCountWithoutPrice: productHasOptions
? getProductVariationsTotalCount< number >(
totalCountWithoutPriceRequestParams
)
: 0,
};
},
[ totalCountWithoutPriceRequestParams ]
[ productHasOptions, totalCountWithoutPriceRequestParams ]
);
const {