Extension to customise the review page error message

Create extension to customise the error message on place order in review page. Error message will show when ordered quantity is greater than available quantity of item.

JJ.Reviewoutofstock.Reviewoutofstock.js file


define(
	'JJ.Reviewoutofstock.Reviewoutofstock'
,   [
		'JJ.Reviewoutofstock.Reviewoutofstock.View','GlobalViews.Message.View','LiveOrder.Model'
	]
,   function (
		ReviewoutofstockView,GlobalViewsMessageView,LiveOrderModel
	)
{
	'use strict';

	return  {
		mountToApp: function mountToApp (container)
		{
			// using the 'Layout' component we add a new child view inside the 'Header' existing view 
			// (there will be a DOM element with the HTML attribute data-view="Header.Logo")
			// more documentation of the Extensibility API in
			// https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Frontend/index.html
			
			/** @type {LayoutComponent} */
			var layout = container.getComponent('Layout');
			
			if(layout)
			{
				layout.addChildView('Header.Logo', function() { 
					return new ReviewoutofstockView({ container: container });
				});
			}
			_.extend(GlobalViewsMessageView.prototype,{

				getContext: _.wrap(GlobalViewsMessageView.prototype.getContext, function (fn) {

				var context = fn.apply(this, _.toArray(arguments).slice(1));
                console.log("context",context);
				var liveorder=LiveOrderModel.getInstance();
				console.log("liveorder",liveorder);
				const itemname=[];
				const orderdquantity=[];
				const availablequantity=[];
				context.name='';
				var url = window.location.href;
				console.log("password incorect mesg url",url.indexOf("review"));
				if (url.indexOf("review") > -1) {
				console.log('abbb')
				
				var itemid=liveorder.attributes.lines.models[0].attributes.item.attributes.itemid
				console.log("itemid",itemid);
				console.log("length",liveorder.attributes.lines.length);

				for (var i = 0; i <liveorder.attributes.lines.length; i++) {

					itemname[i] = liveorder.attributes.lines.models[i].attributes.item.attributes.displayname;
					orderdquantity[i] = liveorder.attributes.lines.models[i].attributes.quantity;
					availablequantity[i] = liveorder.attributes.lines.models[i].attributes.item.attributes.quantityavailable;
					console.log("oqty", itemname[i])
					console.log("oqty", orderdquantity[i])
					console.log("oqty", availablequantity[i])
					if (orderdquantity[i] > availablequantity[i]) {
	
						 context.name = context.name + ' ' + itemname[i] + ', ';
						 console.log("context-name",context.name)
						 
						 $(".order-wizard-submitbutton-module-button").prop("disabled", true);
						 
	
					}
					else {
						$(".order-wizard-submitbutton-module-button").prop("disabled", false);
					}
				}
				context.name = context.name.replace(/,*$/, '');
				console.log("context-name",context)
			}
			return context;
				})

			})

		}
	};
});

In the global_views_message.tpl file change code

<div class="global-views-message {{type}} alert" role="alert">
	<div>
		{{#if showStringMessage}}
			{{#if showMultipleMessage}}
				<ul>
				{{#each messages}}
					<li>{{{this}}}</li>
				{{/each}}
				<ul>
			{{else}}
				{{#if hasErrorCode}}
					{{{message}}}<span class="alert-error-code">{{translate 'CODE'}}: {{errorCode}}</span>
				{{else}}
				    {{#if name}}
				        {{name}}{{{message}}}
				    {{else}}
					    {{{message}}}
				    {{/if}}
				{{/if}}
			{{/if}}
		{{else}}
			<div data-view="global-views-message-childview-message"></div>
		{{/if}}
	</div>
	{{#if closable}}
		<button class="global-views-message-button" data-action="close-message" type="button" data-dismiss="alert">&times;</button>
	{{/if}}
</div>

Leave a comment

Your email address will not be published. Required fields are marked *