From 9437ab196bc5d1e4049580d556caf539f79c278e Mon Sep 17 00:00:00 2001 From: Aditya Sharma Date: Fri, 23 Jun 2023 12:08:23 +0530 Subject: [PATCH] Fixed: handled when variantId not available in current variants (#85zt0m4qc) --- src/i18n/locales/en.json | 1 + src/views/catalog-product-details.vue | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index e55b577f..b6af156a 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -159,6 +159,7 @@ "Select item": "Select item", "Select store": "Select store", "Selected variant not available": "Selected variant not available", + "Selected variant not available. Reseting to first variant.": "Selected variant not available. Reseting to first variant.", "Select a new promise date for these orders. This new date will be used for allocating inventory and fulfilling these orders.": "Select a new promise date for these orders. This new date will be used for allocating inventory and fulfilling these orders.", "Select time zone": "Select time zone", "Service has been scheduled": "Service has been scheduled", diff --git a/src/views/catalog-product-details.vue b/src/views/catalog-product-details.vue index 4a9c912a..1bc66c62 100644 --- a/src/views/catalog-product-details.vue +++ b/src/views/catalog-product-details.vue @@ -466,9 +466,18 @@ export default defineComponent({ Object.keys(features).forEach((color) => this.features[color] = sortSizes(features[color])) - const openedVariant = this.product.variants.find((variant: any) => variant.productId === this.$route.params.variantId) - this.selectedColor = getFeature(openedVariant.featureHierarchy, '1/COLOR/') - this.selectedSize = getFeature(openedVariant.featureHierarchy, '1/SIZE/') + let selectedVariant = this.product.variants.find((variant: any) => variant.productId === this.$route.params.variantId) + + if (!selectedVariant) { + // if the variant does not have color or size as features + selectedVariant = this.product.variants[0] + showToast(translate("Selected variant not available. Reseting to first variant.")) + } + + if (selectedVariant) { + this.selectedColor = getFeature(selectedVariant.featureHierarchy, '1/COLOR/') + this.selectedSize = getFeature(selectedVariant.featureHierarchy, '1/SIZE/') + } }, async updateVariant() { let variant