Host app can implement onUpdateProductDetails callback to update product info in the client side, such as product name. We call this product hydration. For example, the host apps could fetch the latest product information from their own servers on the callback and return the lastest product info in the callback. The code snippets are:
FireworkSDK.getInstance().shopping.onUpdateProductDetails =
(UpdateProductDetailsEvent? event) async {
if (event == null) {
return null;
}
List<Product> products = [];
for (var productId in event.productIds) {
// Get the latest product info from the server, such as the host app server.
final remoteProduct = await fetchProductFromServer(productId)
final product = Product(
productId: productId,
name: remoteProduct.name, // Update the product name
description: remoteProduct.description, // Update the product description
units: remoteProduct.variants!.map((remoteProductVariant) {
return ProductUnit(
unitId: remoteProductVariant.id,
url: remoteProductVariant.url, // Update product variant url
imageUrl: remoteProductVariant.imageUrl, // Update product variant image url
isAvailable: remoteProductVariant.isAvailable, // Update product variant availability
price: ProductPrice(
amount: remoteProductVariant.amount,
currencyCode: remoteProductVariant.currencyCode,
), // Update product variant price
);
}).toList(),
);
products.add(product);
}
// The above example retrieves products one by one.
// But if the server API allows bulk retrieval of product information,
// you can also obtain remote product information in bulk.
// Such as: final remoteProducts = await fetchProductsFromServer(event.productIds)
return products;
};