commerce-kit 0.65.0 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/dist/api-types.d.ts +525 -1
- package/dist/index.d.ts +57 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,70 @@ const { data, meta } = await commerce.productBrowse({
|
|
|
38
38
|
const product = await commerce.productGet({ idOrSlug: 'running-shoes' });
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
## Custom fields
|
|
42
|
+
|
|
43
|
+
Merchant-defined fields on products and variants: material, scent notes, lens width. A field
|
|
44
|
+
is defined once per store; every product or variant then holds its own value under
|
|
45
|
+
`metafields`. Variant `attributes` keep coming back, derived from the variant's fields.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Define a field, then write values with the product or variant
|
|
49
|
+
await commerce.metafieldDefinitionCreate({
|
|
50
|
+
ownerType: 'product',
|
|
51
|
+
name: 'Material',
|
|
52
|
+
type: 'choice',
|
|
53
|
+
options: [{ label: 'Wool' }, { label: 'Silk' }],
|
|
54
|
+
storefrontVisible: true,
|
|
55
|
+
filterable: true,
|
|
56
|
+
});
|
|
57
|
+
await commerce.productUpdate({ idOrSlug: 'classic-tee' }, { metafields: [{ key: 'material', value: 'wool' }] });
|
|
58
|
+
|
|
59
|
+
// Read: a product carries its fields and its variants' fields
|
|
60
|
+
const product = await commerce.productGet({ idOrSlug: 'classic-tee' });
|
|
61
|
+
product?.metafields; // [{ key: 'material', name: 'Material', type: 'choice', value: 'wool', options: [{ key: 'wool', label: 'Wool' }, …], hidden: false }]
|
|
62
|
+
|
|
63
|
+
// Lists carry values only when asked, and can be narrowed by filterable fields
|
|
64
|
+
const { data } = await commerce.productBrowse({
|
|
65
|
+
active: true,
|
|
66
|
+
include: 'metafields',
|
|
67
|
+
filter: 'product.custom.material:wool,silk;variant.custom.weight:100..300',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Filter facets list the filterable fields with their options or number range
|
|
71
|
+
const { metafields } = await commerce.productFilters({ lang: 'de-DE' });
|
|
72
|
+
|
|
73
|
+
// Private fields need a key with `catalog:write`
|
|
74
|
+
const full = await commerce.productGet({ idOrSlug: 'classic-tee', metafields: 'all' });
|
|
75
|
+
|
|
76
|
+
// Manage fields: archive keeps every value, delete is for archived fields only
|
|
77
|
+
const { data: fields } = await commerce.metafieldDefinitionBrowse({ ownerType: 'variant' });
|
|
78
|
+
await commerce.metafieldDefinitionUpdate({ idOrKey: 'product.custom.material' }, { filterable: false });
|
|
79
|
+
await commerce.metafieldDefinitionArchive({ idOrKey: 'material' });
|
|
80
|
+
await commerce.metafieldDefinitionRestore({ idOrKey: 'material' });
|
|
81
|
+
await commerce.metafieldDefinitionDelete({ idOrKey: 'material' }, { confirm: 'material', expectedValueCount: 12 });
|
|
82
|
+
|
|
83
|
+
// Turn a text field into a choice, in place: preview, then confirm the grouping
|
|
84
|
+
const preview = await commerce.metafieldDefinitionConversionPreview({ idOrKey: 'variant.custom.scent' });
|
|
85
|
+
await commerce.metafieldDefinitionConvertToChoice(
|
|
86
|
+
{ idOrKey: 'variant.custom.scent' },
|
|
87
|
+
{ groups: preview.suggestedGroups, planHash: preview.planHash },
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// Translations: field names and option labels, then the values of a product or variant
|
|
91
|
+
await commerce.metafieldDefinitionTranslationPut(
|
|
92
|
+
{ idOrKey: 'product.custom.material', locale: 'de-DE' },
|
|
93
|
+
{ name: 'Material', optionLabels: { wool: 'Wolle', silk: 'Seide' } },
|
|
94
|
+
);
|
|
95
|
+
await commerce.productMetafieldTranslationsPut(
|
|
96
|
+
{ idOrSlug: 'classic-tee', locale: 'de-DE' },
|
|
97
|
+
{ values: [{ key: 'care', value: 'Nur Handwäsche' }] },
|
|
98
|
+
);
|
|
99
|
+
await commerce.metafieldsTranslateMissing({ locales: ['de-DE'] }); // machine, never over a person's text
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Addressing a field: its id, or `<ownerType>.<namespace>.<key>` such as `product.custom.material`.
|
|
103
|
+
The deprecated variant `attributes` input is still accepted on writes and stored as custom fields.
|
|
104
|
+
|
|
41
105
|
## Cart
|
|
42
106
|
|
|
43
107
|
```typescript
|