Skip to content

Commit

Permalink
Added tracking number. Fixes #205
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvautin committed Oct 30, 2021
1 parent 642637c commit 41c997e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const restrictedRoutes = [
{ route: '/admin/product/setasmainimage', response: 'json' },
{ route: '/admin/product/deleteimage', response: 'json' },
{ route: '/admin/product/removeoption', response: 'json' },
{ route: '/admin/order/statusupdate', response: 'json' },
{ route: '/admin/order/updateorder', response: 'json' },
{ route: '/admin/settings/update', response: 'json' },
{ route: '/admin/settings/pages/new', response: 'redirect' },
{ route: '/admin/settings/pages/edit/:page', response: 'redirect' },
Expand Down
6 changes: 4 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,7 @@
"Product GTIN": "Product GTIN",
"The Serial number, GTIN or Barcode": "The Serial number, GTIN or Barcode",
"Product Brand": "Product Brand",
"The brand of the product": "The brand of the product"
}
"The brand of the product": "The brand of the product",
"Tracking number": "Tracking number",
"Update order": "Update order"
}
10 changes: 7 additions & 3 deletions public/javascripts/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,15 @@ $(document).ready(function (){
}
});

$(document).on('click', '#orderStatusUpdate', function(e){
$(document).on('click', '#orderUpdate', function(e){
$.ajax({
method: 'POST',
url: '/admin/order/statusupdate',
data: { order_id: $('#order_id').val(), status: $('#orderStatus').val() }
url: '/admin/order/updateorder',
data: {
order_id: $('#order_id').val(),
status: $('#orderStatus').val(),
trackingNumber: $('#trackingNumber').val()
}
})
.done(function(msg){
showNotification(msg.message, 'success', true);
Expand Down
20 changes: 12 additions & 8 deletions routes/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
clearCustomer
} = require('../lib/common');
const {
paginateData,
paginateData
} = require('../lib/paginate');
const {
emptyCart
Expand Down Expand Up @@ -279,18 +279,22 @@ router.get('/admin/order/delete/:id', restrict, async(req, res) => {
}
});

// update order status
router.post('/admin/order/statusupdate', restrict, checkAccess, async (req, res) => {
// update order
router.post('/admin/order/updateorder', restrict, checkAccess, async (req, res) => {
const db = req.app.db;
try{
const updateobj = { orderStatus: req.body.status };
if(req.body.trackingNumber){
// add tracking number
updateobj.trackingNumber = req.body.trackingNumber;
}
await db.orders.updateOne({
_id: getId(req.body.order_id) },
{ $set: { orderStatus: req.body.status }
}, { multi: false });
return res.status(200).json({ message: 'Status successfully updated' });
{ $set: updateobj }, { multi: false });
return res.status(200).json({ message: 'Order successfully updated' });
}catch(ex){
console.info('Error updating status', ex);
return res.status(400).json({ message: 'Failed to update the order status' });
console.info('Error updating order', ex);
return res.status(400).json({ message: 'Failed to update the order' });
}
});

Expand Down
6 changes: 3 additions & 3 deletions views/order.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<div class="order-layout col-md-12">
<div class="row">
<div class="col-md-12 bottom-pad-20">
<button id="orderStatusUpdate" class="btn btn-outline-success float-left">{{ @root.__ "Update status" }}</button>
<button id="orderUpdate" class="btn btn-outline-success float-left">{{ @root.__ "Update order" }}</button>
<a href="/admin/orders" class="btn btn-outline-info float-right">{{ @root.__ "Go Back" }}</a>
</div>
</div>
<ul class="list-group">
<li class="list-group-item list-group-input-pad">
<strong> Order status: </strong><span class="text-{{getStatusColor result.orderStatus}} float-right">{{result.orderStatus}}</span>
<div class="float-right col-md-2">
<select class="form-control" id="orderStatus">
<select class="form-control form-control-sm" id="orderStatus">
<option value="Completed">{{ @root.__ "Completed" }}</option>
<option value="Paid">{{ @root.__ "Paid" }}</option>
<option value="Pending">{{ @root.__ "Pending" }}</option>
Expand Down Expand Up @@ -54,8 +54,8 @@
<li class="list-group-item"><strong> {{ @root.__ "Postcode" }}: </strong><span class="float-right">{{result.orderPostcode}}</span></li>
<li class="list-group-item"><strong> {{ @root.__ "Phone number" }}: </strong><span class="float-right">{{result.orderPhoneNumber}}</span></li>
<li class="list-group-item"><strong> {{ @root.__ "Order type" }}: </strong><span class="float-right">{{result.orderType}}</span></li>
<li class="list-group-item"><strong> {{ @root.__ "Tracking number" }}: </strong><div class="float-right"><input class="form-control form-control-sm" id="trackingNumber" value="{{result.trackingNumber}}" /></div></li>
<li class="list-group-item"><strong> {{ @root.__ "Order comment" }}: </strong><span class="float-right">{{result.orderComment}}</span></li>

<li class="list-group-item">&nbsp;</li>
<li class="list-group-item"><strong class="text-info">{{ @root.__ "Products ordered" }}</strong></li>
{{#each result.orderProducts}}
Expand Down
3 changes: 3 additions & 0 deletions views/themes/Cloth/customer-account.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<li class="list-group-item"><strong> {{ @root.__ "State" }}: </strong><span class="float-right">{{this.orderState}}</span></li>
<li class="list-group-item"><strong> {{ @root.__ "Postcode" }}: </strong><span class="float-right">{{this.orderPostcode}}</span></li>
<li class="list-group-item"><strong> {{ @root.__ "Phone number" }}: </strong><span class="float-right">{{this.orderPhoneNumber}}</span></li>
{{#if this.trackingNumber }}
<li class="list-group-item"><strong> {{ @root.__ "Tracking number" }}: </strong><span class="float-right">{{this.trackingNumber}}</span></li>
{{/if}}
<li class="list-group-item">&nbsp;</li>
<li class="list-group-item"><strong class="text-info">{{ @root.__ "Products ordered" }}</strong></li>
{{#each this.orderProducts}}
Expand Down

0 comments on commit 41c997e

Please sign in to comment.