Create sample product attributes.
This commit is contained in:
parent
6ab6545c3f
commit
1b46a2746e
|
@ -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,
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue