我正在尝试编写simplecart.js代码,以便在点击添加到购物车时添加超过1个newitem。比如2名成人,1名青少年和1名儿童以及每名儿童的价格。
// add in the core functionality
simpleCart.extend({
isReady: false,
// this is where the magic happens, the add function
add: function (values, opt_quiet) {
var info = values || {},
newItem = new simpleCart.Item(info),
addItem = true,
// optionally supress event triggers
quiet = opt_quiet === true ? opt_quiet : false,
oldItem;
// trigger before add event
if (!quiet) {
addItem = simpleCart.trigger('beforeAdd', [newItem]);
if (addItem === false) {
return false;
}
}
// if the new item already exists, increment the value
oldItem = simpleCart.has(newItem);
if (oldItem) {
oldItem.increment(newItem.quantity());
newItem = oldItem;
// otherwise add the item
} else {
sc_items[newItem.id()] = newItem;
}