UNPKG

1.09 kBJavaScriptView Raw
1/**
2 * Takes a ProductListProduct and checks whether it is possible to add it to cart
3 */
4export function validateProduct(product) {
5 if ((product.variant && !product.variant.stockStatus.buyable) ||
6 !product.stockStatus.buyable) {
7 return {
8 status: 'outOfStock',
9 message: product.stockStatus.text
10 };
11 }
12 if (product.isPackage) {
13 return {
14 status: 'package',
15 message: 'Product is a package'
16 };
17 }
18 if (product.isPreOrder) {
19 return {
20 status: 'preOrder',
21 message: 'Pre-order date required'
22 };
23 }
24 if (product.hasConfigurations) {
25 return {
26 status: 'configurations',
27 message: 'Product has configurations'
28 };
29 }
30 if (product.hasVariants && !product.variant) {
31 return {
32 status: 'missingVariant',
33 message: 'Product has no selected variant'
34 };
35 }
36 return {
37 status: 'valid',
38 message: null
39 };
40}
41//# sourceMappingURL=validate-product.js.map
\No newline at end of file