JSON API
...
Examples
Batch Updates

Complex products

2min
in the simple products docid 6czvblzoj5qvahkjfmzaf , we saw how to index products let's say you have a complex product like a shirt, available in s and m sizes the following example shows how to index this complex product some other fields are left out for simplicity \[ { "id" "1", "type" "klevu parent product", "attributes" { "name" { "default" "shirt" }, "image" { "default" { "url" "https //4 imimg com/data4/ao/da/my 24693421/black shirt jpg" } }, "url" "https //test myshopify com/products/black shirt", "shortdescription" { "default" "this is a black shirt available in different sizes " } } }, { "id" "2", "type" "klevu product", "relations" { "parentproduct" { "values" \[ "1" ] } }, "attributes" { "name" { "default" "shirt" }, "image" { "default" { "url" "https //4 imimg com/data4/ao/da/my 24693421/black shirt jpg" } }, "price" { "usd" { "defaultprice" 100, "saleprice" 80 }, "gbp" { "defaultprice" 90, "saleprice" 70 } }, "url" "https //test myshopify com/products/black shirt s", "shortdescription" { "default" "black shirt" }, "size" "s" } }, { "id" "3", "type" "klevu product", "relations" { "parentproduct" { "values" \[ "1" ] } }, "attributes" { "name" { "default" "shirt" }, "image" { "default" { "url" "https //4 imimg com/data4/ao/da/my 24693421/black shirt jpg" } }, "price" { "usd" { "defaultprice" 100, "saleprice" 80 }, "gbp" { "defaultprice" 90, "saleprice" 70 } }, "url" "https //test myshopify com/products/black shirt m", "shortdescription" { "default" "black shirt" }, "size" "m" } } ] here we have indexed 3 items, first the parent product, then the two variants of the product a few points to note the parent product needs to be indexed before indexing the variants the “ relations ” field represents the relation of the item with other items in your catalog here we have used the “ parentproduct " relation at the variant level to map them to the parent product “size” is a custom attribute used to provide different values of the variant under prices, observe that the sale price is different for variants, but startprice and toprice are calculated based on all the variants of the complex product and indexed into all variants this helps in rendering the startprice in the product card on the website “ url ” if variants have variant specific urls, then use that for indexing else use the same product url for all variants currently, as you index the parent product, it will also come in the search result all the attributes have to be repeated for all variants start and to prices have to be calculated and sent for each variant due to this, if any variant being deleted causes a change in either of the two values, then all other variants need to be indexed again