Added ability to add comments to product in order

master
Mark Moffat 2018-10-05 21:24:42 +09:30
parent 354f4e980e
commit 9d94ea0a80
11 changed files with 117 additions and 53 deletions

View File

@ -66,9 +66,9 @@ exports.checkLogin = (req, res, next) => {
}; };
exports.mongoSanitize = (param) => { exports.mongoSanitize = (param) => {
if (param instanceof Object) { if(param instanceof Object){
for (const key in param) { for(const key in param){
if (/^\$/.test(key)) { if(/^\$/.test(key)){
delete param[key]; delete param[key];
} }
} }
@ -76,6 +76,13 @@ exports.mongoSanitize = (param) => {
return param; return param;
}; };
exports.checkboxBool = (param) => {
if(param && param === 'on'){
return true;
}
return false;
};
// Middleware to check for admin access for certain route // Middleware to check for admin access for certain route
exports.checkAccess = (req, res, next) => { exports.checkAccess = (req, res, next) => {
const routeCheck = _.find(restrictedRoutes, {'route': req.route.path}); const routeCheck = _.find(restrictedRoutes, {'route': req.route.path});

View File

@ -468,7 +468,12 @@ $(document).ready(function (){
$.ajax({ $.ajax({
method: 'POST', method: 'POST',
url: '/product/addtocart', url: '/product/addtocart',
data: {productId: $('#productId').val(), productQuantity: $('#product_quantity').val(), productOptions: JSON.stringify(productOptions)} data: {
productId: $('#productId').val(),
productQuantity: $('#product_quantity').val(),
productOptions: JSON.stringify(productOptions),
productComment: $('#product_comment').val()
}
}) })
.done(function(msg){ .done(function(msg){
$('#cart-count').text(msg.totalCartItems); $('#cart-count').text(msg.totalCartItems);

File diff suppressed because one or more lines are too long

View File

@ -218,6 +218,7 @@ router.post('/product/emptycart', (req, res, next) => {
router.post('/product/addtocart', (req, res, next) => { router.post('/product/addtocart', (req, res, next) => {
const db = req.app.db; const db = req.app.db;
let productQuantity = req.body.productQuantity ? parseInt(req.body.productQuantity) : 1; let productQuantity = req.body.productQuantity ? parseInt(req.body.productQuantity) : 1;
const productComment = req.body.productComment ? req.body.productComment : null;
// Don't allow negative quantity // Don't allow negative quantity
if(productQuantity < 0){ if(productQuantity < 0){
@ -270,6 +271,7 @@ router.post('/product/addtocart', (req, res, next) => {
productObj.totalItemPrice = productPrice * productQuantity; productObj.totalItemPrice = productPrice * productQuantity;
productObj.options = options; productObj.options = options;
productObj.productImage = product.productImage; productObj.productImage = product.productImage;
productObj.productComment = productComment;
if(product.productPermalink){ if(product.productPermalink){
productObj.link = product.productPermalink; productObj.link = product.productPermalink;
}else{ }else{

View File

@ -85,6 +85,7 @@ router.post('/admin/product/insert', common.restrict, common.checkAccess, (req,
productPublished: req.body.frmProductPublished, productPublished: req.body.frmProductPublished,
productTags: req.body.frmProductTags, productTags: req.body.frmProductTags,
productOptions: req.body.productOptJson, productOptions: req.body.productOptJson,
productComment: common.checkboxBool(req.body.frmProductComment),
productAddedDate: new Date() productAddedDate: new Date()
}; };
@ -103,6 +104,7 @@ router.post('/admin/product/insert', common.restrict, common.checkAccess, (req,
req.session.productPrice = req.body.frmProductPrice; req.session.productPrice = req.body.frmProductPrice;
req.session.productPermalink = req.body.frmProductPermalink; req.session.productPermalink = req.body.frmProductPermalink;
req.session.productPermalink = req.body.productOptJson; req.session.productPermalink = req.body.productOptJson;
req.session.productComment = common.checkboxBool(req.body.frmProductComment);
req.session.productTags = req.body.frmProductTags; req.session.productTags = req.body.frmProductTags;
// redirect to insert // redirect to insert
@ -118,6 +120,7 @@ router.post('/admin/product/insert', common.restrict, common.checkAccess, (req,
req.session.productPrice = req.body.frmProductPrice; req.session.productPrice = req.body.frmProductPrice;
req.session.productPermalink = req.body.frmProductPermalink; req.session.productPermalink = req.body.frmProductPermalink;
req.session.productPermalink = req.body.productOptJson; req.session.productPermalink = req.body.productOptJson;
req.session.productComment = common.checkboxBool(req.body.frmProductComment);
req.session.productTags = req.body.frmProductTags; req.session.productTags = req.body.frmProductTags;
req.session.message = 'Error: Inserting product'; req.session.message = 'Error: Inserting product';
@ -207,6 +210,7 @@ router.post('/admin/product/update', common.restrict, common.checkAccess, (req,
req.session.productPermalink = req.body.frmProductPermalink; req.session.productPermalink = req.body.frmProductPermalink;
req.session.productTags = req.body.frmProductTags; req.session.productTags = req.body.frmProductTags;
req.session.productOptions = req.body.productOptJson; req.session.productOptions = req.body.productOptJson;
req.session.productComment = common.checkboxBool(req.body.frmProductComment);
// redirect to insert // redirect to insert
res.redirect('/admin/product/edit/' + req.body.frmProductId); res.redirect('/admin/product/edit/' + req.body.frmProductId);
@ -219,7 +223,8 @@ router.post('/admin/product/update', common.restrict, common.checkAccess, (req,
productPrice: req.body.frmProductPrice, productPrice: req.body.frmProductPrice,
productPermalink: req.body.frmProductPermalink, productPermalink: req.body.frmProductPermalink,
productTags: req.body.frmProductTags, productTags: req.body.frmProductTags,
productOptions: req.body.productOptJson productOptions: req.body.productOptJson,
productComment: common.checkboxBool(req.body.frmProductComment)
}; };
// if no featured image // if no featured image

View File

@ -58,6 +58,9 @@
) )
{{/if}} {{/if}}
<div class="pull-right">{{currencySymbol config.currencySymbol}}{{formatAmount this.totalItemPrice}}</div> <div class="pull-right">{{currencySymbol config.currencySymbol}}{{formatAmount this.totalItemPrice}}</div>
{{#if productComment}}
<h4><span class="text-danger">Comment:</span> {{this.productComment}}</h4>
{{/if}}
</li> </li>
{{/each}} {{/each}}
</ul> </ul>

View File

@ -99,6 +99,18 @@
<p class="help-block">Here you can set options for your product. Eg: Size, color, style</p> <p class="help-block">Here you can set options for your product. Eg: Size, color, style</p>
</div> </div>
</div> </div>
<div class="form-group">
<label for="frmProductComment" class="col-sm-2 control-label">Allow comment</label>
<div class="col-sm-10">
<div class="checkbox">
<label>
<input class="frmProductComment" type="checkbox" {{checkedState result.productComment}} id="frmProductComment"
name="frmProductComment">
</label>
</div>
<p class="help-block">Allow free form comments when adding products to cart</p>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="frmProductTags" class="col-sm-2 control-label">Product tag words</label> <label for="frmProductTags" class="col-sm-2 control-label">Product tag words</label>
<div class="col-sm-10"> <div class="col-sm-10">

View File

@ -98,6 +98,18 @@
<p class="help-block">Here you can set options for your product. Eg: Size, color, style</p> <p class="help-block">Here you can set options for your product. Eg: Size, color, style</p>
</div> </div>
</div> </div>
<div class="form-group">
<label for="frmProductComment" class="col-sm-2 control-label">Allow comment</label>
<div class="col-sm-10">
<div class="checkbox">
<label>
<input class="frmProductComment" type="checkbox" {{checkedState result.productComment}} id="frmProductComment"
name="frmProductComment">
</label>
</div>
<p class="help-block">Allow free form comments when adding products to cart</p>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="frmProductTags" class="col-sm-2 control-label">Product tag words</label> <label for="frmProductTags" class="col-sm-2 control-label">Product tag words</label>
<div class="col-sm-10"> <div class="col-sm-10">

View File

@ -50,6 +50,12 @@
</span> </span>
</div> </div>
</div> </div>
{{#if result.productComment}}
<div class="col-md-10">
Leave a comment?
<textarea class="form-control" id="product_comment"></textarea>
</div>
{{/if}}
<div class="col-md-10 btnAddToCart"> <div class="col-md-10 btnAddToCart">
<button class="btn btn-primary btn-block product-add-to-cart" type="button">Add to cart</button> <button class="btn btn-primary btn-block product-add-to-cart" type="button">Add to cart</button>
</div> </div>

View File

@ -52,6 +52,12 @@
</span> </span>
</div> </div>
</div> </div>
{{#if result.productComment}}
<div class="col-md-10">
Leave a comment?
<textarea class="form-control" id="product_comment"></textarea>
</div>
{{/if}}
<div class="btnAddToCart"> <div class="btnAddToCart">
<button class="btn waves-effect waves-light blue darken-3 col s10 product-add-to-cart" type="button">Add to cart</button> <button class="btn waves-effect waves-light blue darken-3 col s10 product-add-to-cart" type="button">Add to cart</button>
</div> </div>

View File

@ -52,6 +52,12 @@
</span> </span>
</div> </div>
</div> </div>
{{#if result.productComment}}
<div class="col-md-10">
Leave a comment?
<textarea class="form-control" id="product_comment"></textarea>
</div>
{{/if}}
<div class="btnAddToCart"> <div class="btnAddToCart">
<button class="btn waves-effect waves-light black col s10 product-add-to-cart" type="button">Add to cart</button> <button class="btn waves-effect waves-light black col s10 product-add-to-cart" type="button">Add to cart</button>
</div> </div>