SFRA Server-side Javascript - Source: app_storefront_base/cartridge/controllers/ContactUs.js menu

SFRA / Server-side JS / Source: app_storefront_base/cartridge/controllers/ContactUs.js

  1. 'use strict';
  2. /**
  3. * @namespace ContactUs
  4. */
  5. var server = require('server');
  6. /**
  7. * ContactUs-Landing : This endpoint is called to load contact us landing page
  8. * @name Base/ContactUs-Landing
  9. * @function
  10. * @memberof ContactUs
  11. * @param {middleware} - server.middleware.https
  12. * @param {category} - sensitive
  13. * @param {renders} - isml
  14. * @param {serverfunction} - get
  15. */
  16. server.get('Landing', server.middleware.https, function (req, res, next) {
  17. var URLUtils = require('dw/web/URLUtils');
  18. res.render('contactUs/contactUs.isml', {
  19. actionUrl: URLUtils.url('ContactUs-Subscribe').toString()
  20. });
  21. next();
  22. });
  23. /**
  24. * ContactUs-Subscribe : This endpoint is called to submit the shopper's contact information
  25. * @name Base/ContactUs-Subscribe
  26. * @function
  27. * @memberof ContactUs
  28. * @param {middleware} - server.middleware.https
  29. * @param {httpparameter} - contactFirstName - First Name of the shopper
  30. * @param {httpparameter} - contactLastName - Last Name of the shopper
  31. * @param {httpparameter} - contactEmail - Email of the shopper
  32. * @param {httpparameter} - contactTopic - ID of the "Contact Us" topic
  33. * @param {httpparameter} - contactComment - Comments entered by the shopper
  34. * @param {category} - sensitive
  35. * @param {returns} - json
  36. * @param {serverfunction} - post
  37. */
  38. server.post('Subscribe', server.middleware.https, function (req, res, next) {
  39. var Resource = require('dw/web/Resource');
  40. var hooksHelper = require('*/cartridge/scripts/helpers/hooks');
  41. var emailHelper = require('*/cartridge/scripts/helpers/emailHelpers');
  42. var myForm = req.form;
  43. var isValidEmailid = emailHelper.validateEmail(myForm.contactEmail);
  44. if (isValidEmailid) {
  45. var contactDetails = [myForm.contactFirstName, myForm.contactLastName, myForm.contactEmail, myForm.contactTopic, myForm.contactComment];
  46. hooksHelper('app.contactUs.subscribe', 'subscribe', contactDetails, function () {});
  47. res.json({
  48. success: true,
  49. msg: Resource.msg('subscribe.to.contact.us.success', 'contactUs', null)
  50. });
  51. } else {
  52. res.json({
  53. error: true,
  54. msg: Resource.msg('subscribe.to.contact.us.email.invalid', 'contactUs', null)
  55. });
  56. }
  57. next();
  58. });
  59. module.exports = server.exports();