summaryrefslogtreecommitdiffstats
path: root/frontend/lib/calcTotalPrice.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/lib/calcTotalPrice.js')
-rw-r--r--frontend/lib/calcTotalPrice.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/frontend/lib/calcTotalPrice.js b/frontend/lib/calcTotalPrice.js
new file mode 100644
index 0000000..4822468
--- /dev/null
+++ b/frontend/lib/calcTotalPrice.js
@@ -0,0 +1,6 @@
+export default function calcTotalPrice(cart) {
+ return cart.reduce((tally, cartItem) => {
+ if (!cartItem.item) return tally;
+ return tally + cartItem.quantity * cartItem.item.price;
+ }, 0);
+}