Skip to content

Commit

Permalink
Added price and total on cart page
Browse files Browse the repository at this point in the history
  • Loading branch information
peeofive committed Feb 23, 2024
1 parent ae2b20f commit 66d5704
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/checkout/components/LineItem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html } from "../utils.js";

export default ({ sku, id, name, quantity, image }) => {
export default ({ sku, id, name, quantity, price, image }) => {
const url = `/product/${id}?sku=${sku}`;
return html`<li class="c_LineItem">
<a href="${url}" class="c_LineItem__image">
Expand All @@ -10,6 +10,7 @@ export default ({ sku, id, name, quantity, image }) => {
<strong>${name}</strong><br />${sku}
</a>
<div class="c_LineItem__quantity">${quantity}</div>
<div class="c_LineItem__price">${price * quantity} Ø</div>
<form action="/checkout/cart/remove" method="post">
<input type="hidden" name="sku" value="${sku}" />
<input type="submit" value="remove" />
Expand Down
6 changes: 6 additions & 0 deletions src/checkout/pages/CartPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
list-style: none;
padding: 0;
}

.c_CartPage__total {
margin-top: 20px;
text-align: right;
font-weight: bold;
}
10 changes: 10 additions & 0 deletions src/checkout/pages/CartPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ export default ({ req }) => {
<ul class="c_CartPage__lineItems">
${lineItems.map(LineItem).join("")}
</ul>
<hr />
<p class="c_CartPage__total">
Total:
${lineItems.reduce(
(acc, { price, quantity }) => acc + price * quantity,
0,
)}
Ø
</p>
<form action="/checkout/checkout" method="get">
<button>checkout</button>
</form>
Expand Down

0 comments on commit 66d5704

Please sign in to comment.