Skip to content

Commit

Permalink
feat(increase-item-qnt): handle 'increaseItemQnt' method
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Aug 29, 2019
1 parent 9ee9ef9 commit 764c007
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/methods/increase-item-qnt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import fixItemQuantity from './../lib/fix-item-quantity'

export default (self, itemId, quantity = 1, save = true) => {
// find respective item on list by ID
const item = self.cart.items.find(({ _id }) => _id === itemId)
if (item) {
item.quantity += quantity
fixItemQuantity(item)
if (save) {
self.save()
}
} else {
return null
}
return item
}

/**
* @method
* @name EcomCart#increaseItemQnt
* @description Increase quantity of specific item by ID and save cart.
*
* @param {string} itemId - The unique object ID of item
* @param {integer} [quantity=1] - Quantity to increase (can be negative)
* @param {boolean} [save=true] - Save cart data
*
* @returns {object|null} Returns the updated item object or null
* when item not found.
*
* @example
cart.increaseItemQnt('12300000000000000000000f', 3)
*/

0 comments on commit 764c007

Please sign in to comment.