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

@ -76,6 +76,13 @@ exports.mongoSanitize = (param) => {
return param;
};
exports.checkboxBool = (param) => {
if(param && param === 'on'){
return true;
}
return false;
};
// Middleware to check for admin access for certain route
exports.checkAccess = (req, res, next) => {
const routeCheck = _.find(restrictedRoutes, {'route': req.route.path});

View File

@ -468,7 +468,12 @@ $(document).ready(function (){
$.ajax({
method: 'POST',
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){
$('#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) => {
const db = req.app.db;
let productQuantity = req.body.productQuantity ? parseInt(req.body.productQuantity) : 1;
const productComment = req.body.productComment ? req.body.productComment : null;
// Don't allow negative quantity
if(productQuantity < 0){
@ -270,6 +271,7 @@ router.post('/product/addtocart', (req, res, next) => {
productObj.totalItemPrice = productPrice * productQuantity;
productObj.options = options;
productObj.productImage = product.productImage;
productObj.productComment = productComment;
if(product.productPermalink){
productObj.link = product.productPermalink;
}else{

View File

@ -85,6 +85,7 @@ router.post('/admin/product/insert', common.restrict, common.checkAccess, (req,
productPublished: req.body.frmProductPublished,
productTags: req.body.frmProductTags,
productOptions: req.body.productOptJson,
productComment: common.checkboxBool(req.body.frmProductComment),
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.productPermalink = req.body.frmProductPermalink;
req.session.productPermalink = req.body.productOptJson;
req.session.productComment = common.checkboxBool(req.body.frmProductComment);
req.session.productTags = req.body.frmProductTags;
// 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.productPermalink = req.body.frmProductPermalink;
req.session.productPermalink = req.body.productOptJson;
req.session.productComment = common.checkboxBool(req.body.frmProductComment);
req.session.productTags = req.body.frmProductTags;
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.productTags = req.body.frmProductTags;
req.session.productOptions = req.body.productOptJson;
req.session.productComment = common.checkboxBool(req.body.frmProductComment);
// redirect to insert
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,
productPermalink: req.body.frmProductPermalink,
productTags: req.body.frmProductTags,
productOptions: req.body.productOptJson
productOptions: req.body.productOptJson,
productComment: common.checkboxBool(req.body.frmProductComment)
};
// if no featured image

View File

@ -58,6 +58,9 @@
)
{{/if}}
<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>
{{/each}}
</ul>

View File

@ -99,6 +99,18 @@
<p class="help-block">Here you can set options for your product. Eg: Size, color, style</p>
</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">
<label for="frmProductTags" class="col-sm-2 control-label">Product tag words</label>
<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>
</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">
<label for="frmProductTags" class="col-sm-2 control-label">Product tag words</label>
<div class="col-sm-10">

View File

@ -50,6 +50,12 @@
</span>
</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">
<button class="btn btn-primary btn-block product-add-to-cart" type="button">Add to cart</button>
</div>

View File

@ -52,6 +52,12 @@
</span>
</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">
<button class="btn waves-effect waves-light blue darken-3 col s10 product-add-to-cart" type="button">Add to cart</button>
</div>

View File

@ -52,6 +52,12 @@
</span>
</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">
<button class="btn waves-effect waves-light black col s10 product-add-to-cart" type="button">Add to cart</button>
</div>