shop.tonybtw.com

shop.tonybtw.com

https://git.tonybtw.com/shop.tonybtw.com.git git://git.tonybtw.com/shop.tonybtw.com.git
2,004 bytes raw
1
package views
2
3
import (
4
	"fmt"
5
	"shop.tonybtw.com/internal/models"
6
)
7
8
func get_all_images(product models.Product, images []models.Product_Image) []string {
9
	var urls []string
10
	urls = append(urls, product.Image_URL)
11
	for _, img := range images {
12
		urls = append(urls, img.Image_URL)
13
	}
14
	return urls
15
}
16
17
templ Product(product models.Product, variants []models.Variant, images []models.Product_Image, cart_count int) {
18
	@Layout(product.Name) {
19
		<div class="product-detail">
20
			<div class="product-gallery" x-data={ fmt.Sprintf("{ active: 0, images: %s }", to_json(get_all_images(product, images))) }>
21
				<img :src="images[active]" :alt="active" class="gallery-main"/>
22
				if len(images) > 0 {
23
					<div class="gallery-thumbs">
24
						<template x-for="(img, index) in images" :key="index">
25
							<img
26
								:src="img"
27
								:class="{ 'active': active === index }"
28
								@click="active = index"
29
								class="gallery-thumb"
30
							/>
31
						</template>
32
					</div>
33
				}
34
			</div>
35
			<div class="product-info">
36
				<h1>{ product.Name }</h1>
37
				<p class="product-price">{ Format_Price(product.Price) }</p>
38
				<p class="product-description">{ product.Description }</p>
39
				<form hx-post="/cart/add" hx-target="#cart-widget" hx-swap="outerHTML">
40
					<input type="hidden" name="product_id" value={ templ.EscapeString(fmt.Sprintf("%d", product.ID)) }/>
41
					<label for="variant_id">Size:</label>
42
					<select name="variant_id" id="variant_id" required>
43
						for _, variant := range variants {
44
							<option value={ templ.EscapeString(fmt.Sprintf("%d", variant.ID)) }>
45
								{ variant.Size }
46
							</option>
47
						}
48
					</select>
49
					<label for="quantity">Quantity:</label>
50
					<select name="quantity" id="quantity">
51
						for i := 1; i <= 10; i++ {
52
							<option value={ templ.EscapeString(fmt.Sprintf("%d", i)) }>{ templ.EscapeString(fmt.Sprintf("%d", i)) }</option>
53
						}
54
					</select>
55
					<button type="submit" class="btn-primary">Add to Cart</button>
56
				</form>
57
			</div>
58
		</div>
59
	}
60
}