-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(increase-item-qnt): handle 'increaseItemQnt' method
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
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) | ||
*/ |