coyotte508 HF staff commited on
Commit
5e27702
1 Parent(s): edb4af2

✨ Invidiual product page

Browse files
src/routes/vente/+page.server.ts CHANGED
@@ -1,5 +1,4 @@
1
  import type { PageServerLoad } from './$types';
2
- import '$lib/server/db';
3
  import { collections } from '$lib/server/db';
4
 
5
  export const load: PageServerLoad = async () => {
 
1
  import type { PageServerLoad } from './$types';
 
2
  import { collections } from '$lib/server/db';
3
 
4
  export const load: PageServerLoad = async () => {
src/routes/vente/[id]/+page.server.ts ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { PageServerLoad } from './$types';
2
+ import { collections } from '$lib/server/db';
3
+ import { error } from '@sveltejs/kit';
4
+
5
+ export const load: PageServerLoad = async (input) => {
6
+ const product = await collections.products.findOne({
7
+ _id: input.params.id,
8
+ state: { $ne: 'draft' }
9
+ });
10
+
11
+ if (!product) {
12
+ throw error(404, 'Produit non trouvé');
13
+ }
14
+
15
+ product.photos = await collections.pictures
16
+ .find({ productId: input.params.id })
17
+ .sort({ createdAt: 1 })
18
+ .toArray();
19
+
20
+ return {
21
+ product,
22
+ title: `${product.name} - ${product.price} €`,
23
+ description: product.description,
24
+ pictures: product.photos,
25
+ type: 'og:product',
26
+ price: product.price
27
+ };
28
+ };
src/routes/vente/[id]/+page.svelte ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import Container from '$lib/components/Container.svelte';
3
+ import Picture from '$lib/components/Picture.svelte';
4
+ import type { PageData } from './$types';
5
+ import { marked } from 'marked';
6
+
7
+ export let data: PageData;
8
+
9
+ const product = data.product;
10
+ let photoIndex = 0;
11
+
12
+ function submit() {
13
+ alert(
14
+ "Cette partie de l'e-shop n'est pas encore implémentée. Veuillez prendre contact par mail (contact@bergereenchantee.fr), téléphone (07 74 52 11 15) ou instagram."
15
+ );
16
+ }
17
+ </script>
18
+
19
+ <Container>
20
+ <article class="flex my-8 lg:my-16 flex-wrap lg:flex-nowrap">
21
+ <div class="grow lg:basis-0 justify-center items-center flex flex-col">
22
+ <!-- svelte-ignore security-anchor-rel-noreferrer -->
23
+ <a href="/photos/raw/{product.photos[photoIndex].storage[0]._id}" target="_blank">
24
+ <Picture
25
+ picture={product.photos[photoIndex]}
26
+ title="Cliquez pour voir la photo entière"
27
+ class="max-w-full max-h-md lg:max-h-xl rounded-3xl"
28
+ />
29
+ </a>
30
+ {#if product.photos.length > 1}
31
+ <div style="gap: 0.5rem" class="flex justify-start w-full ml-8 mt-2">
32
+ {#each product.photos as photo, i}
33
+ <Picture
34
+ picture={photo}
35
+ style="border-color: #865716"
36
+ class="w-16 h-16 object-cover cursor-pointer box-border {i === photoIndex
37
+ ? 'border border-4'
38
+ : ''} rounded-md"
39
+ on:click={() => (photoIndex = i)}
40
+ />
41
+ {/each}
42
+ </div>
43
+ {/if}
44
+ </div>
45
+ <div class="grow lg:basis-0 lg:px-8 mt-6 lg:m-t0">
46
+ <h1 class="text-oxford text-4xl">{product.name}</h1>
47
+
48
+ <div class="mt-4 flex items-center">
49
+ <span class="font-bold text-2xl mr-2">{product.price} €</span> (+ frais de livraison hors Finistère)
50
+ </div>
51
+ <div class="marked leading-6">
52
+ {@html marked(product.description)}
53
+ </div>
54
+
55
+ <form action="post">
56
+ <button
57
+ type="submit"
58
+ on:click|preventDefault={submit}
59
+ class="mt-4 text-xl leading-6 py-3 px-6 bg-oxford border-0 shadow text-white rounded-md cursor-pointer"
60
+ >
61
+ Acheter
62
+ </button>
63
+ </form>
64
+ </div>
65
+ </article>
66
+ </Container>