add: flatten collection title, tag value, and type value fields
This commit is contained in:
1 parent
c67ca16a9b
commit
560cc0de55
5 files changed
+29
-23
No files matched your search
@@ -12,8 +12,8 @@ Meilisearch Plugin for Medusa to search for products.
|
|||||||
[indexName]: [meilisearch settings passed to meilisearch's `updateSettings()` method]
|
[indexName]: [meilisearch settings passed to meilisearch's `updateSettings()` method]
|
||||||
// example
|
// example
|
||||||
products: {
|
products: {
|
||||||
searchableAttributes: ["title", "description", "sku"],
|
searchableAttributes: ["title", "description", "variant_sku", "type_value"],
|
||||||
displayedAttributes: ["title", "description", "sku"],
|
displayedAttributes: ["title", "description", "variant_sku", "type_value"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { transformProduct } from "../utils/transform-products"
|
import { transformProduct } from "../utils/transform-product"
|
||||||
|
|
||||||
const INDEX_NS = "medusa-commerce"
|
const INDEX_NS = "medusa-commerce"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { transformProduct } from "../utils/transform-products"
|
import { transformProduct } from "../utils/transform-product"
|
||||||
|
|
||||||
class ProductSearchSubscriber {
|
class ProductSearchSubscriber {
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
const variantKeys = ["sku", "title", "upc", "ean", "mid_code", "hs_code"]
|
||||||
|
const prefix = `variant`
|
||||||
|
|
||||||
|
export const transformProduct = (product) => {
|
||||||
|
const initialObj = variantKeys.reduce((obj, key) => {
|
||||||
|
obj[`${prefix}_${key}`] = []
|
||||||
|
return obj
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
const flattenedVariantFields = product.variants.reduce((obj, variant) => {
|
||||||
|
variantKeys.forEach(
|
||||||
|
(k) => variant[k] && obj[`${prefix}_${k}`].push(variant[k])
|
||||||
|
)
|
||||||
|
return obj
|
||||||
|
}, initialObj)
|
||||||
|
|
||||||
|
product.type_value = product.type && product.type.value
|
||||||
|
product.collection_title = product.collection && product.collection.title
|
||||||
|
product.tags_value = product.tags.map((t) => t.value)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...product,
|
||||||
|
...flattenedVariantFields,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
const keys = ["sku", "title", "upc", "ean", "mid_code", "hs_code"]
|
|
||||||
const prefix = `variant`
|
|
||||||
|
|
||||||
export const transformProduct = (product) => {
|
|
||||||
const initialObj = keys.reduce((obj, key) => {
|
|
||||||
obj[`${prefix}_${key}`] = []
|
|
||||||
return obj
|
|
||||||
}, {})
|
|
||||||
|
|
||||||
const flattenedFields = product.variants.reduce((obj, variant) => {
|
|
||||||
keys.forEach((k) => variant[k] && obj[`${prefix}_${k}`].push(variant[k]))
|
|
||||||
return obj
|
|
||||||
}, initialObj)
|
|
||||||
|
|
||||||
return {
|
|
||||||
...product,
|
|
||||||
...flattenedFields,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user