Update Free shipping countdown

Proposal Summary :

1)The tab will not appear on the website if shipping threshold is zero or undefined.

2)If we reach the shipping threshold, the text in the message should be ‘Free Shipping Applied’. 

3)If already SHIPPING METHOD is applied FREE for that then no need to show the tab or show ‘Free shipping already.

Solution :

To update the Free shipping countdown (CartScrollUpdate) extension for the following requirement.
1)The tab will not appear on the website if shipping threshold is zero or undefined.
We have to navigate through Commerce –> Websites –> Configuration. Then in the subtab click extensions and click Shipping Fee. Now change the value of Shipping threshold to zero and click the save button. Do the cache inivalidation then Empty cache. So if we go to the cart page the free shippment tab won’t be shown.

2)If we reach the shipping threshold, the text in the message should be ‘Free Shipping Applied’.
here we change the Shipping threshold value to 100 and click save button. Now if we go to the cart page the message will be shown Free Shipping Applied if the subtotal is more than the shipping threshold and if the subtotal is less than the shipping threshold then it will display how much amount we have to purchase further to get the free shipping.

3)If already SHIPPING METHOD is applied FREE for that then no need to show the tab or show ‘Free shipping already.
Navigate to Customization –> Lists, Records, & Fields –> Entity Fields –> New.
Create a new CheckBox named Free Shipping threshold. so this CheckBox will be disabled firstly and after one purchace with free shippment the checkbox will be enabled and the automatically.
Case 1 :
Checkbox is disable so the free shipping tab will be shown.

Case 2 :
Checkbox is enabled so the free shipping tab will not be shown.

Code :

CartScrollUpdate. Extension.

CartScrollUpdate.View.js

// @module JJ.CartSCrollUpdate.CartScrollUpdate
define('JJ.CartSCrollUpdate.CartScrollUpdate.View'
	, [
		'jj_cartscrollupdate_cartscrollupdate.tpl', 'Profile.Model'

		, 'Backbone'
	]
	, function (
		jj_cartscrollupdate_cartscrollupdate_tpl, Profile

		, Backbone  
	) {
		'use strict';

		// @class JJ.CartSCrollUpdate.CartScrollUpdate.View @extends Backbone.View
		return Backbone.View.extend({

			template: jj_cartscrollupdate_cartscrollupdate_tpl

			, initialize: function (options) {

				/*  Uncomment to test backend communication with an example service
					(you'll need to deploy and activate the extension first)
				*/

				// this.model = new CartScrollUpdateModel();
				// var self = this;
				// this.model.fetch().done(function(result) {
				// 	self.message = result.message;
				// 	self.render();
				// });
				console.log('Profile', Profile.getInstance())
				var profilevalue = Profile.getInstance();
				var customfeild = profilevalue.get('customfields')
				var threshold = _.findWhere(customfeild, { name: 'custentity_anx_free_shipping_threshold' });
				console.log(threshold.value, 'threshold')
				this.shippingthr = parseFloat(threshold.value).toFixed(2)
				this.subtotal = options.model.get('summary').subtotal
				console.log(this.shippingthr, this.subtotal)
				// console.log(this.shippingthr >= this.subtotal)
				if (this.shippingthr == 0) {
					this.HaveShippingFee = true;
				}
				else if (this.shippingthr > this.subtotal) {
					this.HaveShippingFee1 = true;
					this.threshold = parseFloat(this.shippingthr - this.subtotal).toFixed(2)
					this.percent = parseFloat(100 - (this.threshold / 100)).toFixed(2);
					console.log(this.percent)
				}

				else if (this.shippingthr < this.subtotal) {
					this.HaveShippingFee2 = true;
				}
			}
			, events: {
			}

			, bindings: {
			}

			, childViews: {

			}

			//@method getContext @return JJ.CartSCrollUpdate.CartScrollUpdate.View.Context
			, getContext: function getContext() {
				//@class JJ.CartSCrollUpdate.CartScrollUpdate.View.Context
				console.log(this.HaveShippingFee)
				return {
					threshold: this.threshold,
					percent: this.percent,
					HaveShippingFee: this.HaveShippingFee,
					HaveShippingFee1: this.HaveShippingFee1,
					HaveShippingFee2: this.HaveShippingFee2
				};
			}
		});
	});
  • JJ.CartSCrollUpdate.CartScrollUpdate.js
define(
	'JJ.CartSCrollUpdate.CartScrollUpdate', [
	'JJ.CartSCrollUpdate.CartScrollUpdate.View', 'Cart.Item.Actions.View', 'GlobalViews.Modal.View', 'Profile.Model', 'Cart.AddToCart.Button.View', 'Cart.Summary.View', 'Cart.Detailed.View', 'Header.MiniCart.View'
],
	function (
		CartScrollUpdateView, CartItemActionsView, GlobalViewsModalView, ProfileModel, CartAddToCartButtonView, CartSummaryView, CartDetailedView, HeaderMiniCartView
	) {
		'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');




				//prevent scroll on modal close
				var url = window.location.href;
				//	console.log('url', url)
				if (url.indexOf("cart") > -1) {
					_.extend(GlobalViewsModalView.prototype, {
						events: {
							'click .global-views-modal-content-header-close': "preventScroll"

						},
						preventScroll: function preventScroll(test2) {



							var globalid = this.options.childViewIstance.model.id;


							var elem1 = $('div[data-internalid = globalid]')

							if ($(window).width() < 769) {

								$("html, body").animate({
									scrollTop: $($("#" + globalid)).offset().top - 70
								}, 1000);
							}



						},

						getContext: _.wrap(GlobalViewsModalView.prototype.getContext, function (fn) {
							try {
								var original_Ret = fn.apply(this, _.toArray(arguments).slice(1));

								var test2 = this.options.childViewIstance.model.id;

							} catch (e) {
								console.log("err@barcode2View", e);
							}

							return original_Ret
						})
					});
				}
				_.extend(CartSummaryView.prototype.childViews, {
					ShippingThreshold: function () {
						return new CartScrollUpdateView({
							model: this.model,
							application: this.options.application
						});
					},

				});

				// **For Implementing the Cart sorting Functionality**

				_.extend(CartDetailedView.prototype, {
					initialize: _.wrap(CartDetailedView.prototype.initialize, function wrapInitialice(fn) {
						fn.apply(this, _.toArray(arguments).slice(1));
						var recordView = this;
						this.on('afterViewRender', function () {
							var newlines = recordView.model.get('lines').models;
							if (newlines.length > 0) {
								//Sorting Function
								recordView.model.get('lines').models = _.sortBy(newlines, function (data) {
									//For Getting sub category
									var category = data.get('item').get('custitem_product_category');
									if(category){
									const [category1, subcategory] = category.split(':');
									var finalsubcat = subcategory;}
									//For Getting Brand(Department)
									var brand = data.get('item').get('department');
									//Sorting condition
									var sortingcondition = (finalsubcat) ? (brand.concat(finalsubcat)) : brand;
									//console.log("sortingcondition", sortingcondition)
									data.sortingcondition = sortingcondition;
									return data.sortingcondition
								})
							}
						});
					}),
				});

			}
		};
	});

Leave a comment

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