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