Skip to content

Instantly share code, notes, and snippets.

@Adrian-Samuel
Created August 16, 2019 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adrian-Samuel/1cbb3398a230abb22b62a72d8192cce7 to your computer and use it in GitHub Desktop.
Save Adrian-Samuel/1cbb3398a230abb22b62a72d8192cce7 to your computer and use it in GitHub Desktop.
document.addEventListener('DOMContentLoaded', async () => {
const domain = window.location.host;
const [RAD, orderID] = window.location.href.match(/\d+/g);
const orderTableLines = document.querySelectorAll('body .document:nth-of-type(3) tbody tr > td:nth-child(2)')
document.querySelector("body > table:nth-child(8) > thead > tr > th:nth-child(2)").insertAdjacentHTML('afterend', '<th>Category Name</th>')
const getOrder = await fetch(`https://${domain}/API/Account/${RAD}/DisplayTemplate/Order/${orderID}.json`, {
credentials: 'same-origin'
});
const getOrderJSON = await getOrder.json();
console.log(getOrderJSON)
if (getOrderJSON.Order.hasOwnProperty('OrderLines')) {
const lines = Array.isArray(getOrderJSON.Order.OrderLines.OrderLine) ? getOrderJSON.Order.OrderLines.OrderLine : [getOrderJSON.Order.OrderLines.OrderLine]
console.log(lines)
lines.forEach(async (line, idx) => {
if (line.hasOwnProperty('Item')) {
const categoryID = line.Item.categoryID;
console.log(categoryID)
if (categoryID > 0) {
const getCategoryName = await fetch(`https://${domain}/API/Account/${RAD}/Category/${categoryID}.json`, {
credentials: "same-origin"
});
const getCategoryJSON = await getCategoryName.json();
const categoryPath = getCategoryJSON.Category.fullPathName.replace(/\//g, "-")
orderTableLines[idx].insertAdjacentHTML('afterend', `<td>${categoryPath}</td>`)
} else {
orderTableLines[idx].insertAdjacentHTML('afterend', `<td></td>`)
}
} else {
orderTableLines[idx].insertAdjacentHTML('afterend', `<td></td>`)
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment