Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

SDK

Android - onApp 
Anchor
andoridonapp
andoridonapp

Product recommendations are array of products with product details like brand, price etc. After you receive the product recommendations you need to display recommended products according to your mobile applications’s requirements. This section outlines how to receive recommendations as an array.

...

ZoneID is different for every app so please contact RMC for support. Recommendation widgets like "Alternative Products" require the product code being viewed as a parameter.

The specification of the callback function is:
Code Block
languagejava
linenumberstrue
VisilabsTargetRequest targetRequest = Visilabs.CallAPI().buildTargetRequest(zoneID, "productCode");
targetRequest.executeAsync(callback);

There is also an overload of buildTargetRequest method to which you may pass filters and extra parameters.

Code Block
languagejava
linenumberstrue
List filters = new ArrayList<VisilabsTargetFilter>();
HashMap<String,String> properties = new HashMap<String, String>();
properties.put("OM.extra", "Extra Value");
VisilabsTargetFilter f = new VisilabsTargetFilter();
f.setAttribute("attr1");
f.setFilterType("0"); // There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
f.setValue("value");
filters.add(f);
f = new VisilabsTargetFilter();
f.setAttribute("attr2");
f.setFilterType("1"); // There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
f.setValue("value");
filters.add(f);
VisilabsTargetRequest targetRequest = Visilabs.CallAPI().buildTargetRequest(zoneID, "productCode", properties, filters);
targetRequest.executeAsync(callback);
After the request is completed, depending on the status of the request either success or failure callback function will be called, therefore based on your requirements, you need to code your callback functions as shown below:
Code Block
languagejava
linenumberstrue
VisilabsTargetCallback callback = new VisilabsTargetCallback() {
@Override
public void success(VisilabsResponse response) {
try{
JSONArray array = response.getArray();
if(array != null) {
ArrayList<Product> recommendations = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
JSONObject obj = (JSONObject)array.get(i);
Product product = new Product();
product.setProductCode(obj.getString("code"));
product.setProductName(obj.getString("title"));
product.setMediumImageUrl(obj.getString("img"));
product.setProductURL(obj.getString("dest_url"));
product.setBrand(obj.getString("brand"));
product.setOriginalPrice(obj.getDouble("price"));
product.setDiscountedPrice(obj.getDouble("dprice"));
product.setCurrency(obj.getString("cur"));
product.setDiscountCurrency(obj.getString("dcur"));
product.setFreeShipping(obj.getBoolean("freeshipping")); 
product.setShippingOnSameDay
(obj.getBoolean("samedayshipping"));
product.setRating(obj.getInt("rating"));
product.setComment(obj.getInt("comment"));
product.setDiscountRate(obj.getDouble("discount")); 
product.setAttr1(obj.getString("attr1"));
product.setAttr2(obj.getString("attr2"));
product.setAttr3(obj.getString("attr3"));
product.setAttr4(obj.getString("attr4"));
product.setAttr5(obj.getString("attr5"));
recommendations.add(product);
} 
}
}catch (Exception ex){
showToast(ex.getMessage());
Log.e(LOG_TAG, ex.getMessage(), ex);
}
}
@Override
public void fail(VisilabsResponse response) {
showToast(response.getErrorMessage());
Log.d(LOG_TAG, rawResponse);
}
};

...


...

iOS - onApp 
Anchor
iosonapp
iosonapp

Product recommendations are array of products with product details like brand, price etc. After you receive the product recommendations you need to display recommended products according to your mobile applications’s requirements. This section outlines how to receive recommendations as an array.

Create a VisilabsTargetRequest object:
Code Block
languageapplescript
titleObjective-C
VisilabsTargetRequest *request=[[Visilabs callAPI] buildTargetRequest: @"ZoneID" withProductCode: @"ProductCode"];
Code Block
languageapplescript
titleSwift
let targetRequest = Visilabs.callAPI().buildTargetRequest("ZoneID", withProductCode: "ProductCode")

There is also an overload of buildTargetRequest method to which you may pass filters and extra parameters.


Code Block
languageapplescript
titleObjective-C
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
NSMutableArray *filters = [[NSMutableArray alloc] init];
[dic setObject:@"Extra Value" forKey:@"OM.extra"];
VisilabsTargetFilter *filter1 = [[VisilabsTargetFilter alloc] init];
filter1.attribute = @"attr1";
filter1.value =  @"val";
filter1.filterType =  @"1"; // There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
[filters addObject:filter1];
VisilabsTargetFilter *filter2 = [[VisilabsTargetFilter alloc] init];
filter2.attribute = @"attr2";
filter2.value =  @"val";
filter2.filterType =  @"0"; // There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
[filters addObject:filter2];


