Skip to content

Commit

Permalink
Implemented: logic to get the preorder and backorder dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
adityasharma7 committed Jul 6, 2023
1 parent 2daf744 commit f722748
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ npm-debug.log*
/www
.firebase/

.env
.env
.history
.env.*
!.env.example
4 changes: 4 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"Excluded ATP": "Excluded ATP",
"from date": "from date",
"Failed to update configuration": "Failed to update configuration",
"Failed to get pre-order/backorder categories": "Failed to get pre-order/backorder categories",
"Go to OMS": "Go to OMS",
"History": "History",
"Hold pre-order physical inventory": "Hold pre-order physical inventory",
Expand Down Expand Up @@ -83,12 +84,15 @@
"Loyalty status": "Loyalty status",
"Never in any category": "Never in any category",
"No": "No",
"No backorder category found": "No backorder category found",
"No job found": "No job found",
"No jobs found": "No jobs found",
"No jobs have run yet": "No jobs have run yet",
"No listing data": "No listing data",
"No products found": "No products found",
"No pre-order category found": "No pre-order category found",
"No results found": "No results found",
"No selected store found.": "No selected store found.",
"No time zone found": "No time zone found",
"No warehouses found": "No warehouses found",
"No shop listings found": "No shop listings found",
Expand Down
22 changes: 21 additions & 1 deletion src/services/ProductService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,29 @@ const getCatalogProducts = async (payload: any): Promise<any> => {
})
}

const getProductStoreCatalog = async (payload: any): Promise<any> => {
return api({
url: "performFind",
method: "get",
params: payload,
cache: true
});
}

const getCatalogCategories = async (payload: any): Promise<any> => {
return api({
url: "performFind",
method: "get",
params: payload,
cache: true
});
}

