Added ability to add comments to product in order
parent
354f4e980e
commit
9d94ea0a80
|
@ -66,9 +66,9 @@ exports.checkLogin = (req, res, next) => {
|
|||
};
|
||||
|
||||
exports.mongoSanitize = (param) => {
|
||||
if (param instanceof Object) {
|
||||
for (const key in param) {
|
||||
if (/^\$/.test(key)) {
|
||||
if(param instanceof Object){
|
||||
for(const key in param){
|
||||
if(/^\$/.test(key)){
|
||||
delete param[key];
|
||||
}
|
||||
}
|
||||
|
@ -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});
|
||||
|
|
|
@ -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
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -3,59 +3,65 @@
|
|||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6 pull-right">
|
||||
<div class="row">
|
||||
<h1 class="col-md-10 product-title">{{result.productTitle}}</h1>
|
||||
<h4 class="col-md-10 product-price">{{currencySymbol config.currencySymbol}}{{result.productPrice}}</h4>
|
||||
{{#if productOptions}}
|
||||
<h4 class="col-md-10 product-option">Options</h4>
|
||||
<div class="col-md-10">
|
||||
{{#each productOptions}}
|
||||
{{#ifCond this.optType '==' "select"}}
|
||||
<strong>{{this.optName}}</strong>
|
||||
<select name="opt-{{this.optName}}" class="form-control product-opt">
|
||||
{{#each this.optOptions}}
|
||||
<option value="{{this}}">{{this}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
{{/ifCond}}
|
||||
{{#ifCond this.optType '==' "radio"}}
|
||||
{{#each this.optOptions}}
|
||||
<h1 class="col-md-10 product-title">{{result.productTitle}}</h1>
|
||||
<h4 class="col-md-10 product-price">{{currencySymbol config.currencySymbol}}{{result.productPrice}}</h4>
|
||||
{{#if productOptions}}
|
||||
<h4 class="col-md-10 product-option">Options</h4>
|
||||
<div class="col-md-10">
|
||||
{{#each productOptions}}
|
||||
{{#ifCond this.optType '==' "select"}}
|
||||
<strong>{{this.optName}}</strong>
|
||||
<div class="radio">
|
||||
<select name="opt-{{this.optName}}" class="form-control product-opt">
|
||||
{{#each this.optOptions}}
|
||||
<option value="{{this}}">{{this}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
{{/ifCond}}
|
||||
{{#ifCond this.optType '==' "radio"}}
|
||||
{{#each this.optOptions}}
|
||||
<strong>{{this.optName}}</strong>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" class="product-opt" name="opt-{{../this.optName}}" value="{{this}}">
|
||||
{{this}}
|
||||
</label>
|
||||
</div>
|
||||
{{/each}}
|
||||
{{/ifCond}}
|
||||
{{#ifCond this.optType '==' "checkbox"}}
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="radio" class="product-opt" name="opt-{{../this.optName}}" value="{{this}}">
|
||||
{{this}}
|
||||
<input type="checkbox" class="product-opt" name="opt-{{../this.optName}}" value="{{this.optName}}"><strong>{{this.optName}}</strong>
|
||||
</label>
|
||||
</div>
|
||||
{{/each}}
|
||||
{{/ifCond}}
|
||||
{{#ifCond this.optType '==' "checkbox"}}
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" class="product-opt" name="opt-{{../this.optName}}" value="{{this.optName}}"><strong>{{this.optName}}</strong>
|
||||
</label>
|
||||
</div>
|
||||
{{/ifCond}}
|
||||
{{/each}}
|
||||
{{/ifCond}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="col-md-10 productOptions">
|
||||
<p class="product-option-text">Quantity</p>
|
||||
<div class="input-group">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-primary qty-btn-minus" type="button">-</button>
|
||||
</span>
|
||||
<input type="text" class="form-control add-color text-center" id="product_quantity" maxlength="3" value="1">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-primary qty-btn-plus" type="button">+</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="col-md-10 productOptions">
|
||||
<p class="product-option-text">Quantity</p>
|
||||
<div class="input-group">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-primary qty-btn-minus" type="button">-</button>
|
||||
</span>
|
||||
<input type="text" class="form-control add-color text-center" id="product_quantity" maxlength="3" value="1">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-primary qty-btn-plus" type="button">+</button>
|
||||
</span>
|
||||
{{#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>
|
||||
<div class="col-md-10 body_text">
|
||||
{{{productDescription}}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-10 btnAddToCart">
|
||||
<button class="btn btn-primary btn-block product-add-to-cart" type="button">Add to cart</button>
|
||||
</div>
|
||||
<div class="col-md-10 body_text">
|
||||
{{{productDescription}}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6 pull-left">
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue