Created
August 22, 2019 11:59
-
-
Save mklasen/a0e0904e1e6278998016ae4be1eada2d to your computer and use it in GitHub Desktop.
Editor Tool Integration
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
<html> | |
<head> | |
<script type="text/javascript"> | |
function addToCart() { | |
var data = [ | |
{ | |
product_id: 218, | |
customize_hash: 'erg5eyu2r245710', | |
quantity: 48 | |
} | |
]; | |
window.parent.postMessage(data, 'https://stroopwafels.test'); | |
} | |
</script> | |
<style> | |
body { | |
background: #CCC; | |
padding: 50px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Editor Tool</h1> | |
<a href="javascript:" onClick="addToCart()" style="background: blue; padding: 10px; color: white;">Add to cart</a> | |
</body> | |
</html> |
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
window.addEventListener("message", receiveMessage, false); | |
function receiveMessage(event) { | |
event.data.map(function(item) { | |
console.log(item); | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'https://stroopwafels.test/?add-to-cart='+item.product_id+'&quantity='+item.quantity, true); | |
xhr.onload = function () { | |
console.log('loaded'); | |
location.reload(); | |
}; | |
xhr.send(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment