Home > widget-integration > RecommendationService > transformVariantData
RecommendationService.transformVariantData() method
Transforms a single product variant from Shopify format.
This method can be overridden to customize variant data transformation, such as applying custom pricing, adding custom fields, modifying image URLs, or applying shop-specific business logic.
Signature:
protected transformVariantData(variant: Product$2["variants"][0]): {
price: number;
image: string;
available: boolean;
barcode: string;
compare_at_price: string | null;
fullfillment_service: string;
id: string;
inventory_management: string;
inventory_policy: string;
inventory_quantity: number;
merged_options: Array<string>;
original_merged_options?: Array<string>;
sku: string;
title: string;
featured_image: FeaturedImage;
};
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
variant |
Product$2["variants"][0] |
Shopify product variant object containing price in cents, featured_image, and other variant data |
Returns:
{ price: number; image: string; available: boolean; barcode: string; compare_at_price: string | null; fullfillment_service: string; id: string; inventory_management: string; inventory_policy: string; inventory_quantity: number; merged_options: Array<string>; original_merged_options?: Array<string>; sku: string; title: string; featured_image: FeaturedImage; }
Transformed variant object with price converted to dollars and image URL extracted
Example
Override to apply VIP customer discount:
protected transformVariantData(variant: ShopifyProduct['variants'][0]) {
const baseTransform = super.transformVariantData(variant);
const customer = this.platformLoader.platform.customer;
// Apply VIP discount
if (customer?.tags?.includes('vip-member')) {
baseTransform.price = baseTransform.price * 0.9;
baseTransform.compare_at_price = variant.price / 100;
}
return baseTransform;
}