Skip to content

Commit

Permalink
fix(constructor): setup methods with args correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Aug 29, 2019
1 parent 6f01886 commit 8ae9f53
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
*/

import { _config } from '@ecomplus/utils'
import { _config, randomObjectId } from '@ecomplus/utils'
import emitter from './lib/emitter'

import addItem from './methods/add-item'
Expand Down Expand Up @@ -70,12 +70,12 @@ const EcomCart = function (storeId, storageKey = _key, localStorage = _storage)
}

// instance methods
this.addItem = addItem
this.addPoduct = addPoduct
this.increaseItemQnt = increaseItemQnt
this.removeItem = removeItem
this.save = save
this.clear = clear
this.addItem = (newItem, save) => addItem(self, newItem, save)
this.addPoduct = (product, variationId, qnt, save) => addPoduct(self, product, variationId, qnt, save)
this.increaseItemQnt = (itemId, quantity, save) => increaseItemQnt(self, quantity, itemId)
this.removeItem = (itemId, save) => removeItem(self, itemId, save)
this.save = () => save(self)
this.clear = () => clear(self)

if (localStorage && storageKey) {
// try to preset cart data from storage
Expand All @@ -94,6 +94,11 @@ const EcomCart = function (storeId, storageKey = _key, localStorage = _storage)
}
}
}

if (!self.data._id) {
// generate new cart ID
self.data._id = randomObjectId()
}
}

// events emitter
Expand Down

0 comments on commit 8ae9f53

Please # to comment.