Create sample product attributes.

This commit is contained in:
Jeff Stieler 2021-09-28 12:36:11 -04:00
parent 6ab6545c3f
commit 1b46a2746e
1 changed files with 19 additions and 0 deletions

View File

@ -18,6 +18,13 @@ const httpClient = HTTPClientFactory
.create();
const createProductCategory = ( data ) => httpClient.post( '/wc/v3/products/categories', data );
const createProductAttribute = ( name ) => httpClient.post( '/wc/v3/products/attributes', { name } );
const createProductAttributeTerms = ( parentId, termNames ) => httpClient.post(
`/wc/v3/products/attributes/${ parentId }/terms/batch`,
{
create: termNames.map( name => ( { name } ) )
}
);
const createSampleCategories = async () => {
const { data: clothing } = await createProductCategory( { name: 'Clothing' } );
@ -36,3 +43,15 @@ const createSampleCategories = async () => {
music,
}
};
const createSampleAttributes = async () => {
const { data: color } = await createProductAttribute( 'Color' );
const { data: size } = await createProductAttribute( 'Size' );
await createProductAttributeTerms( color.id, [ 'Blue', 'Gray', 'Green', 'Red', 'Yellow' ] );
await createProductAttributeTerms( size.id, [ 'Large', 'Medium', 'Small' ] );
return {
color,
size,
}
};