File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 4343</template >
4444
4545<script setup>
46- const selectedVariation = ref (null );
4746const route = useRoute ();
4847import { getProduct } from ' ~/gql/queries/getProduct.gql' ;
4948
5049const { result: productResult , loading } = useQuery (getProduct, () => ({ slug: route .params .slug }));
5150const product = computed (() => productResult .value ? .product );
5251
52+ let selectedVariation = ref (null );
53+
54+ watchEffect (() => {
55+ if (productResult .value ? .product && productResult .value ? .product .variations && productResult .value ? .product .variations .nodes ) {
56+ const variationInStock = product .value .variations .nodes .find ((variation ) => variation .stockStatus === ' IN_STOCK' );
57+ selectedVariation .value = variationInStock ? variationInStock .attributes .nodes .map ((attr ) => attr .value ).toString () : null ;
58+ }
59+ });
60+
5361const calculateDiscountPercentage = computed (() => {
5462 const salePriceValue = parseFloat (productResult .value ? .product .salePrice .replace (/ [^ 0-9 ] / g , ' ' ));
5563 const regularPriceValue = parseFloat (productResult .value ? .product .regularPrice .replace (/ [^ 0-9 ] / g , ' ' ));
You can’t perform that action at this time.
0 commit comments