getItemsForCatalogGroup - Checkout API Method
Method Signature |
|
Description |
Queries the catalog for a given url, locates the mapped Catalog Group (if any), and returns back all items assigned to that Catalog Group. This method is mostly used to display a list of products available to a particular page (url). |
Parameters |
|
Result |
|
Since: Version 2.0.1, June 2011
Examples:
There is an html page attached to this page that is a stand alone working example. You'll need the download the required js libraries (jQuery, jquery-json, etc), as well as ensuring your relay script is installed if you wish to run this from your own webserver.
Below is the javascript that makes the remote call:
// normally, you would NOT put the entire initialization of the cart within an 'onclick' method. But, in order
// to illustrate the bare bones, yet complete, code needed to make this remote call, it's all going here together.
function fetch(){
var someMerchant = jQuery('#merchantId').val();
var url = jQuery('#url').val();
var merchantCartConfig =
{
merchantId: someMerchant,
isCheckoutPage: false, // speeds up things. only set to true if you're displaying all the checkout fields (shipping, credit cards, etc.)
checkoutSite: 'secure.ultracart.com', // not needed for a non-checkout page, but good practice to supply.
remoteApiUrl: 'http://www.mystore.com/proxy.php', // this is important. If you don't know what to put here, search docs.ultracart.com for 'Relay Script'
debugMode: true,
verboseAjax: true
};
ultraCart.init(merchantCartConfig);
var itemsResult = ultraCart.getItemsForCatalogGroup(url);
var errDiv = jQuery('#errorString');
var compareLinkDiv = jQuery('#compareLink');
var itemsDiv = jQuery('#items');
if(!itemsResult){
errDiv.html('ItemResult.error: the result for the remote call was null. this is bad. check your browser console for more information.');
return;
}
errDiv.html('ItemResult.error: ' + itemsResult.error);
if(itemsResult.items){
var html = '<pre>ITEMS\n';
for(var i = 0; i < itemsResult.items.length; i++){
html += "ITEM " + i + "\n";
var item = itemsResult.items[i];
for (var prop in item) {
if (item.hasOwnProperty(prop)) {
html += prop + ":" + jQuery.toJSON(item[prop]) + "\n";
}
}
html += "<hr />\n\n";
}
html += '<\/pre>';
itemsDiv.html(html);
compareLinkDiv.html("Compare the results! → <a href='" + url + "'>" + url + "</a><br />");
}
}