Why does this ONLY work on my local? Even at that-...
# suitecommerce
k
Why does this ONLY work on my local? Even at that- it loads twice on every page, one for each item. It also works correctly when first go to the cart page, but if I make a change to quantity or something, the message then displays for ALL items. What is happening here?
Copy code
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');
			var Cart = container.getComponent('Cart');
			var ctx;
			// create a new map for the cart lines with the internalid as the key
			var cartLines = new Map();
			ctx = {
				isCart: false,
			};

			if(layout)
			{
				layout.addToViewContextDefinition(
          "ProductLine.Stock.View",
          "FWCExtras",
          "object",
          function (context) {
						console.log("Is Cart?", SC.Application.getLayout().getCurrentView() instanceof require('Cart.Detailed.View'))
						ctx.isCart = SC.Application.getLayout().getCurrentView() instanceof require('Cart.Detailed.View');
						
						if (Cart && SC.Application.getLayout().getCurrentView() instanceof require('Cart.Detailed.View')) {
							ctx.isCart = true;
							// Get the quantity of the item
							var quantityInCart = context.model.quantity;
							var isAutoBuild = context.model.item.custitem_auto_build;
							var buildableQuantity = context.model.item.custitem_buildable_quantity;

							// Cart.getLines().then(function(lines) {
							// 	// cartLines.set(line.internalid, line);
							// 	console.log("Line", lines);
							// });

							console.log("Context", context);
							if (isAutoBuild) {
								if (quantityInCart > buildableQuantity) {
									ctx.showCartQuantityMessage = true;
									ctx.buildableQuantity = buildableQuantity;
								}
								else {
									ctx.showCartQuantityMessage = false;
								}
							}
							return ctx;
						}
          }
        );
			}
		}
	};