Neovictorian Paisley Menswear

    sphere-product-type-export

    0.9.2 • Public • Published

    commercetools logo

    sphere-product-type-export

    Travis Codecov npm semantic-release Commitizen friendly NPM version

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

    Features

    • Export product types from your CTP project
    • Creates 2 files - product type / attributes matrix and attributes list - that can be used to reimport product types

    Configuration

    The configuration object may contain:

    • config: configuration object that may contain the following options
      • delimiter: the delimiter to be used in the csv (default: ,)
      • outputFolder (required): the folder used to store the exported product types and attributes
      • exportFormat (optional): output format, supported are csv, xlsx (default: csv)
      • encoding (optional): encoding used when saving data, supported encodings are listed here (default: utf8)
      • where (optional): where predicate used to filter exported productTypes. More info here
      • includeProductTypeInAttributes (optional): flag to be used when all the attibutes need to be exported
    • sphereClientConfig: see the sphere-node-sdk docs for more information on this

    Usage

    This module can be used as a command line tool as well as a node.js module.

    CLI

    Before using this module in the command line, install it with a global flag.

    npm install sphere-product-type-export -g

    Command

    Command accepts following arguments:

    • The --projectKey or -p parameter is required and contains a project key which should be used when exporting productTypes.
    • The --outputFolder or -o parameter is required and contains a path to an output folder where the output will be saved.
    • The --accessToken or -t parameter tells module if it should use access token instead of clientId and clientSecret.
    • The --sphereHost parameter tells module whether to use a different API URL.
    • The --sphereProtocol parameter tells module whether to use a different protocol.
    • The --where or -w parameter can be used for filtering productTypes before exporting.
    • The --exportFormat parameter specifies in which format (CSV or XLSX) shoud it save exported productTypes (default is CSV).
    • The --delimiter or -d parameter specifies what delimiter should be used when exporting to CSV (default is ',').
    • The --compressOutput or -c parameter specifies whether to archive export files after export is done (default is false).
    • The --encoding parameter specifies in which encoding should be exported CSV files (default is utf8).
    • The includeProductTypeInAttributes flag to be used when all the attibutes need to be exported.

    To export all productTypes in the CSV format we can run this command:

    product-type-export -p project-key -o tmp

    Output

    Export successful!
    {
      "errors": [],
      "exported": {
        "productTypes": 3,
        "attributes": 18
      }
    }

    In the tmp folder there will be created two files attributes.csv and products-to-attributes.csv which describe exported productTypes.

    JS

    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-export --save

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

    export ProductTypeExport from 'sphere-product-type-export'
    
    const config = {
      sphereClientConfig: {
        config: {
          project_key: <PROJECT_KEY>,
          client_id: '*********',
          client_secret: '*********'
        }
      },
      config: {
        outputFolder: '',
        delimiter: '',       // default: ,
        compressOutput: '',  // default: false
        exportFormat: '',    // default: csv
        encoding: '',        // default: utf8
        where: '',           // default: ''
      }
    }
    const productTypeExport = ProductTypeExport(config)
    
    productTypeExport.run()
    .then(() => {
      // done exporting the productType
      // look at the summary to see errors
      productTypeExport.summary
      // the summary hast the following structure
      // {
      //   errors: [],
      //   exported: [<some-name>],
      //   successfulExports: 1
      // }
    })

    Contributing

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

    Install

    npm i sphere-product-type-export

    DownloadsWeekly Downloads

    30

    Version

    0.9.2

    License

    MIT

    Unpacked Size

    174 kB

    Total Files

    8

    Last publish

    Collaborators

    • chukwuemeka
    • ahmetoz
    • commercetools-admin
    • emmenko
    • hajoeichler
    • yanns
    • tdeekens
    • timonrey
    • vineetkumarkushwaha
    • acbeni
    • markusazer
    • jherey
    • danrleyt
    • michele.george
    • jenschude