netsuitesuitescriptsuitecommerce

Detecting a category page in the isCategoryPage method


I currently have an SCA website that has sub categories that need to display as a category page, and not a Product listing page. (i.e. display the categories, not the products).

Currently, I have modified the isCategoryPage to override the Facets.Views.isCategoryPage such that it does this correctly. However, when doing a search on the site - it breaks that page with a blank page.

I am currently stuck at figuring out how to detect if I am on a search page rather than a category page.

The code is thus:

...
        // @Overrides Facets.Views.isCategoryPage
        isCategoryPage: function isCategoryPage(translator) {
            var currentFacets = translator.getAllFacets();
            var categories = translator.getCategoryPath();

            if (<--IsSearchPage() === true --->) {
                return (_.keys(categories[categories.length-1].categories).length !== 0);
            } else {
                return (currentFacets.length === 1 &&
                    currentFacets[0].id === 'category' &&
                   categories &&
                    CategoryHelper.showCategoryPage(categories)
                );
            }
        },
...

As you can see the if statement is where I need a bit of help.

if (<--IsSearchPage() === true --->) {

What method, function, code would detect if the page is a search page. Or if the page url has /search in the url. (either would work).

Thank you.


Solution

  • The proper update, after much trial and error:

    isCategoryPage: function isCategoryPage(translator) {
        var currentFacets = translator.getAllFacets();
        var categories = translator.getCategoryPath();
    
        if (categories) {
            return (_.keys(categories[categories.length-1].categories).length !== 0);
        } else {
            return (currentFacets.length === 1 &&
                currentFacets[0].id === 'category' &&
               categories &&
                CategoryHelper.showCategoryPage(categories)
            );
        }
    },