Skip to content

Instantly share code, notes, and snippets.

@thomd
Last active February 5, 2016 11:02
Show Gist options
  • Save thomd/336e07ad247df3c4941e to your computer and use it in GitHub Desktop.
Save thomd/336e07ad247df3c4941e to your computer and use it in GitHub Desktop.
transform demandware pricebooks to other currencies for testing multi-currency sites
var request = require("request")
var replaceStream = require('replacestream')
var fs = require('fs')
var path = require('path')
var originCurrency = "EUR"
var originFile = "eu-prices.xml"
var targetCurrency = "NOK"
var rate = 1
function calc() {
var value = arguments[1]
return (value * rate).toFixed(2) + arguments[2]
}
request({
url: "http://api.fixer.io/latest",
json: true
}, function (err, res, body) {
if (!err && res.statusCode === 200) {
rate = body.rates[targetCurrency]
fs.createReadStream(path.join(__dirname, originFile))
.pipe(replaceStream('EUR', 'NOK'))
.pipe(replaceStream('eu-list-prices', 'no-list-prices'))
.pipe(replaceStream('eu-sale-prices', 'no-sale-prices'))
.pipe(replaceStream(/([^>]+)(<\/amount>)/g, calc))
.pipe(process.stdout)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment