Skip to content

Commit

Permalink
feat(save): add 'save' method
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Aug 29, 2019
1 parent 874b000 commit 26206b9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/methods/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default self => {
const { cart, storageKey, localStorage } = self
// fix cart subtotal first
cart.subtotal = 0
for (let i = 0; i < cart.items.length; i++) {
const item = cart.items[i]
cart.subtotal += item.quantity * (item.final_price || item.price)
}
if (typeof localStorage === 'object' && localStorage) {
localStorage.setItem(storageKey, JSON.stringify(cart))
}
return self
}

/**
* @method
* @name EcomCart#save
* @description Save cart object to local storage.
*
* @returns {self}
*
* @example
cart.save()
*/

0 comments on commit 26206b9

Please sign in to comment.