SC Category Page Widget catalogItemJS.getItemSummary()

Steven Watts2
Tera Guru

Hi,

 

I'm trying to display additional catalogue item attributes in the SC Category Page widget. For example I might want to display the Delivery Time next to the Price.

HTML:

 

 

<span> ${Delivery Time}: {{::item.deliveryTime}}</span>

 

 

 Server Script:

 

 

function fetchItemDetails(itemRecord, items) {
		while (itemRecord.next()) {
				var catalogItemJS = new sn_sc.CatItem(itemRecord.getUniqueValue());
				if (!catalogItemJS.canView())
					continue;

				var catItemDetails = catalogItemJS.getItemSummary();
				var 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 = catItemDetails.show_price;
				item.page = 'sc_cat_item';
				item.type = catItemDetails.type;
				item.order = catItemDetails.order;
				item.sys_class_name = catItemDetails.sys_class_name;
				item.titleTag = catItemDetails.name;
				item.delivery_time = catItemDetails.delivery_time;

 

 

I have come across getItemSummary() that I don't seem to be able to find any documentation for. The function doesn't allow me to fetch any attributes outside of those which are already being returned. Has anyone come across the same issue and been able to fetch additional attributes via this function? Ideally I don't want to be running another query to fetch the catalogue item and then return the fields needed.

 

StevenWatts2_0-1697729957143.png

 

I've confirmed the HTML call work, it's currently just being used for testing, by calling item.price which displays the price next to Delivery Time:.

 

Steven

4 REPLIES 4

RaghavSh
Kilo Patron

I dont think you will be able to get this directly.

Try below Workaround:

1. Glide the sc_cat_item with and fetch catalog item. sys_id is already there in var catalogItemJS

2. store that in item.delivery and do item.push()

 


Raghav
MVP 2023

Hi @RaghavSh 

Thanks, will give this a go.

 

Steven

Let me know if this does not work


Raghav
MVP 2023

Community Alums
Not applicable

Hi @Steven Watts2 ,

 

This question is quite old, but I'm sharing a solution here to help future readers who might face the same issue.

We can use below code to achieve this,

 

var catItem = new sn_sc.CatItem("97a99c7483002210357c71a6feaad3a8"); //pass the sysId of the catalog item
var values = catItem.read({"table_name" : "", "price" : ""}, false); //pass the backend names of the variable which you are looking for
gs.info("Catalog item name: " + values.table_name);
gs.info("Catalog item price: " + values.price);

 

 

Mark this as Helpful / Accept the Solution if this helps.