diff --git a/src/routes/(app)/cart/+page.svelte b/src/routes/(app)/cart/+page.svelte index abc0b5e00..f9e76326d 100644 --- a/src/routes/(app)/cart/+page.svelte +++ b/src/routes/(app)/cart/+page.svelte @@ -15,6 +15,7 @@ import { oneMaxPerLine } from '$lib/types/Product.js'; import { UrlDependency } from '$lib/types/UrlDependency.js'; import CmsDesign from '$lib/components/CmsDesign.svelte'; + import { CUSTOMER_ROLE_ID } from '$lib/types/User'; export let data; @@ -40,7 +41,9 @@ }, vatProfiles: data.vatProfiles }); - + let alias = ''; + let formAlias: HTMLFormElement; + let loading = false; const { t, locale, countryName } = useI18n(); @@ -68,9 +71,42 @@ {/if}

{t('cart.items')}

+ {#if data.roleId && data.roleId !== CUSTOMER_ROLE_ID} +
{ + errorMessage = ''; + return async ({ result }) => { + loading = false; + if (result.type === 'error') { + errorMessage = result.error.message; + return; + } + await invalidate(UrlDependency.Cart); + }; + }} + on:submit|preventDefault={() => (loading = true)} + > +
+ +
+
+ {/if} {#if errorMessage && !errorProductId} -

{errorMessage}

+

{errorMessage}

{/if} {#if items.length} diff --git a/src/routes/(app)/product/[id]/+page.server.ts b/src/routes/(app)/product/[id]/+page.server.ts index aae2696cb..c77fbabf6 100644 --- a/src/routes/(app)/product/[id]/+page.server.ts +++ b/src/routes/(app)/product/[id]/+page.server.ts @@ -119,7 +119,9 @@ export const load = async ({ params, locals }) => { }; async function addToCart({ params, request, locals }: RequestEvent) { - const product = await collections.products.findOne({ _id: params.id }); + const product = await collections.products.findOne({ + alias: params.id + }); if (!product) { throw error(404, 'Product not found'); @@ -147,6 +149,7 @@ async function addToCart({ params, request, locals }: RequestEvent) { customPriceCurrency: formData.get('customPriceCurrency') || undefined, deposit: formData.get('deposit') || undefined }); + const customPrice = customPriceAmount && customPriceCurrency ? { @@ -159,6 +162,7 @@ async function addToCart({ params, request, locals }: RequestEvent) { ...(product.payWhatYouWant && { customPrice }), deposit: deposit === 'partial' }); + throw redirect(303, request.headers.get('referer') || '/cart'); } export const actions = {