From 41c997e3375c52bf35421b2eaca3a6a5bc386949 Mon Sep 17 00:00:00 2001 From: Mark Moffat Date: Sat, 30 Oct 2021 19:55:39 +1030 Subject: [PATCH] Added tracking number. Fixes #205 --- lib/auth.js | 2 +- locales/en.json | 6 ++++-- public/javascripts/admin.js | 10 +++++++--- routes/order.js | 20 ++++++++++++-------- views/order.hbs | 6 +++--- views/themes/Cloth/customer-account.hbs | 3 +++ 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index 55a2d826..a515394a 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -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' }, diff --git a/locales/en.json b/locales/en.json index 956d568b..bb0b66e7 100644 --- a/locales/en.json +++ b/locales/en.json @@ -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" +} \ No newline at end of file diff --git a/public/javascripts/admin.js b/public/javascripts/admin.js index d9662a9d..dadade80 100644 --- a/public/javascripts/admin.js +++ b/public/javascripts/admin.js @@ -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); diff --git a/routes/order.js b/routes/order.js index da7dd74e..34641987 100644 --- a/routes/order.js +++ b/routes/order.js @@ -8,7 +8,7 @@ const { clearCustomer } = require('../lib/common'); const { - paginateData, + paginateData } = require('../lib/paginate'); const { emptyCart @@ -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' }); } }); diff --git a/views/order.hbs b/views/order.hbs index 0357185c..e1ee4127 100644 --- a/views/order.hbs +++ b/views/order.hbs @@ -6,7 +6,7 @@
- + {{ @root.__ "Go Back" }}
@@ -14,7 +14,7 @@
  • Order status: {{result.orderStatus}}
    - @@ -54,8 +54,8 @@
  • {{ @root.__ "Postcode" }}: {{result.orderPostcode}}
  • {{ @root.__ "Phone number" }}: {{result.orderPhoneNumber}}
  • {{ @root.__ "Order type" }}: {{result.orderType}}
  • +
  • {{ @root.__ "Tracking number" }}:
  • {{ @root.__ "Order comment" }}: {{result.orderComment}}
  • -
  •  
  • {{ @root.__ "Products ordered" }}
  • {{#each result.orderProducts}} diff --git a/views/themes/Cloth/customer-account.hbs b/views/themes/Cloth/customer-account.hbs index df6a2eeb..988f6600 100644 --- a/views/themes/Cloth/customer-account.hbs +++ b/views/themes/Cloth/customer-account.hbs @@ -98,6 +98,9 @@
  • {{ @root.__ "State" }}: {{this.orderState}}
  • {{ @root.__ "Postcode" }}: {{this.orderPostcode}}
  • {{ @root.__ "Phone number" }}: {{this.orderPhoneNumber}}
  • + {{#if this.trackingNumber }} +
  • {{ @root.__ "Tracking number" }}: {{this.trackingNumber}}
  • + {{/if}}
  •  
  • {{ @root.__ "Products ordered" }}
  • {{#each this.orderProducts}}