Ask a Friend

Give your Cartpinion

Your friend needs some help deciding on a few things in our store. Give them a helping hand...

Your friend values your opinion, please leave your comments and thoughts to help them decide.

${com.content}

`; } if (com.dislikes == 1) { comment += `

${com.commenterName} said:

${com.content}

`; } } } mainHTML += `

product image

Ocean Blue

${product.title}

${product.price / 100} ${Shopify.currency.active}

${product.description || ''}

${comment}

`; } if (data.cart.cartItems.length == 0) { document.querySelector('.rte').innerHTML = 'No Cart Found'; } document.querySelector('.cart-products-main-div').innerHTML = mainHTML; if (data.cart.ownerId == userID) { document.querySelector('#askbtn').click(); var learnmore = document.querySelectorAll('.cart-products-learnmore'); learnmore.forEach(function (element) { element.style.display = 'block'; }); var removeButton = document.querySelectorAll('.cart-product-remove-button'); removeButton.forEach(function (element) { //element.style.display = 'flex'; element.onclick = function (e) { console.log('remove clicked'); console.log(e.target.getAttribute('data-id')); console.log(e.target.getAttribute('data-cartid')); var reqData = { type: 'remove-item', userID: userID, extra: {}, data: { cartId: e.target.getAttribute('data-cartid'), itemId: e.target.getAttribute('data-id'), }, }; fetch('/apps/ask-a-friend', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(reqData), }) .then((response) => response.json()) .then((data) => { console.log(data); window.location.reload(); // initCustomPage(data) // Handle the response from the server }) .catch((error) => { console.error('Error sending request:', error); }); }; }); console.log('cart owner'); // Get all the divs with the classname "ask-comment-area" var askCommentAreas = document.querySelectorAll('.ask-comment-area'); // Loop through each div and hide it askCommentAreas.forEach(function (element) { element.style.display = 'none'; }); // Get the element with the class "cart-product-feedback-btn" var feedbackButton = document.querySelector('.cart-product-feedback-btn'); // Change the attribute value feedbackButton.setAttribute('data-type', 'checkout'); feedbackButton.innerText = 'Checkout'; } else { var learnmore = document.querySelectorAll('.cart-products-learnmore'); learnmore.forEach(function (element) { element.style.display = 'none'; }); var removeButton = document.querySelectorAll('.cart-product-remove-button'); removeButton.forEach(function (element) { element.style.display = 'none'; }); } // Get all the cart-product-like-dislike elements var cartProductLikeDislikeElements = document.querySelectorAll('.cart-product-like-dislike'); // Iterate over each cart-product-like-dislike element cartProductLikeDislikeElements.forEach(function (element) { // Get the like and dislike buttons within the current element var likeButton = element.querySelector('.cart-product-like'); var dislikeButton = element.querySelector('.cart-product-dislike'); var likeImage = likeButton.querySelector('.cart-image-like'); var dislikeImage = dislikeButton.querySelector('.cart-image-dislike'); // Add click event listener to the like button likeButton.addEventListener('click', function () { // Add "active" and "liked" classes to the like button likeButton.classList.add('active', 'liked'); // Remove "active" class from the dislike button dislikeButton.classList.remove('active'); dislikeButton.classList.remove('disliked'); // Add "empty" class to the dislike button dislikeButton.classList.add('empty'); likeButton.classList.remove('empty'); sendGAEvent('like_button_clicked', {userID, "cartID": likeImage.getAttribute('data-cartid'), storeURL, "cartItemID": likeImage.getAttribute('data-id')}) }); // Add click event listener to the dislike button dislikeButton.addEventListener('click', function () { // Add "active" and "disliked" classes to the dislike button dislikeButton.classList.add('active', 'disliked'); // Remove "active" class from the like button likeButton.classList.remove('active'); // Remove "empty" class from the dislike button if it exists dislikeButton.classList.remove('empty'); likeButton.classList.add('empty'); sendGAEvent('dislike_button_clicked', {userID, "cartID": dislikeImage.getAttribute('data-cartid'), storeURL, "cartItemID": dislikeImage.getAttribute('data-id')}) }); }); document.querySelector('.cart-product-feedback-btn').onclick = function (e) { e.preventDefault(); //document.querySelector("#ask2").style.display = "none" //document.querySelector("#ask3").style.display = "block" console.log('send feedback'); if (this.getAttribute('data-type') == 'feedback') { document.querySelector('#ask2').style.display = 'none'; document.querySelector('#ask3').style.display = 'block'; window.scrollTo(0, 0); var getFeedBackDiv = document.querySelectorAll('.cart-product-single'); //cart-product-single let feedbackData = []; for (let feedback of getFeedBackDiv) { let tmp = { cartItem: feedback.querySelector('.cart-product-feedback').getAttribute('data-id'), feedback: feedback.querySelector('.cart-product-feedback').value, like: feedback.querySelector('.comment.active').classList.contains('liked') ? 1 : 0, dislike: feedback.querySelector('.comment.active').classList.contains('disliked') ? 1 : 0, }; feedbackData.push(tmp); cartId = feedback.querySelector('.cart-product-feedback').getAttribute('data-cartid'); } sendGAEvent('send_cartpinion_clicked', {userID, "cartID": cartId, storeURL}) const reqData = { type: 'save-feedback', userID: userID, extra: {}, data: { commenterId: userID, cartId: cartId, cartToken: cartToken, feedbackData: feedbackData, }, }; console.log(reqData); fetch('/apps/ask-a-friend', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(reqData), }) .then((response) => response.json()) .then((data) => { console.log(data); // initCustomPage(data) // Handle the response from the server }) .catch((error) => { console.error('Error sending request:', error); }); } else { console.log('Checkout Called'); window.location.href = `${window.Shopify.routes.root}checkout`; sendGAEvent('checkout_button_clicked', {userID, storeURL}) } }; document.querySelector('#askbtnlast').onclick = function (e) { console.log('last button clicked'); e.preventDefault(); if (document.querySelector('#askbtnlast').getAttribute('data-done')) { sendGAEvent('lets_go_shopping_button_clicked', {userID, "cartID": cartId, storeURL}) window.location.href = window.Shopify.routes.root; return false; } //document.querySelector('#ask1').style.display = 'none'; //document.querySelector('#ask2').style.display = 'block'; var askButton = document.querySelector('#askbtnlast'); askButton.disabled = true; askButton.innerText = 'Processing.....'; let askname = document.querySelector('#thankyouname'); let askemail = document.querySelector('#thankyouemail'); sendGAEvent('thank_you_button_clicked', {userID, "cartID": cartId, storeURL, "name": askname.value, "email": askemail.value}) var getFeedBackDiv = document.querySelectorAll('.cart-product-single'); //cart-product-single let feedbackData = []; for (let feedback of getFeedBackDiv) { let tmp = { cartItem: feedback.querySelector('.cart-product-feedback').getAttribute('data-id'), commenterName: askname.value, commenterEmail: askemail.value, }; feedbackData.push(tmp); cartId = feedback.querySelector('.cart-product-feedback').getAttribute('data-cartid'); } const reqData = { type: 'update-feedback', userID: userID, extra: {}, data: { commenterId: userID, cartId: cartId, cartToken: cartToken, feedbackData: feedbackData, }, }; fetch('/apps/ask-a-friend', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(reqData), }) .then((response) => response.json()) .then((data) => { console.log(data); document.querySelector('#thankyouname').value = ''; document.querySelector('#thankyouemail').value = ''; // Disable the button and change the text var askButton = document.querySelector('#askbtnlast'); askButton.removeAttribute('disabled'); askButton.innerText = 'Let’s go shopping'; askButton.setAttribute('data-done', true); document.querySelectorAll('.ask-friend-section-first-box').forEach(function (element) { element.style.display = 'none'; }); document.querySelector('.thank-you-inputs-container').style.display = 'none'; // initCustomPage(data) // Handle the response from the server }) .catch((error) => { console.error('Error sending request:', error); }); }; document.querySelector('#askbtn').onclick = function () { console.log('button clicked'); sendGAEvent('get_started_button_clicked', {userID, storeURL}) sessionStorage.setItem('get_started', 1); document.querySelector('#ask1').style.display = 'none'; document.querySelector('#ask2').style.display = 'block'; }; if (sessionStorage.getItem('get_started')) { document.querySelector('#askbtn').click(); } document.querySelector('#ask-friend-section-close-icon-pre-advice').onclick = function (e) { sendGAEvent('get_started_close_button_clicked', {userID, storeURL}) console.log('close button clicked'); e.preventDefault(); window.location.href = window.Shopify.routes.root; }; document.querySelector('#ask-friend-section-close-icon-post-advice').onclick = function (e) { sendGAEvent('thank_you_close_button_clicked', {userID, "cartID": cartId, storeURL}) console.log('close button clicked'); e.preventDefault(); window.location.href = window.Shopify.routes.root; }; }