🔨 refactor: filter one product vatiant

:%s
This commit is contained in:
DatNguyen
2021-10-11 13:38:48 +07:00
parent 820e93652f
commit 587eb5d1bc
8 changed files with 26 additions and 9 deletions

View File

@@ -31,6 +31,7 @@ const ProductCardComponent = ({
isNotSell,
isSingleButton,
productVariantId,
productVariantName
}: ProductCardProps) => {
const {addProduct,loading} = useAddProductToCart()
@@ -84,7 +85,7 @@ const ProductCardComponent = ({
<div className={s.cardMidTop}>
<Link href={`${ROUTE.PRODUCT_DETAIL}/${slug}`}>
<a>
<div className={s.productname}>{name} </div>
<div className={s.productname}>{productVariantName} </div>
</a>
</Link>
<div className={s.productWeight}>{weight}</div>

View File

@@ -1,4 +1,5 @@
import { Facet } from "@commerce/types/facet";
import { ProductCard } from "@commerce/types/product";
import { Collection, FacetValue, SearchResultSortParameter } from './../../framework/vendure/schema.d';
import { CODE_FACET_DISCOUNT, CODE_FACET_FEATURED, CODE_FACET_FEATURED_VARIANT, FACET, PRODUCT_SORT_OPTION_VALUE } from "./constanst.utils";
import { PromiseWithKey, SortOrder } from "./types.utils";
@@ -139,4 +140,16 @@ export const getCategoryNameFromCollectionId = (colelctions: Collection[], colle
export function getAllPromies(promies: PromiseWithKey[]) {
return promies.map(item => item.promise)
}
export const FilterOneVatiant = (products:ProductCard[]) => {
let idList:string[] = []
let filtedProduct: ProductCard[]=[]
products.map((product:ProductCard)=>{
if(!idList.includes(product.id)){
filtedProduct.push(product)
idList.push(product.id)
}
})
return filtedProduct
}