Added config to sort products
parent
e91b44074a
commit
ce2d6c5bd0
|
@ -31,6 +31,8 @@
|
|||
"maxQuantity": 25,
|
||||
"twitterHandle": "",
|
||||
"facebookAppId": "",
|
||||
"productOrderBy": "date",
|
||||
"productOrder": "descending",
|
||||
"modules": {
|
||||
"enabled": {
|
||||
"shipping": "shipping-basic",
|
||||
|
|
|
@ -124,6 +124,16 @@
|
|||
"facebookAppId": {
|
||||
"type": "string"
|
||||
},
|
||||
"productOrderBy": {
|
||||
"type": "string",
|
||||
"enum": ["date", "title"],
|
||||
"default": "date"
|
||||
},
|
||||
"productOrder": {
|
||||
"type": "string",
|
||||
"enum": ["descending", "ascending"],
|
||||
"default": "descending"
|
||||
},
|
||||
"modules": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -651,6 +651,22 @@ const paginateData = (frontend, req, page, collection, query, sort) => {
|
|||
});
|
||||
};
|
||||
|
||||
const getSort = () => {
|
||||
const config = getConfig();
|
||||
let sortOrder = -1;
|
||||
if(config.productOrder === 'ascending'){
|
||||
sortOrder = 1;
|
||||
}
|
||||
let sortField = 'productAddedDate';
|
||||
if(config.productOrderBy === 'title'){
|
||||
sortField = 'productTitle';
|
||||
}
|
||||
|
||||
return {
|
||||
[sortField]: sortOrder
|
||||
};
|
||||
};
|
||||
|
||||
const hooker = (order) => {
|
||||
const config = getConfig();
|
||||
|
||||
|
@ -708,6 +724,7 @@ module.exports = {
|
|||
getId,
|
||||
newId,
|
||||
paginateData,
|
||||
getSort,
|
||||
hooker,
|
||||
getCountryList,
|
||||
cleanAmount
|
||||
|
|
|
@ -17,6 +17,7 @@ const {
|
|||
emptyCart,
|
||||
updateSubscriptionCheck,
|
||||
paginateData,
|
||||
getSort,
|
||||
addSitemapProducts,
|
||||
getCountryList
|
||||
} = require('../lib/common');
|
||||
|
@ -731,7 +732,7 @@ router.get('/category/:cat/:pageNum?', (req, res) => {
|
|||
}
|
||||
|
||||
Promise.all([
|
||||
paginateData(true, req, pageNum, 'products', { _id: { $in: lunrIdArray } }),
|
||||
paginateData(true, req, pageNum, 'products', { _id: { $in: lunrIdArray } }, getSort()),
|
||||
getMenu(db)
|
||||
])
|
||||
.then(([results, menu]) => {
|
||||
|
@ -813,7 +814,7 @@ router.get('/page/:pageNum', (req, res, next) => {
|
|||
const numberProducts = config.productsPerPage ? config.productsPerPage : 6;
|
||||
|
||||
Promise.all([
|
||||
paginateData(true, req, req.params.pageNum, 'products'),
|
||||
paginateData(true, req, req.params.pageNum, 'products', {}, getSort()),
|
||||
getMenu(db)
|
||||
])
|
||||
.then(([results, menu]) => {
|
||||
|
@ -854,7 +855,7 @@ router.get('/:page?', async (req, res, next) => {
|
|||
// if no page is specified, just render page 1 of the cart
|
||||
if(!req.params.page){
|
||||
Promise.all([
|
||||
paginateData(true, req, 1, 'products', {}),
|
||||
paginateData(true, req, 1, 'products', {}, getSort()),
|
||||
getMenu(db)
|
||||
])
|
||||
.then(([results, menu]) => {
|
||||
|
|
Loading…
Reference in New Issue