Skip to content

Commit

Permalink
Improved: Fetched product identifier options dynamically (#345).
Browse files Browse the repository at this point in the history
  • Loading branch information
ravilodhi committed Oct 25, 2024
1 parent 1d09f6c commit 8549bd6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/DxpProductIdentifier.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ const productIdentificationStore = useProductIdentificationStore();
const appState = appContext.config.globalProperties.$store
const eComStore = computed(() => appState.getters['user/getCurrentEComStore'])
const productIdentificationPref = computed(() => productIdentificationStore.getProductIdentificationPref);
const productIdentificationOptions = productIdentificationStore.getProductIdentificationOptions;
const productIdentificationOptions = computed(() => productIdentificationStore.getProductIdentificationOptions);
onMounted(() => {
productIdentificationStore.prepareProductIdentifierOptions();
productIdentificationStore.getIdentificationPref(eComStore.value.productStoreId);
})
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export let dxpComponents = {

productIdentificationContext.getProductIdentificationPref = options.getProductIdentificationPref
productIdentificationContext.setProductIdentificationPref = options.setProductIdentificationPref
productIdentificationContext.fetchGoodIdentificationTypes = options.fetchGoodIdentificationTypes

notificationContext.addNotification = options.addNotification
notificationContext.appFirebaseConfig = options.appFirebaseConfig
Expand Down
13 changes: 12 additions & 1 deletion src/store/productIdentification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const useProductIdentificationStore = defineStore('productIdentification'
primaryId: '',
secondaryId: ''
},
productIdentificationOptions: ["productId", "groupId", "groupName", "internalName", "parentProductName", "primaryProductCategoryName", "sku", "title", "SHOPIFY_PROD_SKU", "upc"]
productIdentificationOptions: []
}
},
getters: {
Expand Down Expand Up @@ -44,6 +44,17 @@ export const useProductIdentificationStore = defineStore('productIdentification'
}

this.productIdentificationPref = await productIdentificationContext.getProductIdentificationPref(eComStoreId)
},
async prepareProductIdentifierOptions() {
//static identifications
const productIdentificationOptions = ["productId", "groupId", "groupName", "internalName", "parentProductName", "primaryProductCategoryName", "title"];

//good identification types
const fetchedGoodIdentificationTypes = await productIdentificationContext.fetchGoodIdentificationTypes("HC_GOOD_ID_TYPE");
const fetchedGoodIdentificationOptions = fetchedGoodIdentificationTypes?.map((fetchedGoodIdentificationType: any) => fetchedGoodIdentificationType.goodIdentificationTypeId) || [];

// Merge the arrays and remove duplicates
this.productIdentificationOptions = Array.from(new Set([...productIdentificationOptions, ...fetchedGoodIdentificationOptions])).sort();
}
}
})

0 comments on commit 8549bd6

Please sign in to comment.