Skip to content

Fix build error #1502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions components/Products/ProductsSingleProduct.vue
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
<template>
<div class="product-single-container">
<template v-if="data?.product">
<template v-if="product">
<section>
<div class="container flex flex-wrap items-center pt-4 pb-12 mx-auto">
<div
class="grid grid-cols-1 gap-4 mt-8 lg:grid-cols-2 xl:grid-cols-2 md:grid-cols-2 sm:grid-cols-2"
>
<ProductsImage
:alt="data.product.name"
:src="data.product.image.sourceUrl"
/>
<ProductsImage :alt="product.name" :src="product.image.sourceUrl" />
<div class="ml-8">
<p class="text-3xl font-bold text-left">
{{ data.product.name }}
{{ product.name }}
</p>
<ProductsPrice
:product="data.product"
:product="product"
:shouldCenterPrice="false"
priceFontSize="big"
/>
<p class="pt-1 mt-6 text-2xl text-gray-900">
{{ stripHTML(data.product.description) }}
{{ stripHTML(product.description) }}
</p>
<p
v-if="data.product.stockQuantity"
v-if="product.stockQuantity"
class="pt-1 mt-4 text-2xl text-gray-900"
>
{{ data.product.stockQuantity }} in stock
{{ product.stockQuantity }} in stock
</p>
<p
v-if="data.product.variations"
v-if="product.variations"
class="pt-1 mt-4 text-xl text-gray-900"
>
<span class="py-2">Varianter</span>
Expand All @@ -40,19 +37,19 @@
v-model="selectedVariation"
>
<option
v-for="(variation, index) in data.product.variations.nodes"
v-for="(variation, index) in product.variations.nodes"
:key="variation.databaseId"
:value="variation.databaseId"
:selected="index === 0"
>
{{ filteredVariantName(data.product.name, variation.name) }}
{{ filteredVariantName(product.name, variation.name) }}
({{ variation.stockQuantity }} in stock)
</option>
</select>
</p>
<div class="pt-1 mt-2">
<CommonButton
@common-button-click="addProductToCart(data.product)"
@common-button-click="addProductToCart(product)"
:is-loading="isLoading"
>
ADD TO CART
Expand All @@ -62,7 +59,7 @@
</div>
</div>
</section>
<Toast ref="toast" />
<CommonToast ref="toast" />
</template>
</div>
</template>
Expand All @@ -80,8 +77,6 @@

import { ref, watch, computed } from "vue";

import GET_SINGLE_PRODUCT_QUERY from "@/apollo/queries/GET_SINGLE_PRODUCT_QUERY.gql";

import { stripHTML, filteredVariantName } from "@/utils/functions";

import { useCart } from "@/store/useCart";
Expand All @@ -90,23 +85,19 @@ const cart = useCart();

const isLoading = computed(() => cart.loading);

const selectedVariation = ref(); // TODO Pass this value to addProductToCart()
const toast = ref(null);

const props = defineProps({
id: { type: String, required: true },
slug: { type: String, required: true },
product: { type: Object, required: true },
});

const variables = { id: props.id, slug: props.slug };
const { data } = await useAsyncQuery(GET_SINGLE_PRODUCT_QUERY, variables);
const selectedVariation = ref();

watch(
() => data.value,
(dataValue) => {
if (dataValue && dataValue.product?.variations?.nodes?.length > 0) {
selectedVariation.value =
dataValue.product?.variations?.nodes[0].databaseId;
() => props.product,
(productValue) => {
if (productValue && productValue.variations?.nodes?.length > 0) {
selectedVariation.value = productValue.variations?.nodes[0].databaseId;
}
},
{ immediate: true }
Expand Down
2 changes: 1 addition & 1 deletion components/common/CommonToast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defineExpose({ show });
.toast-enter-from,
.toast-leave-to {
opacity: 0;
transform: translateX(30px);
transform: translateX(30px);
}

.toast-enter-to,
Expand Down
8 changes: 7 additions & 1 deletion pages/product/[product].vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<template>
<ProductsSingleProduct :id="route.query.id" :slug="route.params.product" />
<ProductsSingleProduct :product="productData" v-if="productData" />
</template>

<script setup>
import { useAsyncQuery } from "@vue/apollo-composable";
import GET_SINGLE_PRODUCT_QUERY from "@/apollo/queries/GET_SINGLE_PRODUCT_QUERY.gql";
const route = useRoute();

const variables = { id: route.query.id };
const { result } = await useAsyncQuery(GET_SINGLE_PRODUCT_QUERY, variables);
const productData = result.value?.product;

useHead({
title: route.params.product,
titleTemplate: "%s - Nuxt 3 Woocommerce",
Expand Down