I am trying to code the simplecart.js to add more than 1 newitem when the add to cart is clicked

250 Views Asked by At

I am trying to code the simplecart.js to add more than 1 newitem when the add to cart is clicked. Like 2 adults and 1 teenager and 1 child along with the prices for each.

        // 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;
                }
0

There are 0 best solutions below