shop.tonybtw.com

shop.tonybtw.com

https://git.tonybtw.com/shop.tonybtw.com.git git://git.tonybtw.com/shop.tonybtw.com.git
2,305 bytes raw
1
package views
2
3
import (
4
	"fmt"
5
	"shop.tonybtw.com/internal/models"
6
)
7
8
templ Cart(items []models.Cart_Item_Detail, total int, cart_count int) {
9
	@Layout("Cart") {
10
		<h1>Your Cart</h1>
11
		@Cart_Items(items)
12
		if len(items) > 0 {
13
			<div class="cart-actions">
14
				<a href="/" class="btn-secondary">Continue Shopping</a>
15
				<a href="/checkout" class="btn-primary">Checkout</a>
16
			</div>
17
		}
18
	}
19
}
20
21
templ Cart_Items(items []models.Cart_Item_Detail) {
22
	<div id="cart-items">
23
		if len(items) == 0 {
24
			<p class="empty-cart">Your cart is empty.</p>
25
		} else {
26
			<table class="cart-table">
27
				<thead>
28
					<tr>
29
						<th>Product</th>
30
						<th>Size</th>
31
						<th>Price</th>
32
						<th>Qty</th>
33
						<th>Subtotal</th>
34
						<th></th>
35
					</tr>
36
				</thead>
37
				<tbody>
38
					for _, item := range items {
39
						<tr>
40
							<td>
41
								<img src={ item.Image_URL } alt="" class="cart-thumb"/>
42
								{ item.Name }
43
							</td>
44
							<td>{ item.Size }</td>
45
							<td>{ Format_Price(item.Price) }</td>
46
							<td>
47
								<form hx-post="/cart/update" hx-target="#cart-items" hx-swap="outerHTML">
48
									<input type="hidden" name="product_id" value={ templ.EscapeString(fmt.Sprintf("%d", item.Product_ID)) }/>
49
									<input type="hidden" name="variant_id" value={ templ.EscapeString(fmt.Sprintf("%d", item.Variant_ID)) }/>
50
									<input
51
										type="number"
52
										name="quantity"
53
										value={ templ.EscapeString(fmt.Sprintf("%d", item.Quantity)) }
54
										min="1"
55
										max="10"
56
										class="qty-input"
57
										hx-trigger="change"
58
									/>
59
								</form>
60
							</td>
61
							<td>{ Format_Price(item.Subtotal) }</td>
62
							<td>
63
								<form hx-post="/cart/remove" hx-target="#cart-items" hx-swap="outerHTML">
64
									<input type="hidden" name="product_id" value={ templ.EscapeString(fmt.Sprintf("%d", item.Product_ID)) }/>
65
									<input type="hidden" name="variant_id" value={ templ.EscapeString(fmt.Sprintf("%d", item.Variant_ID)) }/>
66
									<button type="submit" class="btn-remove">&times;</button>
67
								</form>
68
							</td>
69
						</tr>
70
					}
71
				</tbody>
72
				<tfoot>
73
					<tr>
74
						<td colspan="4"><strong>Total</strong></td>
75
						<td colspan="2"><strong>{ Format_Price(models.Get_Cart_Total(items)) }</strong></td>
76
					</tr>
77
				</tfoot>
78
			</table>
79
		}
80
	</div>
81
}