sphere-product-type-import

Library that helps with importing product type into the commercetools platform

Usage no npm install needed!

<script type="module">
  import sphereProductTypeImport from 'https://cdn.skypack.dev/sphere-product-type-import';
</script>

README

commercetools logo

sphere-product-type-import

Travis Codecov npm semantic-release Commitizen friendly NPM version

A library that helps with importing product-types into the Commercetools Platform.
This library is built to be used in conjunction with sphere-node-cli.

Table of Contents

Features

  • Import product types to your CTP project
  • Pre-validate product types using a JSON schema

Configuration

The configuration object may contain:

Usage

Usage with sphere-node-cli

You can use the product type import from the command line using the sphere-node-cli. In order for the cli to import product types, the file to import from must be JSON and follow the this structure:

{
  "productTypes": [
    <product-type>,
    <product-type>,
    ...
  ]
}

Then you can import this file using the cli:

sphere-node-cli -t productType -p my-project-key -f /sample_dir/productTypes.json

You can pass a custom configuration as described above via the -c operator followed by a JSON String that represents your configuration

Direct usage

If you want more control, you can also use this library directly in JavaScript. To do this you first need to install it:

npm install sphere-product-type-import --save-dev

Then you can use it to import product types like so:

import ProductTypeImport from 'sphere-product-type-import'

const productType = {
  name: '<some-name>',
  description: '<some-description>'
}
const config = {
  importerConfig: {
    continueOnProblems: false
  },
  sphereClientConfig: {
    config: {
      project_key: <PROJECT_KEY>,
      client_id: '*********',
      client_secret: '*********'
    }
  }
}
const productTypeImport = ProductTypeImport(config)

productTypeImport.importProductType(productType)
.then(() => {
  // done importing the productType
  // look at the summary to see errors
  productTypeImport.summary
  // the summary hast the following structure
  // {
  //   errors: [],
  //   inserted: [<some-name>],
  //   successfulImports: 1
  // }
})

When there is an error during processing productTypes, process will by default save this error to summary.errors array and reject. If the configuration flag importerConfig.continueOnProblems is set to true the importer will only push error to summary and then continue with next productType.

Contributing

See CONTRIBUTING.md file for info on how to contribute to this library