diff --git a/README.md b/README.md index c78266c..1ea1279 100644 --- a/README.md +++ b/README.md @@ -249,11 +249,6 @@ Enables/disable the menu setup in `/admin/settings/menu`. This is the text which will be displayed at the top of your menu. -##### Menu position - -You can set position where your menu will be displayed. Setting the value to `side` will position the menu to the left of your products, setting the value to `top` -will create a 'breadcrumb' menu at the top of the page - ##### Paypal (Payments) The Paypal config file is located: `/config/payment/config/paypal.json`. A example Paypal settings file is provided: diff --git a/config/settings.json b/config/settings.json index 18b2eab..c926075 100644 --- a/config/settings.json +++ b/config/settings.json @@ -40,5 +40,6 @@ "shipping": {}, "discount": {} } - } + }, + "showRelatedProducts": true } \ No newline at end of file diff --git a/config/settingsSchema.json b/config/settingsSchema.json index ac4a7a4..5b6e63d 100644 --- a/config/settingsSchema.json +++ b/config/settingsSchema.json @@ -143,6 +143,10 @@ "shipping": "shipping-basic" } } + }, + "showRelatedProducts": { + "type": "boolean", + "default": true } }, "required": [ diff --git a/locales/en.json b/locales/en.json index 761a045..368d95f 100644 --- a/locales/en.json +++ b/locales/en.json @@ -203,5 +203,7 @@ "Currency ISO": "Currency ISO", "Currency used for Blockonomics conversion": "Currency used for Blockonomics conversion", "Logout": "Logout", - "Company": "Company" + "Company": "Company", + "View": "View", + "Related products": "Related products" } \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index c3a837d..a803161 100644 --- a/routes/index.js +++ b/routes/index.js @@ -337,6 +337,7 @@ router.post('/checkout/removediscountcode', async (req, res) => { router.get('/product/:id', async (req, res) => { const db = req.app.db; const config = req.app.config; + const productsIndex = req.app.productsIndex; const product = await db.products.findOne({ $or: [{ _id: getId(req.params.id) }, { productPermalink: req.params.id }] }); if(!product){ @@ -358,11 +359,29 @@ router.get('/product/:id', async (req, res) => { // show the view const images = await getImages(product._id, req, res); + // Related products + let relatedProducts = {}; + if(config.showRelatedProducts){ + const lunrIdArray = []; + const productTags = product.productTags.split(','); + const productTitleWords = product.productTitle.split(' '); + const searchWords = productTags.concat(productTitleWords); + searchWords.forEach((word) => { + productsIndex.search(word).forEach((id) => { + lunrIdArray.push(getId(id.ref)); + }); + }); + relatedProducts = await db.products.find({ + _id: { $in: lunrIdArray, $ne: product._id } + }).limit(4).toArray(); + } + res.render(`${config.themeViews}product`, { title: product.productTitle, result: product, productOptions: productOptions, images: images, + relatedProducts, productDescription: stripHtml(product.productDescription), metaDescription: config.cartTitle + ' - ' + product.productTitle, config: config, diff --git a/views/themes/Cloth/product.hbs b/views/themes/Cloth/product.hbs index 857a713..f3618f4 100644 --- a/views/themes/Cloth/product.hbs +++ b/views/themes/Cloth/product.hbs @@ -97,5 +97,59 @@ + {{#if config.showRelatedProducts}} + {{#if relatedProducts}} +
+

Related products

+
+ {{#each relatedProducts}} +
+
+ {{#if productPermalink}} + + {{else}} + +
+ {{#if productImage}} + ... + {{else}} + ... + {{/if}} +
+

+ {{this.productTitle}} +

+
+ {{/if}} +

+ {{currencySymbol ../config.currencySymbol}}{{formatAmount productPrice}} +

+

+ {{#if productPermalink}} + {{ @root.__ "View" }} + {{else}} + {{ @root.__ "View" }} + {{/if}} +

+
+
+ {{/each}} +
+
+ {{/if}} + {{/if}} \ No newline at end of file