Created
July 5, 2022 04:22
-
-
Save petercossey/669aaa7a25c99d6d8e4c889c32c863a8 to your computer and use it in GitHub Desktop.
Script you can execute on a BigCommerce Stencil storefront to delete existing cart for current session.
This file contains 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
const myStorefrontUrl = "http://my-storefront.com" | |
findAndDeleteCart(myStorefrontUrl); | |
function findAndDeleteCart(storefrontUrl) { | |
fetch(storefrontUrl + "/api/storefront/carts", { | |
"method": "GET", | |
"headers": { | |
"Content-Type": "application/json" | |
} | |
}) | |
.then(response => response.json()) | |
.then(cart => { | |
if (cart.length < 1) return; | |
return fetch(storefrontUrl + "/api/storefront/carts/" + cart[0].id ,{ | |
"method": "DELETE", | |
"headers": { | |
"Content-Type": "application/json" | |
} | |
}); | |
}) | |
.then(response => console.log(response)) | |
.catch(err => console.log(err)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment