Skip to content

Commit

Permalink
Merge pull request #34 from disha1202/#1xc2eqg
Browse files Browse the repository at this point in the history
Implemented logic to show product variants on the basis of the selected attribute(#1xc2eqg)
  • Loading branch information
adityasharma7 authored Jan 5, 2022
2 parents e5e0fe5 + 4c8eed5 commit 9a51855
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
6 changes: 6 additions & 0 deletions changelogs/unreleased/-1xc2eqg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Implemented logic to show product variants on the basis of the selected attribute(#1xc2eqg)
ticket_id: "#1xc2eqg"
merge_request: 34
author: Disha
type: added
42 changes: 36 additions & 6 deletions src/views/product-details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
<ion-list-header>{{ $t("Colors") }}</ion-list-header>
<ion-item lines="none">
<ion-row>
<ion-chip v-bind:key="colorFeature" v-for="colorFeature in $filters.getFeaturesList(current.product.featureHierarchy, '1/COLOR/')"> <ion-label>{{ colorFeature }}</ion-label></ion-chip>
<ion-chip v-bind:key="colorFeature" v-for="colorFeature in $filters.getFeaturesList(current.product.featureHierarchy, '1/COLOR/')" @click="filter(colorFeature, 'color')"> <ion-label>{{ colorFeature }}</ion-label></ion-chip>
</ion-row>
</ion-item>
</ion-list>
<ion-list>
<ion-list-header>{{ $t("Sizes") }} </ion-list-header>
<ion-item lines="none">
<ion-row>
<ion-chip v-bind:key="sizeFeature" v-for="sizeFeature in $filters.getFeaturesList(current.product.featureHierarchy, '1/SIZE/')"> <ion-label>{{ sizeFeature }}</ion-label></ion-chip>
<ion-chip v-bind:key="sizeFeature" v-for="sizeFeature in $filters.getFeaturesList(current.product.featureHierarchy, '1/SIZE/')" @click="filter(sizeFeature, 'size')"> <ion-label>{{ sizeFeature }}</ion-label></ion-chip>
</ion-row>
</ion-item>
</ion-list>
Expand Down Expand Up @@ -116,7 +116,7 @@

<!-- Variant -->
<div v-else>
<ion-card v-bind:key="item.groupValue" v-for="item in current.list.items">
<ion-card v-bind:key="item.groupValue" v-for="item in filteredProducts.list.items">
<div class="variant-info">
<ion-item lines="none">
<ion-thumbnail slot="start">
Expand Down Expand Up @@ -253,7 +253,11 @@ export default defineComponent({
selectedVariants: {} as any,
cusotmerLoyaltyOptions : JSON.parse(process.env?.VUE_APP_CUST_LOYALTY_OPTIONS),
cusotmerLoyalty: '',
hasPromisedDate: true
hasPromisedDate: true,
filters:{
color: [] as any,
size: [] as any
} as any
}
},
computed: {
Expand All @@ -264,10 +268,36 @@ export default defineComponent({
isJobPending: 'job/isJobPending',
jobTotal: 'job/getTotal',
userProfile: 'user/getUserProfile',
selectedBrand: 'user/getSelectedBrand'
})
selectedBrand: 'user/getSelectedBrand',
}),
filteredProducts () {
const filteredProducts = JSON.parse(JSON.stringify(this.current));
if(this.filters.size.length || this.filters.color.length){
filteredProducts.list.items = this.current.list.items.map((item: any)=>{
const product = this.getProduct(item.groupValue);
const hasSize = this.filters.size.some((sizeFeature: any) => {
return product.productFeatures.includes("Size/" + sizeFeature)
})
const hasColor = this.filters.color.some((colorFeature: any) => {
return product.productFeatures.includes("Color/" + colorFeature)
})
if (hasSize || hasColor) return item;
else return null
}).filter((product: any) => product);
}
return filteredProducts;
}
},
methods: {
filter (featureValue: any, type: any) {
if (this.filters[type].includes(featureValue)) {
const index = this.filters[type].indexOf(featureValue);
this.filters[type].splice(index,1);
}
else {
this.filters[type].push(featureValue);
}
},
async getVariantProducts() {
const payload = {
groupByField: 'productId',
Expand Down

0 comments on commit 9a51855

Please sign in to comment.