I have an entry point file for a custom PDP extens...
# suitecommerce
k
I have an entry point file for a custom PDP extension. IF the PDP component exists I am using the the Layout component addToViewContextDefinition method on ProductViews.Price.View. Which is working great. If I navigate using the back button (chrome) the contextDefinition values render on the PLP. Granted ProductViews.Price.View exists on both the PDP and PLP. I thought the resolution would be to leverage the Layout component removeToViewContextDefinition method on “afterShowContent”. Which also works well. My issue now is that if any child view on the PDP is interacted with, such as incrementing the quantity, the contextDefinition values disappear. Any thoughts?
s
If you're using a child view shared across many parent views but you want for it to only show on a particular parent view you can do what I call contextual rendering. This is where you trigger a child view's
render()
method only if the user is on a particular parent view. I talk about it here: https://developers.suitecommerce.com/use-helper-files-services-and-contextual-rendering-in-your-extension#title4 (scroll up for the code snippet).
Remember, things like
addChildView()
and
removeChildView()
and adding/removing to/from a context object is done a class basis, rather than an instance basis. If you use them, but want them to run on a case-by-case basis, then you need to add code that affects what happens when they are constructed.
👍 1
k
@Steve Goldberg, that is a good way of looking at it. Thanks for the tip and for the blog article too.