Product Hydration
Introduction
Product hydration - is a process of updating information about products on the runtime.
Firework SDK requests product hydration when a video associated with the products starts playing.
To implement product hydration, the host app should override OnProductActionListener.onProductHydration() callback.
This callback has following parameters:
products- list of products for which hydration is requested.hydrator- a builder that the host app should use to modify fields of a specific product.videoInfo- information about the video which requested the hydration.
❗After hydration is completed the host app should notify the SDK by calling hydrator.completeHydration().
Without this, updated values will not be applied to Firework SDK.
Please refer to the sample app to see a complete example of the product hydration.
A simple example of product hydration may look like this:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
...
FireworkSdk.shopping.setOnProductHydrationListener { products, hydrator, videoInfo ->
val firstProduct = products.first()
// Hydrate the first product in the list
hydrator.hydrate(firstProduct.id) {
name("Modified product name")
description("Modified product description.")
isAvailable(false)
}
// Tell the SDK that to apply hydration to the products
hydrator.completeHydration()
}
}
}
override fun onDestroy() {
// Remove OnCartActionListener from the SDK
FireworkSdk.shopping.setOnProductHydrationListener(null)
super.onDestroy()
}
}Remove a variant
Removes a specified variant from the product based on its unique identifier.
This method efficiently filters out the variant with the given ID from the product's list of variants. If the variant to be removed includes an associated image, this method also ensures that the image is removed from the product's images lists. This is crucial for maintaining data integrity and ensuring that all product representations are up-to-date and accurate.
Add a new variant
Adds a new variant to the product.
This method appends a new variant to the existing list of product variants. It handles image management by potentially adding a new image to the product's image collections if the variant includes an image. This is useful for expanding the product's variant offerings with additional options like sizes, colors, or configurations.
Clear all existing variants
Clears all variants from the product, including their associated images.
This method removes all existing variants from the product's list of variants (units). It also removes any associated images from the product's images lists (unitsImages and images). This is useful when resetting the product specifications or before reconfiguring the product with a new set of variants.
❗User should add at least one variants after you clear all existing variants
Replace existing variants with new variants
Replaces the current list of product variants with a new list.
This method is used to update the entire set of variants for a product by clearing the existing variants and replacing them with a new list provided as an argument. This is particularly useful when there is a need to refresh the product's variant offerings due to changes in product specifications, discontinuations, or new variant introductions.
Modify existing variants
Modifies an existing variant of the product using a builder block for detailed configuration.
This method locates a variant by its unique identifier and applies a configuration block to it, allowing for detailed custom modifications. If the variant with the specified ID is found, the method uses a builder pattern to apply changes and then updates the product's list of variants with the modified version. This method is ideal for updating specific properties of a variant without altering other variants.
Please note:
allowedVariantOptions
Sets the list of attribute names that are permissible for product variants.
❗ This method updates the product's internal configuration to only allow variants that have attributes specified in the given list. This is essential for maintaining a consistent set of variant attributes such as color, size, material, etc., and ensures that all product variants conform to the expected attributes.
API Doc for Product Hydration
Last updated
Was this helpful?