Skip to content

Commit

Permalink
Validate product on SKU id
Browse files Browse the repository at this point in the history
The SKU id is generally the unique item identifier. We should use it to to find the correct match instead of the name.
  • Loading branch information
thorsten-stripe authored May 2, 2020
1 parent 3aff207 commit 7a0d4b4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions use-shopping-cart/src/serverUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const validateCartItems = (inventorySrc, cartDetails) => {
if (!Object.prototype.hasOwnProperty.call(cartDetails, sku)) continue

const product = cartDetails[sku]
const validatedItem = inventorySrc.find(
(currentProduct) => currentProduct.name === product.name
const inventoryItem = inventorySrc.find(
(currentProduct) => currentProduct.sku === sku
)
validatedItems.push({
name: validatedItem.name,
amount: validatedItem.price,
currency: validatedItem.currency,
name: inventoryItem.name,
amount: inventoryItem.price,
currency: inventoryItem.currency,
quantity: product.quantity
})
}
Expand Down

0 comments on commit 7a0d4b4

Please sign in to comment.