This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 218
/
constants.ts
78 lines (71 loc) · 1.83 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* External dependencies
*/
import { getSetting } from '@woocommerce/settings';
import { objectOmit } from '@woocommerce/utils';
/**
* Internal dependencies
*/
import {
ProductCollectionAttributes,
TProductCollectionOrder,
TProductCollectionOrderBy,
ProductCollectionQuery,
ProductCollectionDisplayLayout,
} from './types';
export const STOCK_STATUS_OPTIONS = getSetting< Record< string, string > >(
'stockStatusOptions',
[]
);
const GLOBAL_HIDE_OUT_OF_STOCK = getSetting< boolean >(
'hideOutOfStockItems',
false
);
export const getDefaultStockStatuses = () => {
return GLOBAL_HIDE_OUT_OF_STOCK
? Object.keys( objectOmit( STOCK_STATUS_OPTIONS, 'outofstock' ) )
: Object.keys( STOCK_STATUS_OPTIONS );
};
export const DEFAULT_ATTRIBUTES: Partial< ProductCollectionAttributes > = {
query: {
perPage: 9,
pages: 0,
offset: 0,
postType: 'product',
order: 'asc',
orderBy: 'title',
author: '',
search: '',
exclude: [],
sticky: '',
inherit: false,
taxQuery: '',
parents: [],
isProductCollectionBlock: true,
woocommerceOnSale: false,
woocommerceStockStatus: getDefaultStockStatuses(),
},
tagName: 'div',
displayLayout: {
type: 'flex',
columns: 3,
},
};
export const getDefaultSettings = (
currentAttributes: ProductCollectionAttributes
): Partial< ProductCollectionAttributes > => ( {
displayLayout:
DEFAULT_ATTRIBUTES.displayLayout as ProductCollectionDisplayLayout,
query: {
...currentAttributes.query,
orderBy: ( DEFAULT_ATTRIBUTES.query as ProductCollectionQuery )
.orderBy as TProductCollectionOrderBy,
order: ( DEFAULT_ATTRIBUTES.query as ProductCollectionQuery )
.order as TProductCollectionOrder,
},
} );
export const DEFAULT_FILTERS = {
woocommerceOnSale: ( DEFAULT_ATTRIBUTES.query as ProductCollectionQuery )
.woocommerceOnSale,
woocommerceStockStatus: getDefaultStockStatuses(),
};