Product Collection: Make sure all variations are taken into account when choosing collection (#43273)

* Make sure all variations are taken into account when choosing collection

* Add changelog
This commit is contained in:
Karol Manijak 2024-01-08 10:55:42 +01:00 committed by GitHub
parent aab950e27a
commit 8d4f1cecec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -1,7 +1,10 @@
/**
* External dependencies
*/
import { select } from '@wordpress/data';
import {
// @ts-expect-error Type definition is missing
store as blocksStore,
type BlockVariation,
registerBlockVariation,
BlockAttributes,
@ -49,7 +52,15 @@ export const getCollectionByName = ( collectionName?: CollectionName ) => {
return null;
}
return collections.find( ( { name } ) => name === collectionName );
// @ts-expect-error Type definitions are missing
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/wordpress__blocks/store/selectors.d.ts
const variations = select( blocksStore ).getBlockVariations(
blockJson.name
);
// @ts-expect-error Type definitions are missing
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/wordpress__blocks/store/selectors.d.ts
return variations.find( ( { name } ) => name === collectionName );
};
export default registerCollections;

View File

@ -0,0 +1,4 @@
Significance: minor
Type: enhancement
Make sure all variations of Product Collection are taken into account when choosing collection by name