Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Example extension for implementing a custom result processor (PR #269) #270

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion config/default.json
Expand Up @@ -137,7 +137,8 @@
"mailchimp-subscribe",
"example-magento-api",
"cms-data",
"mail-service"
"mail-service",
"example-processor"
],
"extensions": {
"mailchimp": {
Expand All @@ -155,6 +156,11 @@
},
"targetAddressWhitelist": ["contributors@vuestorefront.io"],
"secretString": "__THIS_IS_SO_SECRET__"
},
"example-processor": {
"resultProcessors": {
"product": "my-product-processor"
}
}
},
"magento2": {
Expand Down
8 changes: 8 additions & 0 deletions src/api/extensions/example-processor/index.js
@@ -0,0 +1,8 @@
import { Router } from 'express'

module.exports = () => {

let exampleApi = Router()

return exampleApi
}
@@ -0,0 +1,21 @@
class MyProductProcessor {
constructor (config, request) {
this._request = request
this._config = config
}

process (productList) {
// Product search results can be modified here.
// For example, the following would add a paragraph to the short description of every product
//
// for (const prod of productList) {
// prod._source.short_description = prod._source.short_description + '<p class="cl-red fs-large">Free Shipping Today Only!</p>'
// }
//
// For a real-life example processor, see src/platform/magento2/tax.js
// For more details and another example, see https://docs.vuestorefront.io/guide/extensions/extensions-to-modify-results.html
return productList
}
}

module.exports = MyProductProcessor