Skip to content

Commit

Permalink
fix(handle-item): internal fix item final price with customization ad…
Browse files Browse the repository at this point in the history
…ditionals
  • Loading branch information
leomp12 committed Oct 25, 2020
1 parent c23ce4a commit 0f59647
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib/fix-item-final-price.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default item => {
// fix item final price with customizations additions
// @TODO handle gift wrap
if (Array.isArray(item.customizations)) {
item.customizations.forEach(customization => {
if (customization.add_to_price) {
const { type, addition } = customization.add_to_price
item.final_price += type === 'percentage'
? item.price * addition / 100
: addition
}
})
}
return item
}
2 changes: 2 additions & 0 deletions src/methods/add-item.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { randomObjectId } from '@ecomplus/utils'
import fixItemQuantity from './../lib/fix-item-quantity'
import fixItemFinalPrice from './../lib/fix-item-final-price'
import fixSubtotal from './../lib/fix-subtotal'

/**
Expand Down Expand Up @@ -59,6 +60,7 @@ export default ({ data, save }, emitter, [newItem, canSave = false]) => {
}
data.items.push(itemCopy)
fixedItem = fixItemQuantity(itemCopy)
fixItemFinalPrice(fixedItem)
}
fixSubtotal(data)

Expand Down
2 changes: 2 additions & 0 deletions src/methods/increase-item-qnt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fixItemQuantity from './../lib/fix-item-quantity'
import fixItemFinalPrice from './../lib/fix-item-final-price'
import fixSubtotal from './../lib/fix-subtotal'

export default ({ data, save }, emitter, [itemId, quantity = 1, canSave = true]) => {
Expand All @@ -9,6 +10,7 @@ export default ({ data, save }, emitter, [itemId, quantity = 1, canSave = true])
item.quantity += quantity

fixItemQuantity(item)
fixItemFinalPrice(item)
fixSubtotal(data)

/**
Expand Down

0 comments on commit 0f59647

Please sign in to comment.