2022-08-18 08:02:21 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-11-02 16:46:14 +00:00
|
|
|
import type { Block } from '@wordpress/blocks';
|
2022-08-18 08:02:21 +00:00
|
|
|
import { addFilter } from '@wordpress/hooks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-10-27 17:40:10 +00:00
|
|
|
import { QUERY_LOOP_ID } from './constants';
|
2022-08-18 08:02:21 +00:00
|
|
|
import './inspector-controls';
|
|
|
|
import './variations/product-query';
|
|
|
|
import './variations/products-on-sale';
|
|
|
|
|
|
|
|
function registerProductQueryVariationAttributes(
|
|
|
|
props: Block,
|
|
|
|
blockName: string
|
|
|
|
) {
|
2022-10-27 17:40:10 +00:00
|
|
|
if ( blockName === QUERY_LOOP_ID ) {
|
2022-08-18 08:02:21 +00:00
|
|
|
// Gracefully handle if settings.attributes is undefined.
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore -- We need this because `attributes` is marked as `readonly`
|
|
|
|
props.attributes = {
|
|
|
|
...props.attributes,
|
|
|
|
__woocommerceVariationProps: {
|
|
|
|
type: 'object',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
|
|
|
addFilter(
|
|
|
|
'blocks.registerBlockType',
|
|
|
|
'core/custom-class-name/attribute',
|
|
|
|
registerProductQueryVariationAttributes
|
|
|
|
);
|