Kevin Carpenter
12/13/2022, 4:16 PMPDP
and never Cart
even when I am in the Cart?
var PDP = container.getComponent('PDP');
var Cart = container.getComponent('Cart');
if (PDP) {
console.log("PDP Component");
}
else if (Cart) {
console.log("Cart Component");
}
After this conditional works... I want to iterate over the lines in the cart, compare the quantity in cart to the quantity available and display a Stock Info Message. How would one do that?Steve Goldberg
12/13/2022, 4:24 PMif (PDP)
only checks for the existence of the PDP component, not whether you on a product detail page specificallyKevin Carpenter
12/13/2022, 4:26 PMSteve Goldberg
12/13/2022, 4:27 PMSteve Goldberg
12/13/2022, 4:29 PMSC.Application.getLayout().getCurrentView() instanceof require('ProductDetails.Full.View')
Steve Goldberg
12/13/2022, 4:29 PMSteve Goldberg
12/13/2022, 4:29 PMSteve Goldberg
12/13/2022, 4:30 PMSteve Goldberg
12/13/2022, 4:30 PMKevin Carpenter
12/13/2022, 4:31 PMKevin Carpenter
12/13/2022, 4:31 PMKevin Carpenter
12/13/2022, 4:31 PMreturn {
mountToApp: function (container) {
var Cart = container.getComponent('Cart');
if (Cart) {
console.log("Cart Component");
Cart.getLines().then(function(lines) {
console.log("Line: " , lines);
});
}
}
}
});
Kevin Carpenter
12/13/2022, 4:32 PMSteve Goldberg
12/13/2022, 4:32 PMKevin Carpenter
12/13/2022, 4:32 PMKevin Carpenter
12/13/2022, 4:32 PMStockMessage
by comparing the quantity available to the quantity of each lineKevin Carpenter
12/13/2022, 4:32 PMShowOutOfStockMessage
and Message for each line, if that conditional is met.Steve Goldberg
12/13/2022, 4:33 PMKevin Carpenter
12/13/2022, 4:33 PMboolean
by doing this
PDP.addToViewContextDefinition(
"ProductLine.Stock.View",
"showOutOfStockMessage",
"boolean",
Kevin Carpenter
12/13/2022, 4:33 PMSteve Goldberg
12/13/2022, 4:34 PMSteve Goldberg
12/13/2022, 4:34 PMKevin Carpenter
12/13/2022, 4:35 PMshowoutofstockmessage
boolean on each lineSteve Goldberg
12/13/2022, 4:35 PMKevin Carpenter
12/13/2022, 4:35 PMSteve Goldberg
12/13/2022, 4:35 PMKevin Carpenter
12/13/2022, 4:35 PMKevin Carpenter
12/13/2022, 4:36 PMSteve Goldberg
12/13/2022, 4:36 PMSteve Goldberg
12/13/2022, 4:36 PMKevin Carpenter
12/13/2022, 4:36 PMKevin Carpenter
12/13/2022, 4:36 PMSteve Goldberg
12/13/2022, 4:36 PMKevin Carpenter
12/13/2022, 4:37 PMKevin Carpenter
12/13/2022, 4:38 PMSteve Goldberg
12/13/2022, 4:38 PMKevin Carpenter
12/13/2022, 4:38 PMSteve Goldberg
12/13/2022, 4:38 PMKevin Carpenter
12/13/2022, 4:38 PMSteve Goldberg
12/13/2022, 4:39 PMSteve Goldberg
12/13/2022, 4:39 PMSteve Goldberg
12/13/2022, 4:39 PMSteve Goldberg
12/13/2022, 4:40 PMSteve Goldberg
12/13/2022, 4:41 PMKevin Carpenter
12/13/2022, 4:41 PMKevin Carpenter
12/13/2022, 4:43 PMadd a new property to the context object
?Kevin Carpenter
12/13/2022, 4:43 PMKevin Carpenter
12/13/2022, 4:54 PMGetLines
method, then just addToViewContextDefinition
in a few views and return an object containing a boolean, and a field for text?Steve Goldberg
12/13/2022, 4:55 PMSteve Goldberg
12/13/2022, 4:56 PMSteve Goldberg
12/13/2022, 4:56 PMKevin Carpenter
12/13/2022, 5:16 PM<div class="cart-lines-stock" data-view="<http://Product.Stock.Info|Product.Stock.Info>"></div>
Kevin Carpenter
12/13/2022, 5:16 PMCart.Lines.View
and Product.Stock.View
Kevin Carpenter
12/13/2022, 5:32 PMProduct.Stock.View
from two different places... the PDP and the Cart, which is weird.Kevin Carpenter
12/14/2022, 7:01 AMSC.Application.getLayout().getCurrentView() instanceof require('Cart.Detailed.View')
Steve Goldberg
12/14/2022, 11:43 AMSteve Goldberg
12/14/2022, 11:43 AMSteve Goldberg
12/14/2022, 11:43 AMSteve Goldberg
12/14/2022, 11:44 AMcontainer
when it is passed into the mountToApp
function) and if you want to ‘require’ a module, you should add it as a dependency to your custom moduleKevin Carpenter
12/14/2022, 11:45 AMdefine(
'Fwc.OutOfStockCart.OutOfStockCart'
, [
'Fwc.OutOfStockCart.OutOfStockCart.View'
]
, function (
OutOfStockCartView
)
{
'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');
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
Kevin Carpenter
12/14/2022, 11:46 AMKevin Carpenter
12/14/2022, 11:47 AMKevin Carpenter
12/14/2022, 11:47 AMSC.Application.getLayout().getCurrentView() instanceof require('Cart.Detailed.View')
works in my extensionKevin Carpenter
12/14/2022, 11:48 AMSteve Goldberg
12/14/2022, 11:56 AMI would add what to the dependency array?The module you want to compare — the one you are using
require
for. In your example, Cart.Detailed.View.
• It runs twice on every page loadThis can happen sometimes with some code. I do not know why but it’s something I’ve observed before. If it really bothers you, you could create a variable that tracks how many times something has fired and ensure it only fires it once.
It will. It’s not ‘incorrect’, it’s just following unrecommended coding practices.works in my extensionSC.Application.getLayout().getCurrentView() instanceof require('Cart.Detailed.View')
All I want to do is use the “ProductLine.Stock.View” view, check if in the cart, then iterate over each line in the cart. But thats proving to be VERY difficult.I recommend completing our training course or, at least, following my beginners’ tutorial before attempting to create customisations.
Kevin Carpenter
12/14/2022, 11:59 AMSteve Goldberg
12/14/2022, 12:00 PM