Last active
January 31, 2022 06:34
-
-
Save mig1098/0b0bf19900dce8584331 to your computer and use it in GitHub Desktop.
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
var MGUtil={ | |
data:[], | |
ini:0, | |
total:0, | |
addItem:function(qty,id,properties,callback) { | |
var params = {quantity:qty,id:id}; | |
if(properties != false){ | |
params.properties = properties; | |
} | |
$.ajax({ | |
type: 'POST', | |
url: '/cart/add.js', | |
dataType: 'json', | |
async:false, | |
data: params, | |
success: function(){ | |
if(typeof callback === 'function'){ | |
callback(); | |
} | |
}, | |
error: function(){} | |
}); | |
}, | |
recursive:function(){ | |
MGUtil.addItem(MGUtil.data[MGUtil.ini].qty,MGUtil.data[MGUtil.ini].id,MGUtil.data[MGUtil.ini].properties,function(){ | |
//console.log(MGUtil.data[MGUtil.ini]); | |
MGUtil.ini += 1; | |
if(MGUtil.ini < MGUtil.total){ | |
MGUtil.recursive(); | |
}else{ | |
return false; | |
//document.location.href = '/cart';//AFTER TO ADD ITEMS, GO TO THE CART | |
} | |
}); | |
}, | |
begin:function(){ | |
/*SAMPLE*/ | |
/* SET YOUR ARRAY QTY's' ID's PROPERTIES(FALSE IF IS EMPTY)*/ | |
MGUtil.data = [ | |
{"id":"12345","qty":2,"properties":{"data1":"1"}}, | |
{"id":"34567","qty":3,"properties":{"data2":"1"}}, | |
{"id":"67892","qty":1,"properties":{"data3":"1"}}, | |
{"id":"23456","qty":6,"properties":{"data4":"1"}} | |
]; | |
MGUtil.total = MGUtil.data.length; | |
MGUtil.recursive(); | |
} | |
} | |
// | |
MGUtil.begin(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome, this works, thanks a lot!!