Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- function addProductToTheCart(productId, pageRefresh) {
- try {
- var ACTION_URL = window.location.origin + '/cart/add.js?';
- var productData = {
- form_type: 'product',
- utf8: '%E2%9C%93',
- id: productId,
- quantity: 1
- };
- for (const key in productData) {
- ACTION_URL += key + '=' + productData[key] + '&';
- }
- var data = null;
- var xhr = new XMLHttpRequest();
- xhr.withCredentials = true;
- xhr.addEventListener('readystatechange', function () {
- if (this.readyState === 4) {
- console.log(this.responseText);
- if (pageRefresh) {
- window.location.reload();
- }
- }
- });
- xhr.open('POST', ACTION_URL);
- xhr.setRequestHeader('cache-control', 'no-cache');
- xhr.send(data);
- } catch(error) {
- console.log(error.message);
- }
- }
- var product1 = '39282690064419';
- var product2 = '32340515291171';
- addProductToTheCart(product1, false);
- setTimeout(function() {
- addProductToTheCart(product2, true);
- },300);
- })();
Advertisement
Add Comment
Please, Sign In to add comment