Versions Compared

Key

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

Method Objective

The method returns an API response when requesting product recommendations.

Note

Please note that the priority way of placing the product recommendations blocks on the site is to insert the DIV tag created in the PersonaClick account and fill it automatically with the PersonaClick library. The instruction below is intended for exceptional cases when an automatic drawing of the block doesn't give the maximum necessary functionality.

Syntax and parameters

Code Block
languagejava
themeFadeToGrey
personaclick("recommend", PersonaClick.recommend(code, params, success, errorcallback);


NameTypeRequirementDescription
codestringrequiredUnique code of the recommendation block. See this value in the "data-recommender-code" attribute of the block created in PersonaClick account.
paramsobjectenumrequiredObject with request Request parameters.
successcallbackfunctionrequiredA callback function, to which the API response will be passed. Response type: object.errorfunctionoptionallyA callback function that will be called when an error occurs (any HTTP status code other than 200).

Request parameters

number/
NameTypeRequirementDescription
itemITEMnumber/stringrequired in some casesProduct ID. This  This parameter is mandatory for the requests of blocks with algorithms that use the algorithms "Similar" and "Also bought".
excludearrayoptionallyProduct IDs array, which should be excluded from the recommended products list.
categorydepend on the current product. Algorithms: "Similar", "Products usually purchased with this product", "Store recommendations", etc.
CATEGORY_IDstringrequired in some casesCategory ID. This parameter is mandatory for all blocks set on category pages.
searchSEARCH_queryQUERYstringrequired in some casesThe text of the search query. This parameter is mandatory for the requests of blocks that use the "Search" algorithm.
limitLIMITnumberstringoptionallyA maximum number of products in the API response.
locationsLOCATIONSarraystringoptionallyArray String with location IDs separated by comma. If used, the API response will return products available in the listed locations.
brandsBRANDSarraystringoptionallyArray String with brand names separated by comma. If  If used, only the products of the listed brands will be returned in the API response.
exclude

EXCLUDE_

brands

BRANDS

arraystringoptionallyArray String with brand names separated by comma. If  If used, the API response will exclude the products of the listed brands.
categoriesCATEGORIESarraystringoptionallyArray String with category IDs separated by comma. If  If used, the API response will only return products that are included in the listed categories.
discountDISCOUNTbooleanoptionallyIf used with "true" value, then only those products, the value of which is less than the "oldprice" value, will be returned in the API response.
EXTENDEDbooleanoptionallyAllows getting extended information about products for self-rendering of the recommended products widget. See the "recommends" property of the API response. Default: false

API response properties

NameTypeDescription
htmlstringHTML-code of the block with products. The template is customized in the PersonaClick account.
titlestringThe block title. Corresponds to the value of the "Action" element in the block rules.
productsrecommendsarray/Object Array

Depending on the value of the "EXTENDED" parameter in the API request, it returns either an Array or an Object Array.

The Array contains only product IDs.

The Object Array contains objects with the following properties:

  • barcode – product barcode, if it was imported in the product catalog (type: string)
  • brand – product vendor (type: string)
  • categories – an Object array with details of the product category hierarchy, where each object has properties:
    "id" – category ID (type: string)
    "level" – сategory level in the hierarchy (type: string)
    "name" – category name (type: string)
    "name_with_parent" – string name from the name of the parent and main product categories, separated by a "-" (type: string)
    "parent_id" – parent category ID (type: string)
    "url" – category page url (type: string)
  • category_ids – an array of IDs of the product category hierarchy (type: String array)
  • currency – product currency (type: string, matches the currency of the PersonaClick account, or the user value set in the settings of the PersonaClick account)
  • discount – the percentage difference between the old price and the current price (type: number)
  • discount_formatted – the percentage difference between the old and the current price that is formatted as a string with the "%" symbol (type: string)
  • discount_percent – user-defined discount value (type: number)
  • gift – specifies whether the product is a gift (type: boolean)
  • group_id – product group ID (type: string)
  • installment – the payment cost if purchasing the product in installments (type: number)
  • id – product ID (type: string)
  • image_url – URL of the original product image (type: string)
  • image_url_handle – relative URL of the original product image (type: string)
  • image_url_resized – the object with the URLs of the resize product image. Available object keys matching the size of the image in pixels: 120, 140, 160, 180, 200, 220, 310, 520 (type: object)
  • is_new – new arrival product (type: boolean). See the parameter in the product catalog import (XML, HTTP API)
  • leftovers – rough number of the products left in stock. Available values are: 
    "one" - one product
    "few" - 2-10 products
    "lot" - over 10 products
  • model –  model and product name (type: string)
  • name – product name (type: string)
  • oldprice – integer old price of the product (type: number)
  • oldprice_formatted – formatted integer old price of the product, including currency (type: string)
  • oldprice_full – old price of the product (type: number)
  • oldprice_full_formatted – formatted old price of the product, including currency (type: string)
  • params – object array with pairs of "key" (type: string), "values" (type: array) properties. The data matches the values of the "param" parameter of the product feed/catalog (XML, HTTP API).
  • picture – link to the product image in the PersonaClick image repository (type: string)
  • price – integer current price of the product (type: number)
  • price_formatted – formatted integer current price of the product, including currency (type: string)
  • price_full – current price of the product (type: number)
  • price_full_formatted – formatted current price of the product, including currency (type: string)
  • price_with_promocode – the product price when using the promo code specified for the product (type: number)
  • price_with_promocode_formatted – formatted product price when using the promo code specified for the product, including currency (type: string)
  • promocode – the promo code is for a specific product (type: string)
  • rating – product rating (type: number)
  • relative_sales_rate – level of sales of current product ( in percentage) in relation to the maximum level of sales of products in the store (type: number)
  • sales_rate – level of product sales (absolute value) (type: number)
  • url – product page URL (type: string)
  • url_handle - relative product page URL (type: string)
idnumberUnique block identifier. Corresponds to the block ID in the list of blocks in the PersonaClick account.

Examples of use

For blocks with algorithms that require the "Product ID":

Code Block
languagejsjava
themeFadeToGrey
personaclick("recommend", Params recommender_params = new Params();
recommender_params.put(Params.Parameter.ITEM, "100500");
PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", {item: 100500}, function(recommender_params, new Api.OnApiCallbackListener() {
    @Override
    public void onSuccess(JSONObject response) {
        // the functionality of rendering a block of product recommendations
}, function(error)
{   // when something went wrong
}
});


For blocks with algorithms that require the "Category ID":

Code Block
languagejsjava
themeFadeToGrey
personaclick("recommend", "1fd1b3495137bc3c9299816026acf36f", {category: 146}, function(response) {
  Params recommender_params = new Params();
recommender_params.put(Params.Parameter.CATEGORY_ID, "146");
PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", recommender_params, new Api.OnApiCallbackListener() {
    @Override
    public void onSuccess(JSONObject response) {
        // the functionality of rendering a block of product recommendations
}, function(error) {   // when something went wrong}
});


For blocks with an algorithm that requires the "Search Query":

Code Block
languagejsjava
themeFadeToGrey
personaclick("recommend", "1fd1b3495137bc3c9299816026acf36f", {search_query:Params recommender_params = new Params();
recommender_params.put(Params.Parameter.SEARCH_QUERY, "To be or not to be"}, function();
PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", recommender_params, new Api.OnApiCallbackListener() {
    @Override
    public void onSuccess(JSONObject response) {
        // the functionality of rendering a block of product recommendations
}, function(error) {   // when something went wrong
}
});

Full example:

Code Block
languagejsjava
themeFadeToGrey
personaclick("recommend", "1fd1b3495137bc3c9299816026acf36f", {item: 100500, exclude: [3, 14, 159, 26535], category: 146, search_query:Params recommender_params = new Params();
recommender_params.put(Params.Parameter.ITEM, "100500");
recommender_params.put(Params.Parameter.SEARCH_QUERY, "To be or not to be", limit: 15, brands: ["Alas", "poor", "Yorick"], categories: [1, 146, 100500]}, function();
recommender_params.put(Params.Parameter.CATEGORY_ID, "146");
recommender_params.put(Params.Parameter.LIMIT, "15");
recommender_params.put(Params.Parameter.BRANDS, "Alas,poor,Yorick");
recommender_params.put(Params.Parameter.CATEGORIES, "1,146,100500");
recommender_params.put(Params.Parameter.EXTENDED, true);
PersonaClick.recommend("1fd1b3495137bc3c9299816026acf36f", recommender_params, new Api.OnApiCallbackListener() {
    @Override
    public void onSuccess(JSONObject response) {
        // the functionality of rendering a block of product recommendations
}, function(error) {   // when something went wrong}
});



Column

Page Navigation

Table of Contents

classpersonaclick-fixed-position

maxLevel3
indent0px
stylenone




Related Pages

Filter by label (Content by label)
showLabelsfalse
showSpacefalse
sorttitle
cqllabel = "recommenders"