commercetools / nodejs

Everything related to the Node.js ecosystem for the commercetools platform.
https://commercetools.github.io/nodejs/
MIT License
75 stars 70 forks source link

Expose Price sync actions in syncActions #1432

Open LEQADA opened 4 years ago

LEQADA commented 4 years ago

Description

In our project we need to calculate update actions for 2 price drafts. We don't have a full product representation for the old price. It'd be very useful to have a createSyncPrices API which would return update actions for 2 price drafts.

Something like this

import { createSyncPrices } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncPrices = createSyncPrices()
const client = createClient({
  middlewares: [...],
})
const before = {
  // ...
}
const now = {
  // ...
}
const actions = syncPrices.buildActions(now, before)
const productsRequest = {
  url: `/products/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(productsRequest)
.then(result => ...)
.catch(error => ...)

Current Behavior

Currently the only way to achieve the goal is to provide 2 empty products with prices for which we want to get update actions.

daern91 commented 4 years ago

Updating this one with more info to clarify:

Many if not most customers get prices as a separate feed which contains prices only (no variant data besides the SKUs as prices change more often than other product data). We transform the feed into a CTP price representation and we also fetch existing price from CT project. Now we have both before (which represents fetched price array from CTP for particular variant) and now (which represents the transformed price array for the same variant from the feed) and would like to path those arrays to the library so that it decides which price needs to be removed, modifed, added or setPrices applied and return it as list of actions.