VisilabsTargetRequest *request=[[Visilabs callAPI] buildTargetRequest: @"ZoneID" withProductCode: @"ProductCode"  withProperties:dic withFilters:filters];
Code Block
languageapplescript
titleSwift
let zoneID = "9"
let dic = NSMutableDictionary()
dic["OM.extra"] = "Extra Value";
let filters = NSMutableArray()
let filter1 = VisilabsTargetFilter()
filter1.attribute = "attr1"
filter1.filterType = "1"// There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
filter1.value = "val"
filters.add(filter1)
let filter2 = VisilabsTargetFilter()
filter2.attribute = "attr2"
filter2.filterType = "0"// There are 2 filter types: Include and Exclude. For Include pass "0", for Exclude pass "1".
filter2.value = "val"
filters.add(filter2)
let targetRequest = Visilabs.callAPI().buildTargetRequest("ZoneID", withProductCode: "ProductCode", withProperties:dic, with:filters)



After the request is completed, depending on the status of the request either success or failure callback function will be called, therefore based on your requirements, you need to code your callback functions as shown below:
Code Block
languageapplescript
titleObjective-C
void (^ successBlock)(VisilabsResponse *) = ^(VisilabsResponse * response) { NSLog(@"Response: %@", response.rawResponseAsString); NSArray *parsedArray = [response responseArray]; if(parsedArray){ for (NSObject * object in parsedArray) { if([object isKindOfClass:[NSDictionary class]]){ NSDictionary *product = (NSDictionary*)object; NSString *title = [product objectForKey:@"title"]; NSString *img = [product objectForKey:@"img"]; NSString *code = [product objectForKey:@"code"]; NSString *destURL = [product objectForKey:@"dest_url"]; NSString *brand = [product objectForKey:@"brand"]; double price = [[product objectForKey:@"price"] doubleValue]; double discountedPrice = [[product objectForKey:@"dprice"] doubleValue]; NSString *currency = [product objectForKey:@"cur"]; NSString *discountCurrency = [product objectForKey:@"dcur"]; int rating = [[product objectForKey:@"rating"] intValue]; int comment = [[product objectForKey:@"comment"] intValue]; double discount = [[product objectForKey:@"discount"] doubleValue]; BOOL freeShipping = [[product objectForKey:@"freeshipping"] boolValue]; BOOL sameDayShipping = [[product objectForKey:@"samedayshipping"] boolValue]; NSString *attr1 = [product objectForKey:@"attr1"]; NSString *attr2 = [product objectForKey:@"attr2"]; NSString *attr3 = [product objectForKey:@"attr3"]; NSString *attr4 = [product objectForKey:@"attr4"]; NSString *attr5 = [product objectForKey:@"attr5"]; } } } }; void (^ failBlock)(VisilabsResponse *) =^(VisilabsResponse * response){ NSLog(@"Failed to call. Response = %@", [actFailRes.error description]); };
Code Block
languageapplescript
titleSwift
let successBlock:(VisilabsResponse!) -> Void = {response in print("Response:\(response.rawResponseAsString)") for object:AnyObject in response.responseArray{ if(object.isKindOfClass(NSDictionary)){ let productObject = object as! NSDictionary; let title = productObject.objectForKey("title") as! String let img = productObject.objectForKey("img") as! String let code = productObject.objectForKey("code") as! String let dest_url = productObject.objectForKey("dest_url") as! String let brand = productObject.objectForKey("brand") as! String let price = productObject.objectForKey("price") as! Double let discountedPrice = productObject.objectForKey("dprice") as! Double let currency = productObject.objectForKey("cur") as! String let discountCurrency = productObject.objectForKey("dcur") as! String let rating = productObject.objectForKey("rating") as! Int let comment = productObject.objectForKey("comment") as! Int let discount = productObject.objectForKey("discount") as! Double let freeShipping =productObject.objectForKey("freeshipping") as! Bool let sameDayShipping=productObject.objectForKey("samedayshipping") as! Bool let attr1 = productObject.objectForKey("attr1") as! String let attr2 = productObject.objectForKey("attr2") as! String let attr3 = productObject.objectForKey("attr3") as! String let attr4 = productObject.objectForKey("attr4") as! String let attr5 = productObject.objectForKey("attr5") as! String } } } let failBlock: (VisilabsResponse!) -> Void = {response in VisilabsHelper.targetLog(response.targetURL) print("Visilabs target call failed.Error=\(response.rawResponseAsString)") }




Parent Topic: Getting Data