Last active
February 5, 2016 11:02
-
-
Save thomd/336e07ad247df3c4941e to your computer and use it in GitHub Desktop.
transform demandware pricebooks to other currencies for testing multi-currency sites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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