Skip to content

Commit

Permalink
Merge pull request #45 from bigcommerce/addarr
Browse files Browse the repository at this point in the history
Allow array of items to have quantity updated at once
  • Loading branch information
hegrec committed Oct 28, 2015
2 parents bee6ba2 + b2ad9db commit 3cc31eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stencil-utils",
"version": "0.3.2",
"version": "0.3.5",
"jspm": {
"main": "main",
"directories": {
Expand Down
25 changes: 18 additions & 7 deletions src/api/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,25 @@ export default class extends Base
/**
* Update cart item quantity
*
* @param {String} itemId
* @param {Number} qty
* @param {Function} callback
* @param {String|Object} itemId
* @param {Number|Function} qty
* @param {Function|null} callback
*/
itemUpdate(itemId, qty, callback) {
let items = [
{id: itemId, quantity: qty}
];
let callbackArg = callback;
let items;

if (typeof itemId === 'array' && typeof qty === 'function') {
callbackArg = qty;
items = itemId;
} else {
items = [
{
id: itemId,
quantity: qty,
}
];
}

this.update(items, (err, response) => {
let emitData = {
Expand All @@ -43,7 +54,7 @@ export default class extends Base
};

Hooks.emit('cart-item-update-remote', emitData);
callback(err, response);
callbackArg(err, response);
});
}

Expand Down

0 comments on commit 3cc31eb

Please sign in to comment.