export const ProductService = {
fetchProducts,
findOrder,
fetchCurrentList,
getCatalogProducts
getCatalogCategories,
getCatalogProducts,
getProductStoreCatalog
}
5 changes: 3 additions & 2 deletions src/store/modules/product/ProductState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default interface ProductState {
catalogProducts: {
items: any[],
total: number
},
currentCatalogProduct: any
};
currentCatalogProduct: any;
productStoreCategory: any;
}
61 changes: 61 additions & 0 deletions src/store/modules/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,66 @@ const actions: ActionTree<ProductState, RootState> = {
total: 0
});
},
/**
* Fetch catalog products
*/
async getPreOrderBackorderCategory({ commit, state }, payload) {
let productStoreCategories = state.productStoreCategory[payload.productStoreId];

if (productStoreCategories) {
return productStoreCategories;
}

let resp;
try {
productStoreCategories = {};
let productStoreCatalogId;
resp = await ProductService.getProductStoreCatalog({
"inputFields": {
"productStoreId": payload.productStoreId,
},
"fieldList": ["productStoreId", "prodCatalogId"],
"entityName": "ProductStoreCatalog",
"distinct": "Y",
"noConditionFind": "Y",
"filterByDate": "Y",
"viewSize": 1,
})

if (!hasError(resp)) {
productStoreCatalogId = resp.data.docs[0].prodCatalogId
} else {
throw resp.data;
}

resp = await ProductService.getCatalogCategories({
"inputFields": {
"productStoreId": payload.productStoreId,
"prodCatalogCategoryTypeId": ["PCCT_PREORDR", "PCCT_BACKORDER"],
"prodCatalogCategoryTypeId_op": "in"
},
"fieldList": ["productCategoryId", "prodCatalogCategoryTypeId"],
"entityName": "ProdCatalogCategory",
"distinct": "Y",
"noConditionFind": "Y",
"filterByDate": "Y",
"viewSize": 10, // view size should be 2, considered if there are duplicate records it should not affect
})
if (!hasError(resp)) {
resp.data.docs.reduce((productStoreCategories: any, category: any) => {
productStoreCategories[category.prodCatalogCategoryTypeId] = category.productCategoryId;
return productStoreCategories;
}, productStoreCategories);
} else {
throw resp.data;
}
state.productStoreCategory[payload.productStoreId] = productStoreCategories;
commit(types.PRODUCT_STR_CAT_UPDATED, state.productStoreCategory)
} catch (error) {
console.error(error)
return Promise.reject(error);
}
return productStoreCategories;
},
}
export default actions;
3 changes: 2 additions & 1 deletion src/store/modules/product/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const productModule: Module<ProductState, RootState> = {
items: [],
total: 0
},
currentCatalogProduct: {}
currentCatalogProduct: {},
productStoreCategory: {}
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/product/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const PRODUCT_CURRENT_LIST_UPDATED = SN_PRODUCT + '/CURRENT_LIST_UPDATED'
export const PRODUCT_CURRENT_TOTAL_PRE_ORDERS_UPDATED = SN_PRODUCT + '/CURRENT_TOTAL_PRE_ORDERS_UPDATED'
export const PRODUCT_CACHED_UPDATED = SN_PRODUCT + '/CACHED_UPDATED'
export const PRODUCT_CATALOG_UPDATED = SN_PRODUCT + '/CATALOG_UPDATED'
export const PRODUCT_CURRENT_CTLGPRDCT_UPDATED = SN_PRODUCT + '/CURRENT_CTLGPRDCT_UPDATED'
export const PRODUCT_CURRENT_CTLGPRDCT_UPDATED = SN_PRODUCT + '/CURRENT_CTLGPRDCT_UPDATED'
export const PRODUCT_STR_CAT_UPDATED = SN_PRODUCT + '/STR_CAT_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/product/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const mutations: MutationTree <ProductState> = {
},
[types.PRODUCT_CURRENT_CTLGPRDCT_UPDATED] (state, payload) {
state.currentCatalogProduct = payload
},
[types.PRODUCT_STR_CAT_UPDATED] (state, payload) {
state.productStoreCategory = payload
}
}
export default mutations;
41 changes: 31 additions & 10 deletions src/views/catalog-product-details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</ion-item>
<ion-item>
<ion-label class="ion-text-wrap">{{ $t("Category") }}</ion-label>
<ion-label slot="end">{{ poSummary.categoryId === 'PREORDER_CAT' ? $t('Pre-order') : poSummary.categoryId === 'BACKORDER_CAT' ? $t('Back-order') : $t('None') }}</ion-label>
<ion-label slot="end">{{ poSummary.categoryId === preOrderCategoryId ? $t('Pre-order') : poSummary.categoryId === backorderCategoryId ? $t('Back-order') : $t('None') }}</ion-label>
<ion-icon slot="end" :icon="isCategoryValid() ? checkmarkCircleOutline : alertCircleOutline" :color="isCategoryValid() ? 'success' : 'warning'" />
</ion-item>
<ion-item>
Expand Down Expand Up @@ -455,7 +455,9 @@ export default defineComponent({
poSummary: {} as any,
shopListings: [] as any,
configsByStores: [] as any,
listingJobRunTime: 0
listingJobRunTime: 0,
backorderCategoryId: '',
preOrderCategoryId: ''
}
},
computed: {
Expand All @@ -469,6 +471,26 @@ export default defineComponent({
async ionViewWillEnter() {
(this as any).productId = this.$route.params.productId;
(this as any).variantId = this.$route.query.variantId;
const productStoreId = this.currentEComStore.productStoreId;
// TODO Handle it better
if (!productStoreId) {
showToast(translate("No selected store found."))
return;
}
try {
// TODO Handle error case
const productStoreCategories = await this.store.dispatch('product/getPreOrderBackorderCategory', { productStoreId })
this.preOrderCategoryId = productStoreCategories["PCCT_PREORDR"];
this.backorderCategoryId = productStoreCategories["PCCT_BACKORDER"];
if (!this.preOrderCategoryId) {
showToast(translate("No pre-order category found"))
}
if (!this.backorderCategoryId) {
showToast(translate("No backorder category found"))
}
} catch (error) {
showToast(translate("Failed to get pre-order/backorder categories"))
}
await this.getShopifyConfigsByStore()
await this.getVariantDetails()
await this.getCtgryAndBrkrngJobs()
Expand Down Expand Up @@ -585,15 +607,14 @@ export default defineComponent({
showToast(this.$t("Something went wrong, could not fetch", { data: 'total ATP' }))
}
// TODO Make categoryIds dynamic
const hasPreOrderCategory = productCategories?.includes("PREORDER_CAT");
const hasBackorderCategory = productCategories?.includes("BACKORDER_CAT");
const hasPreOrderCategory = productCategories?.includes(this.preOrderCategoryId);
const hasBackorderCategory = productCategories?.includes(this.backorderCategoryId);
if (hasPreOrderCategory || hasBackorderCategory) {
payload = {
"inputFields": {
"productId": variantId,
"productCategoryId": hasPreOrderCategory ? "PREORDER_CAT" : "BACKORDER_CAT",
"productCategoryId": hasPreOrderCategory ? this.preOrderCategoryId : this.backorderCategoryId,
"productCategoryId_op": "equals"
},
"entityName": "ProductCategoryDcsnRsn",
Expand Down Expand Up @@ -794,15 +815,15 @@ export default defineComponent({
},
hasCategory() {
// TODO make categoryIds dynamic
return this.currentVariant.productCategories?.includes("PREORDER_CAT") || this.currentVariant.productCategories?.includes("BACKORDER_CAT");
return this.currentVariant.productCategories?.includes(this.preOrderCategoryId) || this.currentVariant.productCategories?.includes(this.backorderCategoryId);
},
async preparePoSummary() {
this.poSummary.eligible = this.poAndAtpDetails.totalPoAtp > 0 && this.atpCalcDetails.onlineAtp === 0;
this.poSummary.isActivePo = (this.poAndAtpDetails.activePo && Object.keys(this.poAndAtpDetails?.activePo).length) && this.poAndAtpDetails.onlineAtp > 0
// TODO Remove code for lastActivePoId
// this.poSummary.isLastActivePo = this.poAndAtpDetails.lastActivePoId && Object.keys(this.poAndAtpDetails?.activePo).length
this.poSummary.categoryId = this.currentVariant.productCategories?.includes("PREORDER_CAT") ? "PREORDER_CAT" : this.currentVariant.productCategories?.includes("BACKORDER_CAT") ? "BACKORDER_CAT" : ""
// const category = this.poSummary.categoryId === 'PREORDER_CAT' ? 'pre-order' : 'back-order'
this.poSummary.categoryId = this.currentVariant.productCategories?.includes(this.preOrderCategoryId) ? this.preOrderCategoryId : this.currentVariant.productCategories?.includes(this.backorderCategoryId) ? this.backorderCategoryId : ""
// const category = this.poSummary.categoryId === this.preOrderCategoryId ? 'pre-order' : 'back-order'
// Currently we are only having one shop listing condition
// will improve the logic as the listing conditions increase
this.poSummary.listedCount = this.shopListings.reduce((count: number, listData: any) =>
Expand Down Expand Up @@ -862,7 +883,7 @@ export default defineComponent({
}
},
isCategoryValid() {
const poCategoryId = this.poAndAtpDetails.activePo?.isNewProduct === "Y" ? "PREORDER_CAT" : "BACKORDER_CAT";
const poCategoryId = this.poAndAtpDetails.activePo?.isNewProduct === "Y" ? this.preOrderCategoryId : this.backorderCategoryId;
return (this.poSummary.eligible && this.poSummary.categoryId && (!this.poAndAtpDetails.activePo || poCategoryId === this.poSummary.categoryId) ) || (!this.poSummary.eligible && !this.poSummary.categoryId)
},
isShopifyListingValid() {
Expand Down

0 comments on commit f722748

Please sign in to comment.