Skip to content

Commit

Permalink
fix(add-item): fix handling 'addItem' (save)
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Aug 29, 2019
1 parent 7752491 commit 9ee9ef9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/methods/add-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { randomObjectId } from '@ecomplus/utils'
import fixItemQuantity from './../lib/fix-item-quantity'

// add item to cart
export default ({ cart, saveCart }, newItem, save = true) => {
export default (self, newItem, save = true) => {
// check required fields
if (typeof newItem.product_id !== 'string' ||
typeof newItem.quantity !== 'number' || !(newItem.quantity >= 0) ||
Expand All @@ -11,6 +11,7 @@ export default ({ cart, saveCart }, newItem, save = true) => {
return null
}

const { cart } = self
let fixedItem
for (let i = 0; i < cart.items.length; i++) {
const item = cart.items[i]
Expand Down Expand Up @@ -40,7 +41,7 @@ export default ({ cart, saveCart }, newItem, save = true) => {
}

if (save) {
saveCart()
self.save()
}
return fixedItem
}
Expand All @@ -59,6 +60,7 @@ export default ({ cart, saveCart }, newItem, save = true) => {
* @example
cart.addItem({
_id: '12300000000000000000000f',
product_id: '123a5432109876543210cdef',
sku: 's-MP_2B4',
name: 'Mens Pique Polo Shirt',
Expand Down

0 comments on commit 9ee9ef9

Please sign in to comment.