Favorite Product
This functionality allows for personalizing offers for a specific product chosen by the client. It addresses tasks such as:
- targeted personal promotions (discounts on a specific SKU);
- increased cashback / bonuses on a "favorite" product.
Attributes of type sku or product are used to fix the selected product.
The value of such an attribute is an object of the following type:
{
"ref_type": "sku",
"ref_id": "171850"
}
ref_type— reference type (skuorproduct);ref_id— product identifier according to the selected type.
Pre-defined Attributes in the System
A set of attributes ready for use is already established in Sailplay:
favorite_product— favorite product (sku)favorite_product_ecomm— favorite product in e‑commerce (sku)favorite_product_retail— favorite product in retail (sku)
If necessary, an additional attribute can be created following the instructions in the Client Attributes section, necessarily specifying the reference subtype.
Adding an Attribute to a Client
The method /api/v2/users/attributes/set-values-for-user/ is used for adding.
Example of the attributes parameter structure:
[
{
"name": "favorite_product",
"value": {
"ref_type": "sku",
"ref_id": "171850"
}
}
]
Currently, the system supports only one product for one reference attribute (
is_array = false).
Usage Process (End‑to‑End)
1. Preparation
- Ensure that one of the following attributes exists:
favorite_product,favorite_product_ecomm,favorite_product_retail - For a new attribute, set
ref_type(skuorproduct)
2. Product Selection by Client
- On the product card or in the cart, the user clicks "Make favorite" / "Choose for personal discount"
- The frontend determines the SKU or product ID and passes it to the backend
3. Binding Product to Client via API
curl --request POST --url https://api.sailplay.net/api/v2/users/attributes/set-values-for-user/ --header 'Content-Type: application/x-www-form-urlencoded' --data token=*** --data store_department_id=*** --data user_phone=79998880011 --data 'attributes=[{"name":"favorite_product","value":{"ref_type":"sku","ref_id":"171850"}}]'
The request will overwrite the previous value or create a new one if the attribute was previously missing.
4. Promotion Setup in the Dashboard
- Create or edit a promotion
- Reward type: Product Discount → Client Preferences
- Select the corresponding reference attribute
- Configure other promotion parameters (discount size, period, priorities)
If different attributes are used for different channels, create separate promotions.
5. Applying Discount During Purchase
When calculating the cart, the system:
- reads the client's reference attribute value;
- matches
ref_idwith order items; - applies a discount or cashback to matched products.
6. Displaying Selected Product to Client
Retrieve client attribute values:
curl --request GET --url https://api.sailplay.net/api/v2/users/attributes/get-values-by-user/ --header 'Content-Type: application/x-www-form-urlencoded' --data token=*** --data store_department_id=*** --data user_phone=79998880011 --data 'attributes=favorite_product'
Response:
{
"status": "ok",
"result": {
"favorite_product": [
{
"value": {
"ref_type": "sku",
"ref_id": "171850"
}
}
]
}
}
On the frontend, display the product card by ref_id from your catalog.
7. Updating Selection
To change the product, repeat step 3, passing a new ref_id.
Recommendations
- Use a single
ref_typeacross all channels - Validate
ref_idagainst the Sailplay product database - Inform the client of successful binding
- Log attribute assignment operations