Skip to content

Instantly share code, notes, and snippets.

@VictorWesterlund
Last active April 8, 2021 06:36
Show Gist options
  • Save VictorWesterlund/4b9273c8a3cdbc328bbf9d8c20c6b325 to your computer and use it in GitHub Desktop.
Save VictorWesterlund/4b9273c8a3cdbc328bbf9d8c20c6b325 to your computer and use it in GitHub Desktop.
// Simulate the ExpressCart behaviour on ShoppingCart.aspx
const officeGuideConfig = ""; // https://github.com/Deltaco-AB/office-configurator-deltaco-config
const officeGuideElements = {
configurator: document.getElementById("officeGuide"),
wrapper: $(".msax-expresscart-view"),
button: $(".msax-CommandAddToCart")[0],
itemsInput: document.querySelectorAll(".msax-expresscart-items")[0]
}
// Submit Express Cart list
function officeGuideCart_submit() {
// Call the SharePoint function for our .msax-expresscart-view family
Microsoft.Dynamics.Retail.SharePoint.Web.UI.ViewModel.AddToExpressCartViewModel(msaxServices, officeGuideElements.wrapper);
officeGuideElements.button.click();
}
// Message event from iframe
window.addEventListener("message", function(event) {
const data = JSON.parse(event.data);
switch(data.type) {
case "ready":
// Initialize the configurator with a custom config
officeGuideElements.configurator.contentWindow.postMessage({
type: "config",
payload: officeGuideConfig
},"*");
break;
case "cart":
// Add product to Express Cart list
for(const [id,quantity] of Object.entries(data.payload)) {
officeGuideElements.itemsInput.value += `${id}#${quantity}\n`;
}
officeGuideCart_submit();
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment