Skip to content

Instantly share code, notes, and snippets.

@mattkelley
Last active September 10, 2015 18:22
Show Gist options
  • Save mattkelley/c41f1598dc6b2e8afec3 to your computer and use it in GitHub Desktop.
Save mattkelley/c41f1598dc6b2e8afec3 to your computer and use it in GitHub Desktop.
// Override Product IDs here
// - these variables are hardcoded in the ivp experience, and are sent as parameters to the ___addToCart function
// - please redefine the product IDs here if they have changed
KERASTASE_BAIN_ELIXIR_ULTIME_PID = 3474630478244;
KERASTASE_BAIN_RICHE_PID = 3474630677241;
KERASTASE_ELIXIR_ULTIME_PID = 3474630346826;
KERASTASE_IMPERIAL_PID = 3474630476844;
KERASTASE_MASQUE_PID = 3474630477056;
KERASTASE_MORINGA_PID = 3474630476912;
// Override the addToCart function here
// - this function is called when the "Add to Bag" button is clicked on product card.
___addToCart = function (productId) {
console.log('Adding ' + productId + ' to cart');
// An example add to cart implementation (reverse engineered from the kerastase website)
var request = new XMLHttpRequest();
var postDomain = 'http://www.kerastase-usa.com',
postStagingDomain = 'http://www.your-staging-site.com', // replace this with your actual staging site
postRoute = '/on/demandware.store/Sites-kerastase-us-Site/default/Cart-AddProduct?format=ajax',
postUrl = postDomain + postRoute; // swap postDomain for postStagingDomain to test in your staging environment
request.open('POST', postUrl, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
var payload = 'pid='+productId+'&quantity=1&autoReplenishmentInterval=&hasAutoReplenishment=false&replenishment=true&undefined=1&cartAction=add';
request.send(payload);
// If you already have an addToCart implementation, call the function here and comment out the example addToCart implementation
// lorealAddToCart(productId, quantity);
};
<!-- Include the script above on the page directly, inside script tags like this: -->
<script>
// Override Product IDs here
// - these variables are hardcoded in the ivp experience, and are sent as parameters to the ___addToCart function
// - please redefine the product IDs here if they have changed
KERASTASE_BAIN_ELIXIR_ULTIME_PID = 3474630478244;
KERASTASE_BAIN_RICHE_PID = 3474630677241;
KERASTASE_ELIXIR_ULTIME_PID = 3474630346826;
KERASTASE_IMPERIAL_PID = 3474630476844;
KERASTASE_MASQUE_PID = 3474630477056;
KERASTASE_MORINGA_PID = 3474630476912;
// Override the addToCart function here
// - this function is called when the "Add to Bag" button is clicked on product card.
___addToCart = function (productId) {
console.log('Adding ' + productId + ' to cart');
// An example add to cart implementation (reverse engineered from the kerastase website)
var request = new XMLHttpRequest();
var postDomain = 'http://www.kerastase-usa.com',
postStagingDomain = 'http://www.your-staging-site.com', // replace this with your actual staging site
postRoute = '/on/demandware.store/Sites-kerastase-us-Site/default/Cart-AddProduct?format=ajax',
postUrl = postDomain + postRoute; // swap postDomain for postStagingDomain to test in your staging environment
request.open('POST', postUrl, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
var payload = 'pid='+productId+'&quantity=1&autoReplenishmentInterval=&hasAutoReplenishment=false&replenishment=true&undefined=1&cartAction=add';
request.send(payload);
// If you already have an addToCart implementation, call the function here and comment out the example addToCart implementation
// lorealAddToCart(productId, quantity);
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment