Hey everyone, We have a customization to prevent c...
# suitecommerce
m
Hey everyone, We have a customization to prevent categories from showing up in the Nav bar of an SCA site, but we still want those categories active and displayed, just not on the Nav bar. The customization was originally on an Elbrus site and we are trying to make it work on a 22.2 site. I searched for bundles because this seems like it would be a pretty common need, but i am not seeing anything. Anyone know of a bundle for this? Thank you!
s
This is not in a bundle no. Just so I’m clear, you want to use categories to organise your products but then not display them in the navigation? Why? (And are these commerce categories or the older site categories?)
m
these are commerce categories. we want the category’s items on the site, but we don’t want it added to the menu. For example, an email blast might link to mysite.com/specialemailproducts but they don’t want the category displayed in the nav bar, if that makes sense
the older customization was basically running a saved search in a SS file that looked for a custom field on a category and then manipulating the way categories were returned, so that any cat where that field was true, weren’t returned.
maybe another way to say it is, they want to make commerce categories that are active and on the site, don’t get automatically added to the Navigation bar
s
Hmm, then no. We don't have something like that
I think it would be pretty straightforward to target them with CSS or JS, so if you know how to write those you can the code to an HTML block in the SMTs
Eg if I wanted to hide a link to my category that links to /orange-things then I could write CSS like this:
Copy code
a.header-menu-level1-anchor[data-hashtag="#/orange-things"] {
    display: none;
}
m
Well they have over 100 commerce categories to hide this way so I'm not sure targeting that way in the SMTs is the way to go. They'd been relying on a checkbox on the commerce category record.
I don't have much experience with TS and have had difficulty getting an extension of the commons/categories module in the 22.2 core to work like I would extensions in versions before TS. It looks like a lot of what had previously been in the SuiteScript model (at least in the customization) is now handled in the Categories.ts, Categories Collection ts, and Categories Util ts. I have an idea how to do this without the saved search found in the current customization.
s
Well, it is possible to fetch custom commerce category fields, so you can get your hide/show flag for each one
Then it may just be a case of heading over to the header menu view and template and just adding in a check to see if the flag is checked/unchecked before rendering it in the template
Or perhaps even ‘post-processing’ the categories object, removing any that has the flag
Or you could even do that using a beforeShowContent event
m
Thank you, this gives me some other ideas than modifying the current/previous customization. As an aside, having worked only with pre-ts versions of SCA, are extensions still done largely the same on, say, 22.2? Glancing at the docs for something like "write your first custom extension" (probably not the exact title) it seems like the process is still the same and the docs note a few places where something is different. But I was unable to extend objects from the commons/categories module in a new extension like I've done in the past. And probably a dumb question but can we write TS now in an extension?
s
You shouldn’t have a problem calling or extending modules in the core application. Extensions sit on top of the core application, after TS has been converted into JS
What you can’t call are core modules that are written in SuiteScript 2.x
m
ok, thanks, hmmm, because I can’t get my JS to work writing an extension like I have for years, where I extend the JS, overwrite the html/sass, etc. The only place I am having that issue is with 22.2 modules in TS.
@Steve Goldberg when you say fetch custom commerce category fields, do you mean totally on the client side using what is already available or writing new SuiteScript code? Thanks
s
Normally one would write some SS so that when categories are called, the response is modified so that the custom fields are included
For example, when someone asked how to get the custom fields for a single commerce category (eg for showing on the PLP for it) then the following code works:
Copy code
Application.on('after:Category.get', function (CategoryModel, category) {
    var lookupResults = nlapiLookupField('commercecategory', category.internalid, [
        'yourcustomfield'
    ]);
    category.customfield = lookupResults.yourcustomfield
});
m
ok, yeah, that is similar to what the customization we’re working on doing, except it’s building a larger saved search. It fetches the field on the category and in a SuiteScript model basically does all the filtering.
the customized SS model extends an existing SS model that is no longer in the SCA 22.2 core code to extend. That is what started the problems we are getting for this customization to work in 22.2
s
Yeah something like the above would require it to be amongst the core code
m
so i’ve always extended core code. I have never modified the core as I know it’s not best practices, but I also know it can be done. I am beginning to think for this customization to work in 22.2 that might be the approach? Is that what you mean by “amongst the core code”? And the reason I say that is because it doesnt appear to me that the SuiteScript model we’d been using exists now in 22.2.
s
Yes, I mean extending the core code. I basically stopped tinkering with the core code a couple of years ago because I changed roles, and so I’m not really in a position to advise you on the pitfalls or best practices. However, I think you should be able to write in relatively vanilla JS and have it plug into the TS application, because valid JS is valid TS. So all that might be tricky is the wrapping around it
m
_.extend( CategoriesModel.prototype
is something I would have done, but if that Model is now set in TS, that isn’t working. I think I could copy and paste a lot of what the customization I am working on is doing, but I can’t get TS to extend.