Created
August 13, 2020 17:15
-
-
Save summersab/b06c844be7c7ff392f8df6a73101351b to your computer and use it in GitHub Desktop.
Quick JS script to dump products in a Foxy session to URL params
This file contains 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
// These are the bare minimum fields that you should exclude from the URL params: | |
//skip = ['id', 'item_number', 'sub_enddate', 'sub_nextdate', 'sub_startdate']; | |
// You can exclude these without problems - keeps things shorter: | |
skip = ['id', 'item_number', 'downloadable_id', 'expires', 'height', 'is_parent', 'length', 'multiship', 'parent_code', 'price_each', 'price_each_is_fractional', 'price_is_fractional', 'quantity_max', 'quantity_min', 'shipto', 'sub_enddate', 'sub_frequency', 'sub_frequency_raw', 'sub_nextdate', 'sub_startdate', 'url', 'weight', 'weight_each', 'width']; | |
FC.json.items.forEach(function(item) { | |
var urlArr = {}; | |
Object.keys(item).forEach(function(el) { | |
if (!skip.includes(el)) { | |
if (typeof item[el] !== 'object') { | |
urlArr[el] = item[el]; | |
} | |
else if (el == "options") { | |
item[el].forEach(function(opt) { | |
urlArr[opt.name] = opt.value; | |
}); | |
} | |
} | |
}); | |
urlParams = Object.keys(urlArr) | |
.map(key => `${key}=${urlArr[key]}`) | |
.join('&'); | |
console.log(urlParams); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment