Hiding of specific sections based on the subsidiary checkboxes checked-in in the configuration records

Here we hide a specific section for specific subsidiaries and the subsidiaries for which the section need to hide is obtained based on the values obtained from the checkboxes in the configuration record.

Here we are taking an example of hiding a third party shipping section in the checkout page for specifically 4 subsidiaries. Here first we create 4 check boxes in the configuration record for the 4 subsidiaries so that the check box which is checked for a subsidiary will not show our required section. After creating the configuration records.

_.extend(shipView.prototype, {
				template: jj_ship_ship_tpl,

				getContext: _.wrap(shipView.prototype.getContext, function (fn) {
					let original_Ret = fn.apply(this, _.toArray(arguments).slice(1));
					try {
						var profile = ProfileModel.getInstance();
						var customersubsidiary = profile.get('subsidiary');
						var subsideryUK = SC.CONFIGURATION.subsidiaryList.subsidiaryUK;
						var subsidiaryNZ = SC.CONFIGURATION.subsidiaryList.subsidiaryNZ;
						var subsidiaryAU = SC.CONFIGURATION.subsidiaryList.subsidiaryAU;
						var subsidiaryNL = SC.CONFIGURATION.subsidiaryList.subsidiaryNL;
						var customerSubsidiariesToCheck = ['12', '1', '17', '8'];
						var isCustomerSubsidiaryMatch = customerSubsidiariesToCheck.includes(customersubsidiary);
						var thirdParty = false;
						
						if (isCustomerSubsidiaryMatch) {
							if (subsideryUK && (customersubsidiary === '12')) {
								thirdParty = true;
							}
							if (subsidiaryNZ && (customersubsidiary === '17')) {
								thirdParty = true;
							}
							if (subsidiaryAU && (customersubsidiary === '1')) {
								thirdParty = true;
							}
							if (subsidiaryNL && (customersubsidiary === '8')) {
								thirdParty = true;
							}
						}
						else {
							thirdParty = false;
						}
					} catch (error) {
						console.log('An error occurred in the third-party shipment:', error);
					}
					original_Ret.thirdParty = thirdParty;

					return original_Ret;
				}),
			})

Pass this thirdParty variable to the required template and you can hide the required things by creating conditions according to the requirement.

Leave a comment

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