2022-09-01 13:13:19 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-10-27 17:40:10 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2022-09-23 13:07:44 +00:00
|
|
|
import type { InnerBlockTemplate } from '@wordpress/blocks';
|
2022-09-01 13:13:19 +00:00
|
|
|
|
2022-08-18 08:02:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-09-23 13:07:44 +00:00
|
|
|
import { QueryBlockAttributes } from './types';
|
2022-08-18 08:02:21 +00:00
|
|
|
|
2022-10-27 17:40:10 +00:00
|
|
|
/**
|
|
|
|
* Returns an object without a key.
|
|
|
|
*/
|
|
|
|
function objectOmit< T, K extends keyof T >( obj: T, key: K ) {
|
|
|
|
const { [ key ]: omit, ...rest } = obj;
|
|
|
|
|
|
|
|
return rest;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const QUERY_LOOP_ID = 'core/query';
|
|
|
|
|
2022-09-23 13:07:44 +00:00
|
|
|
export const DEFAULT_CORE_ALLOWED_CONTROLS = [ 'order', 'taxQuery', 'search' ];
|
|
|
|
|
2022-10-27 17:40:10 +00:00
|
|
|
export const ALL_PRODUCT_QUERY_CONTROLS = [ 'onSale', 'stockStatus' ];
|
2022-09-23 13:07:44 +00:00
|
|
|
|
|
|
|
export const DEFAULT_ALLOWED_CONTROLS = [
|
|
|
|
...DEFAULT_CORE_ALLOWED_CONTROLS,
|
|
|
|
...ALL_PRODUCT_QUERY_CONTROLS,
|
|
|
|
];
|
|
|
|
|
2022-10-27 17:40:10 +00:00
|
|
|
export const STOCK_STATUS_OPTIONS = getSetting< Record< string, string > >(
|
|
|
|
'stockStatusOptions',
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
const GLOBAL_HIDE_OUT_OF_STOCK = getSetting< boolean >(
|
|
|
|
'hideOutOfStockItems',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2022-09-23 13:07:44 +00:00
|
|
|
export const QUERY_DEFAULT_ATTRIBUTES: QueryBlockAttributes = {
|
2022-10-11 14:04:54 +00:00
|
|
|
allowedControls: DEFAULT_ALLOWED_CONTROLS,
|
2022-09-01 13:13:19 +00:00
|
|
|
displayLayout: {
|
|
|
|
type: 'flex',
|
|
|
|
columns: 3,
|
|
|
|
},
|
2022-08-18 08:02:21 +00:00
|
|
|
query: {
|
|
|
|
perPage: 6,
|
|
|
|
pages: 0,
|
|
|
|
offset: 0,
|
|
|
|
postType: 'product',
|
|
|
|
order: 'desc',
|
|
|
|
orderBy: 'date',
|
|
|
|
author: '',
|
|
|
|
search: '',
|
|
|
|
exclude: [],
|
|
|
|
sticky: '',
|
|
|
|
inherit: false,
|
2022-10-27 17:40:10 +00:00
|
|
|
__woocommerceStockStatus: GLOBAL_HIDE_OUT_OF_STOCK
|
|
|
|
? Object.keys( objectOmit( STOCK_STATUS_OPTIONS, 'outofstock' ) )
|
|
|
|
: Object.keys( STOCK_STATUS_OPTIONS ),
|
2022-08-18 08:02:21 +00:00
|
|
|
},
|
|
|
|
};
|
2022-09-01 13:13:19 +00:00
|
|
|
|
|
|
|
export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [
|
|
|
|
[
|
|
|
|
'core/post-template',
|
|
|
|
{},
|
|
|
|
[
|
2022-09-23 13:07:44 +00:00
|
|
|
[ 'woocommerce/product-image' ],
|
2022-09-01 13:13:19 +00:00
|
|
|
[
|
|
|
|
'core/post-title',
|
|
|
|
{
|
|
|
|
level: 3,
|
|
|
|
fontSize: 'large',
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2022-09-23 13:07:44 +00:00
|
|
|
[ 'core/query-pagination' ],
|
|
|
|
[ 'core/query-no-results' ],
|
2022-09-01 13:13:19 +00:00
|
|
|
];
|