Cleaned up old code and updated readme
parent
219e6b02fc
commit
8ce3074ba0
25
README.md
25
README.md
|
@ -67,23 +67,12 @@ Tags are used when indexing the products for search. It's advised to set tags (k
|
|||
|
||||
## Database
|
||||
|
||||
By default `expressCart` uses an embedded database for easy setup and backup. `expressCart` also supports a MongoDB connection and it's recommended if you expect high traffic to your website.
|
||||
|
||||
Setting of the database is done through the `/config/settings.json` file. There are two properties relating to the database connection:
|
||||
|
||||
Example embedded DB configuration:
|
||||
|
||||
```
|
||||
{
|
||||
"databaseType": "embedded"
|
||||
}
|
||||
```
|
||||
`expressCart` uses a MongoDB for storing all the data. Setting of the database connection string is done through the `/config/settings.json` file. There are two properties relating to the database connection:
|
||||
|
||||
Example MongoDB configuration:
|
||||
|
||||
```
|
||||
{
|
||||
"databaseType": "mongodb",
|
||||
"databaseConnectionString": "mongodb://localhost:27017/expresscart"
|
||||
}
|
||||
```
|
||||
|
@ -144,7 +133,6 @@ to ensure the `Products per page` is a multiple of 3 for the best look.
|
|||
|
||||
This is the number of products displayed per row on your website. You can select anywhere up to 4 `Products per row`.
|
||||
|
||||
|
||||
##### Menu enabled
|
||||
|
||||
Enables/disable the menu setup in `/admin/settings/menu`.
|
||||
|
@ -223,7 +211,7 @@ You can use the `Send test email` button to ensure your email settings are corre
|
|||
|
||||
## Menu
|
||||
|
||||
Although expressCart is a search based shopping cart, you can also group your products into categories using tags. You can then setup menu Items to "filter" based on
|
||||
Although `expressCart` is a search based shopping cart, you can also group your products into categories using tags. You can then setup menu Items to "filter" based on
|
||||
keywords (tags) to make it easier for your customers.
|
||||
|
||||
Setting of menu items is done via `/admin/settings/menu`.
|
||||
|
@ -240,12 +228,3 @@ You can re-order menu items by clicking and dragging the arrows icon and placing
|
|||
You may want to create a static page to show contact details, about us, shipping information etc.
|
||||
|
||||
New static pages are setup via `/admin/settings/pages`.
|
||||
|
||||
## Upgrade from embedded DB to MongoDB
|
||||
|
||||
If you start using an embedded DB and decide your website is needing a dedicated MongoDB server you can simply upgrade by following these steps:
|
||||
|
||||
1. **IMPORTANT** Backup your `/data` folder
|
||||
2. Ensure the MongoDB settings in the `/config/settings.json` file are added and are correct
|
||||
3. Run `npm run dbUpgrade`
|
||||
4. All done!
|
|
@ -95,15 +95,10 @@ router.get('/orders/filter/:search', common.restrict, (req, res, next) => {
|
|||
let db = req.app.db;
|
||||
let searchTerm = req.params.search;
|
||||
let ordersIndex = req.app.ordersIndex;
|
||||
let config = common.getConfig();
|
||||
|
||||
let lunrIdArray = [];
|
||||
ordersIndex.search(searchTerm).forEach((id) => {
|
||||
if(config.databaseType !== 'embedded'){
|
||||
lunrIdArray.push(common.getId(id.ref));
|
||||
}else{
|
||||
lunrIdArray.push(id.ref);
|
||||
}
|
||||
});
|
||||
|
||||
// we search on the lunr indexes
|
||||
|
@ -317,17 +312,12 @@ router.post('/product/emptycart', (req, res, next) => {
|
|||
// Admin section
|
||||
router.get('/products/filter/:search', common.restrict, (req, res, next) => {
|
||||
let db = req.app.db;
|
||||
let config = common.getConfig();
|
||||
let searchTerm = req.params.search;
|
||||
let productsIndex = req.app.productsIndex;
|
||||
|
||||
let lunrIdArray = [];
|
||||
productsIndex.search(searchTerm).forEach((id) => {
|
||||
if(config.databaseType !== 'embedded'){
|
||||
lunrIdArray.push(common.getId(id.ref));
|
||||
}else{
|
||||
lunrIdArray.push(id.ref);
|
||||
}
|
||||
});
|
||||
|
||||
// we search on the lunr indexes
|
||||
|
@ -422,10 +412,7 @@ router.post('/product/insert', common.restrict, (req, res) => {
|
|||
res.redirect('/admin/product/new');
|
||||
}else{
|
||||
// get the new ID
|
||||
let newId = newDoc._id;
|
||||
if(config.databaseType !== 'embedded'){
|
||||
newId = newDoc.insertedIds;
|
||||
}
|
||||
let newId = newDoc.insertedIds;
|
||||
|
||||
// add to lunr index
|
||||
common.indexProducts(req.app)
|
||||
|
|
|
@ -381,11 +381,7 @@ exports.orderMenu = function(req, res){
|
|||
|
||||
// gets the correct type of index ID
|
||||
exports.getId = function(id){
|
||||
let config = exports.getConfig();
|
||||
let ObjectID = require('mongodb').ObjectID;
|
||||
if(config.databaseType === 'embedded'){
|
||||
return id;
|
||||
}
|
||||
if(id){
|
||||
if(id.length !== 24){
|
||||
return id;
|
||||
|
|
|
@ -247,11 +247,7 @@ router.get('/search/:searchTerm/:pageNum?', (req, res) => {
|
|||
|
||||
let lunrIdArray = [];
|
||||
productsIndex.search(searchTerm).forEach((id) => {
|
||||
if(config.databaseType !== 'embedded'){
|
||||
lunrIdArray.push(common.getId(id.ref));
|
||||
}else{
|
||||
lunrIdArray.push(id.ref);
|
||||
}
|
||||
});
|
||||
|
||||
let pageNum = 1;
|
||||
|
@ -296,11 +292,7 @@ router.get('/category/:cat/:pageNum?', (req, res) => {
|
|||
|
||||
let lunrIdArray = [];
|
||||
productsIndex.search(searchTerm).forEach((id) => {
|
||||
if(config.databaseType !== 'embedded'){
|
||||
lunrIdArray.push(common.getId(id.ref));
|
||||
}else{
|
||||
lunrIdArray.push(id.ref);
|
||||
}
|
||||
lunrIdArray.push(common.getId(id.ref))
|
||||
});
|
||||
|
||||
let menuLink = _.find(common.getMenu().items, (obj) => { return obj.link === searchTerm; });
|
||||
|
@ -488,15 +480,6 @@ const getData = function (req, page, query, cb){
|
|||
console.error(colors.red('Error getting total product count', err));
|
||||
}
|
||||
|
||||
if(config.databaseType === 'embedded'){
|
||||
db.products.find(query).skip(skip).limit(parseInt(numberProducts)).exec((err, results) => {
|
||||
if(err){
|
||||
cb(new Error('Error retrieving products'), null);
|
||||
}else{
|
||||
cb(null, {data: results, totalProducts: totalProducts});
|
||||
}
|
||||
});
|
||||
}else{
|
||||
db.products.find(query).skip(skip).limit(parseInt(numberProducts)).toArray((err, results) => {
|
||||
if(err){
|
||||
cb(new Error('Error retrieving products'), null);
|
||||
|
@ -504,7 +487,6 @@ const getData = function (req, page, query, cb){
|
|||
cb(null, {data: results, totalProducts: totalProducts});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -74,16 +74,10 @@ router.get('/checkout_return', (req, res, next) => {
|
|||
if(err){
|
||||
console.info(err.stack);
|
||||
}
|
||||
let lunrDoc = {
|
||||
orderLastname: order.orderLastname,
|
||||
orderEmail: order.orderEmail,
|
||||
orderPostcode: order.orderPostcode,
|
||||
id: order._id
|
||||
};
|
||||
|
||||
// add to lunr index
|
||||
req.app.ordersIndex.add(lunrDoc);
|
||||
|
||||
common.indexOrders(req.app)
|
||||
.then(() => {
|
||||
// set the results
|
||||
req.session.messageType = 'success';
|
||||
req.session.message = paymentMessage;
|
||||
|
@ -106,6 +100,7 @@ router.get('/checkout_return', (req, res, next) => {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// The homepage of the site
|
||||
|
@ -194,12 +189,10 @@ router.post('/checkout_action', (req, res, next) => {
|
|||
}
|
||||
|
||||
// get the new ID
|
||||
let newId = newDoc._id;
|
||||
if(config.databaseType !== 'embedded'){
|
||||
let newId = '';
|
||||
if(newDoc.insertedIds.length > 0){
|
||||
newId = newDoc.insertedIds[0].toString();
|
||||
}
|
||||
}
|
||||
|
||||
// set the order ID in the session
|
||||
req.session.orderId = newId;
|
||||
|
|
|
@ -60,22 +60,11 @@ router.post('/checkout_action', (req, res, next) => {
|
|||
}
|
||||
|
||||
// get the new ID
|
||||
let newId = newDoc._id;
|
||||
if(config.databaseType !== 'embedded'){
|
||||
newId = newDoc.insertedIds;
|
||||
}
|
||||
|
||||
// create order to add to index
|
||||
let lunrDoc = {
|
||||
orderLastname: orderDoc.orderLastname,
|
||||
orderEmail: orderDoc.orderEmail,
|
||||
orderPostcode: orderDoc.orderPostcode,
|
||||
id: newId
|
||||
};
|
||||
let newId = newDoc.insertedIds;
|
||||
|
||||
// add to lunr index
|
||||
req.app.ordersIndex.add(lunrDoc);
|
||||
|
||||
common.indexOrders(req.app)
|
||||
.then(() => {
|
||||
// if approved, send email etc
|
||||
if(charge.paid === true){
|
||||
// set the results
|
||||
|
@ -116,6 +105,7 @@ router.post('/checkout_action', (req, res, next) => {
|
|||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
Loading…
Reference in New Issue