Created
November 29, 2021 11:09
-
-
Save oguzhanoptimum7/47ce034862a7f4cc0a87eba3122857c6 to your computer and use it in GitHub Desktop.
Clear Cart Attr
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
| $.ajax({ | |
| type: "GET", | |
| url: '/cart.js', | |
| dataType: 'json', | |
| success: function(resp) { | |
| var nullHash = {}; | |
| for ([key, value] of Object.entries(resp.attributes)) { | |
| nullHash[key] = null; | |
| } | |
| $.ajax({ | |
| type: "POST", | |
| url: '/cart/update.js', | |
| data: {attributes:nullHash}, | |
| dataType: 'json' | |
| }); | |
| } | |
| }); | |
| Or if you want to delete them by name, you can do this: | |
| var nullHash = { | |
| 'someAtt1': null, | |
| 'someAtt2': null, | |
| 'someAtt3': null | |
| }; | |
| $.ajax({ | |
| type: "POST", | |
| url: '/cart/update.js', | |
| data: {attributes:nullHash}, | |
| dataType: 'json' | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment