How to hide catalog items in popular items?

Giriprasath
Tera Contributor

hide all catalog items in popular list

and specifically hide some catalog item in popular list 

 

1 ACCEPTED SOLUTION

@Giriprasath 

 

Unfortunately, that link's solution is no more relevant for current version

 

Follow the below steps in sequence:

 

1. Create a properties with name exclude_from_popular_list and put the sys_id(s) of the catalog items that you want to exclude from the portal (comma separated)

 

kamleshkjmar_4-1667472545264.png

 

 

2. Open service portal and category page where you see popular items. Now press ctrl + right click on Popular Items and click on Widget in Editor option.

kamleshkjmar_0-1667474299529.png

Create a clone of SC category page widget,  as shown below:

 

kamleshkjmar_0-1667469166488.png

kamleshkjmar_1-1667469261003.png

 

3. Now open your Cutom Category Page which you just now created

kamleshkjmar_2-1667469336796.png

 

4.  Go to function name getPopularItems() and replace it with below script and save the widget:

 

 

 

 

function getPopularItems() {
		var itemsToExclude = gs.getProperty("exclude_from_popular_list");
        return new SCPopularItems().useOptimisedQuery(gs.getProperty('glide.sc.portal.popular_items.optimize', true) + '' == 'true')
            .baseQuery(options.popular_items_created + '')
            .allowedItems(getAllowedCatalogItems())
            .visibleStandalone(true)
            .visibleServicePortal(true)
            .itemsLimit(6)
            .restrictedItemTypes('sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content,sc_cat_item_producer'.split(','))
            .itemValidator(function(item, itemDetails) {
					if(itemsToExclude.indexOf(itemDetails.sys_id)>-1)
						return false;
					
                if (!item.canView() || !item.isVisibleServicePortal())
                    return false;

                return true;
            })
            .responseObjectFormatter(function(item, itemType, itemCount) {
                return {
                    order: 0 - itemCount,
                    name: item.name,
                    short_description: item.short_description,
                    picture: item.picture,
                    price: item.price,
                    sys_id: item.sys_id,
                    hasPrice: item.price != 0,
                    page: itemType == 'sc_cat_item_guide' ? 'sc_cat_item_guide' : 'sc_cat_item'
                };
            })
            .generate();
    }

 

 

 

 

 

kamleshkjmar_1-1667474372500.png

 

 

5. Now go to the SC Category page in designer and drag and drop the Custom Category Page widget over SC Category page widget as shown below. As of now we are not deleting the OOB SC Category Page widget purposefully, for comparing the result:

kamleshkjmar_2-1667474466784.png

 

 

6. Now go to the Portal and see items that you excluded is no more showing in popular items list. You can compare from the pre existing widget, we have kept it one below another to compare.

 

kamleshkjmar_5-1667472978733.png

 

 

7.Once you are staisfied with the result, delete the previous SC Category page widget. And you are done with your requirement.

kamleshkjmar_0-1667474774390.png

 

 

As and when you want to allow any already removed item or add furhter item to remove from Popular items list just make change in the properties and it will reflect on the portal.

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

View solution in original post

9 REPLIES 9

Yeah I'll check it

 

@kamlesh kjmar 

Giriprasath_0-1667548372916.png

Where I need to change the code to hide apple iphone 13 pro

and what is the code to be changed?

@Giriprasath  In my previos post it is already mentioned what to change and how to reach there along with the screenshots.

 

If you have to hide apple iphone 13 pro, you have to store the sys_id of the item in the property created in step 1

 

Regards,

Kamlesh

@kamlesh kjmar 

How can I contact you bro?

 

@Giriprasath 

 

You can DM on chat

 

Regards,

Kamlesh