Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow
WebflowMapper::build_images
Build the unified images array (product gallery + SKU images, deduped by URL).
The importer requires every image referenced from a variation to also appear in this top-level array — that's how the original_id => attachment mapping is populated. We assign stable original_ids here (preferring Webflow's fileId, falling back to a URL hash) so SKU references resolve cleanly later.
Method of the class: WebflowMapper{}
No Hooks.
Returns
array<int,array{original_id:string,src:string,alt:?string,is_featured:bool}>.
Usage
// private - for code of main (parent) class only $result = $this->build_images( $field_data, $skus ): array;
- $field_data(object) (required)
- Product fieldData.
- $skus(array<int,object>) (required)
- SKUs array.
WebflowMapper::build_images() WebflowMapper::build images code WC 11.1.2
private function build_images( object $field_data, array $skus ): array {
$images = array();
$by_url = array();
$featured_url = null;
// Product-level gallery: fieldData['more-images'].
$more_images_key = 'more-images';
if ( isset( $field_data->{$more_images_key} ) && is_array( $field_data->{$more_images_key} ) ) {
foreach ( $field_data->{$more_images_key} as $img ) {
$entry = $this->normalize_image_object( $img );
if ( null === $entry ) {
continue;
}
if ( null === $featured_url ) {
$featured_url = $entry['src'];
}
$this->add_unique_image( $images, $by_url, $entry );
}
}
// SKU main-image + more-images.
$main_image_key = 'main-image';
foreach ( $skus as $sku ) {
$sku_field = isset( $sku->fieldData ) && is_object( $sku->fieldData ) ? $sku->fieldData : null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Webflow API uses camelCase.
if ( null === $sku_field ) {
continue;
}
$main_entry = isset( $sku_field->{$main_image_key} ) ? $this->normalize_image_object( $sku_field->{$main_image_key} ) : null;
if ( $main_entry ) {
if ( null === $featured_url ) {
$featured_url = $main_entry['src'];
}
$this->add_unique_image( $images, $by_url, $main_entry );
}
if ( isset( $sku_field->{$more_images_key} ) && is_array( $sku_field->{$more_images_key} ) ) {
foreach ( $sku_field->{$more_images_key} as $img ) {
$entry = $this->normalize_image_object( $img );
if ( $entry ) {
$this->add_unique_image( $images, $by_url, $entry );
}
}
}
}
// Mark featured.
foreach ( $images as &$image ) {
$image['is_featured'] = ( $image['src'] === $featured_url );
}
unset( $image );
return $images;
}