Invalidate variations upon generation and fix formatted name (#40905)
* Invalidate variations upon generation and fix formatted name * Add aditional invalidates to keep cache up to date * Update formatted name to always return attribute term name list
This commit is contained in:
parent
be46ab25ed
commit
3f7eb0ce31
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: update
|
||||
|
||||
Update the variation name, by using the wc_get_formatted_variation.
|
|
@ -167,6 +167,8 @@ export const VariationsTable = forwardRef<
|
|||
batchUpdateProductVariations,
|
||||
invalidateResolution,
|
||||
} = useDispatch( EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME );
|
||||
const { invalidateResolution: coreInvalidateResolution } =
|
||||
useDispatch( 'core' );
|
||||
|
||||
const { generateProductVariations } = useProductVariationsHelper();
|
||||
|
||||
|
@ -265,6 +267,16 @@ export const VariationsTable = forwardRef<
|
|||
invalidateResolution( 'getProductVariations', [
|
||||
requestParams,
|
||||
] );
|
||||
coreInvalidateResolution( 'getEntityRecord', [
|
||||
'postType',
|
||||
'product',
|
||||
productId,
|
||||
] );
|
||||
coreInvalidateResolution( 'getEntityRecord', [
|
||||
'postType',
|
||||
'product_variation',
|
||||
variationId,
|
||||
] );
|
||||
} )
|
||||
.finally( () => {
|
||||
setIsUpdating( ( prevState ) => ( {
|
||||
|
@ -333,11 +345,24 @@ export const VariationsTable = forwardRef<
|
|||
delete: values.map( ( { id } ) => id ),
|
||||
}
|
||||
)
|
||||
.then( ( response: VariationResponseProps ) =>
|
||||
.then( ( response: VariationResponseProps ) => {
|
||||
invalidateResolution( 'getProductVariations', [
|
||||
requestParams,
|
||||
] ).then( () => response )
|
||||
)
|
||||
] );
|
||||
coreInvalidateResolution( 'getEntityRecord', [
|
||||
'postType',
|
||||
'product',
|
||||
productId,
|
||||
] );
|
||||
values.forEach( ( { id: variationId } ) => {
|
||||
coreInvalidateResolution( 'getEntityRecord', [
|
||||
'postType',
|
||||
'product_variation',
|
||||
variationId,
|
||||
] );
|
||||
} );
|
||||
return response;
|
||||
} )
|
||||
.then( ( response: VariationResponseProps ) => {
|
||||
createSuccessNotice( getSnackbarText( response ) );
|
||||
onVariationTableChange( 'delete' );
|
||||
|
|
|
@ -65,6 +65,8 @@ export function useProductVariationsHelper() {
|
|||
generateProductVariations: _generateProductVariations,
|
||||
invalidateResolutionForStoreSelector,
|
||||
} = useDispatch( EXPERIMENTAL_PRODUCT_VARIATIONS_STORE_NAME );
|
||||
const { invalidateResolution: coreInvalidateResolution } =
|
||||
useDispatch( 'core' );
|
||||
|
||||
const [ isGenerating, setIsGenerating ] = useState( false );
|
||||
|
||||
|
@ -75,7 +77,7 @@ export function useProductVariationsHelper() {
|
|||
) => {
|
||||
setIsGenerating( true );
|
||||
|
||||
const { status: lastStatus } = await resolveSelect(
|
||||
const { status: lastStatus, variations } = await resolveSelect(
|
||||
'core'
|
||||
).getEditedEntityRecord< Product >(
|
||||
'postType',
|
||||
|
@ -111,6 +113,20 @@ export function useProductVariationsHelper() {
|
|||
invalidateResolutionForStoreSelector(
|
||||
'getProductVariations'
|
||||
);
|
||||
if ( variations && variations.length > 0 ) {
|
||||
for ( const variationId of variations ) {
|
||||
coreInvalidateResolution( 'getEntityRecord', [
|
||||
'postType',
|
||||
'product_variation',
|
||||
variationId,
|
||||
] );
|
||||
}
|
||||
}
|
||||
coreInvalidateResolution( 'getEntityRecord', [
|
||||
'postType',
|
||||
'product',
|
||||
productId,
|
||||
] );
|
||||
return invalidateResolutionForStoreSelector(
|
||||
'getProductVariationsTotalCount'
|
||||
);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: fix
|
||||
|
||||
Invalidate variation requests after new product variations are generated.
|
|
@ -119,7 +119,7 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
|
|||
'attributes' => $this->get_attributes( $object ),
|
||||
'menu_order' => $object->get_menu_order(),
|
||||
'meta_data' => $object->get_meta_data(),
|
||||
'name' => preg_replace( '/' . preg_quote( $object->get_title() . ' - ', '/' ) . '/', '', $object->get_name(), 1 ),
|
||||
'name' => wc_get_formatted_variation( $object, true, false, false ),
|
||||
'parent_id' => $object->get_parent_id(),
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue