The recommendations object
The recommendations
object provides product recommendations that are related to a given product, based on data from sales, product descriptions, and relations between products and collections. Product recommendations become more accurate over time as new orders and product data become available. To learn more about how product recommendations work, see Showing product recommendations on product pages.
The recommendations
object returns products only if it's used in a theme section that's rendered through an HTTP request to <base_url>?section_id=<section_id>&product_id=<product_id>
. section_id
is the ID of the section where the recommendations
object is being used, and product_id
is the ID of the product you want to show recommended products for. To determine the base_url
, use the routes.product_recommendations_url
attribute. Using the routes
object rather than a hardcoded URL ensures that the product recommendations load in the correct locale.
To learn how to implement the recommendations
object, see Showing product recommendations with the Product Recommendations API section response.
The recommendations
object has the following attributes:
recommendations.performed
Anchor link to section titled "recommendations.performed"Returns true
if the recommendations
object is referenced inside a theme section that is rendered through the recommendations endpoint with valid parameters:
Parameters | Description | Required |
---|---|---|
product_id | id of the product you want to show recommended products for | yes |
section_id | id of the section where the recommendations object is being used |
yes |
limit | Limits number of results, up to a maximum of ten | no |
recommendations.products_count
Anchor link to section titled "recommendations.products_count"Returns the number of product recommendations, or returns 0 if recommendations.performed
is false
.
recommendations.products
Anchor link to section titled "recommendations.products"Returns product recommendations. These objects are products. Doesn't return any product if recommendations.performed
is false
.
For example, this Liquid snippet creates the conditions to show product recommendations:
It produces the following output when the enclosing section is rendered synchronously:
And it produces the following output when the enclosing section is rendered from the endpoint /recommendations/products?section_id=<section_id>&product_id=<product_id>
: