Replacing Popular Item in portal to list of categories

sunny27
Tera Contributor

Hi All, 

 

We have a requirement where we need to replace the Popular item in portal view to list of categories. I have cloned the page "SC Category Page" and commented related to popular item scripts under server. And trying to replace the table 

'sc_item_produced_record' with 'sc_category', so far I'm getting the result as "No items in category". Could you please help me with displaying the categories here? Let me know if I have paste whole script here.
 
Portal view.png

Server script updated one :
function getPopularItems() {
            //var limit = 9;
            var items = [];
            var allowedItems = getAllowedCatalogItems();

        //  var createdQuery = '';
        //   if (options.popular_items_created == 3)
        //      createdQuery = 'sys_created_onONLast 3 months@javascript:gs.beginningOfLast3Months()@javascript:gs.endOfLast3Months()^';
        //  else if (options.popular_items_created == 6)
        //      createdQuery = 'sys_created_onONLast 6 months@javascript:gs.beginningOfLast6Months()@javascript:gs.endOfLast6Months()^';
        //  else if (options.popular_items_created == 12)
        //      createdQuery = 'sys_created_onONLast 12 months@javascript:gs.beginningOfLast12Months()@javascript:gs.endOfLast12Months()^';

            var count = new GlideAggregate('sc_req_item');
            count.addAggregate('COUNT','cat_item');
            count.groupBy('cat_item.sys_id');
            count.addQuery('cat_item.sys_class_name', 'NOT IN', 'sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content,sc_cat_item_producer');
            count.addQuery('cat_item', "IN", allowedItems);
            count.addQuery('cat_item.visible_standalone','true');
            //count.addEncodedQuery(createdQuery + 'cat_item.hide_sp=false^ORcat_item.hide_spISEMPTY');
            count.orderByAggregate('COUNT', 'cat_item');
            count.query();
            while (count.next()) {
                var catalogItemJS = new sn_sc.CatItem(count.getValue("cat_item.sys_id"));
                    if (!catalogItemJS.canView() || !catalogItemJS.isVisibleServicePortal())
                        continue;
                var item = {};
                var catItemDetails = catalogItemJS.getItemSummary();

                item.order = 0 - count.getAggregate('COUNT', 'cat_item');
                item.name = catItemDetails.name;
                item.short_description = catItemDetails.short_description;
                item.picture = catItemDetails.picture;
                item.price = catItemDetails.price;
                item.sys_id = catItemDetails.sys_id;
                item.hasPrice = item.price != 0;
                item.page = 'sc_cat_item';
                items.push(item);
            }
            var categorys = 0;
            count = new GlideAggregate('sc_category');
            //count.addQuery('producer', "IN", allowedItems);
            count.addActiveQuery();
            //count.addEncodedQuery(createdQuery + 'producer.hide_sp=false^ORproducer.hide_spISEMPTY');

            count.addAggregate('COUNT','sc_category');
            count.groupBy('sc_category.sys_id');
            //count.addQuery('cat_item.sys_class_name', 'NOT IN', 'sc_cat_item_guide,sc_cat_item_wizard,sc_cat_item_content,sc_cat_item_producer');
            //count.addQuery('sc_category', "IN", allowedItems);
            //count.addQuery('sc_category.visible_standalone','true');
            //count.addEncodedQuery(createdQuery + 'cat_item.hide_sp=false^ORcat_item.hide_spISEMPTY');
            count.orderByAggregate('COUNT', 'sc_category');
            count.query();
            while (count.next()) {
                gs.info('SKGH entering1');  
                    var catogyItemJS = new sn_sc.CatCategory(count.getValue('sc_catalog.sys_id'));
                    gs.info('SKGH entering2' +catogyItemJS);
                    if (!catogyItemJS.canView() || !catogyItemJS.isVisibleServicePortal())
                        continue;
                    var catItemDetails = catogyItemJS.getItemSummary();
                    var item = {};
                    item.order = 0 - count.getAggregate('COUNT', 'sc_catalog');
                    item.name = catItemDetails.name;
                    item.short_description = catItemDetails.short_description;
                    item.picture = catItemDetails.picture;
                    item.price = catItemDetails.price;
                 // item.hasPrice = item.price != 0;
                    item.sys_id = catItemDetails.sys_id;
                    item.page = 'help_sc_category';
                    items.push(item);
                    //categorys++;
            }
            return items;
    }

    function getAllowedCatalogItems () {
        var allowedItems = [];
        catalogIDArr.forEach(function(catalogID) {
            var catalogObj = new sn_sc.Catalog(catalogID);
            var catItemIds = catalogObj.getCatalogItemIds();
            for(var i=0; i<catItemIds.length; i++) {
                if (!allowedItems.includes(catItemIds[i]))
                     allowedItems.push(catItemIds[i]);
            }
        });
        return allowedItems;
    }

})();

 
 
0 REPLIES 0