Commit 9e07cfcecc for woocommerce

commit 9e07cfceccb8d993f8898939c74809a8528444d5
Author: Michael Pretty <prettyboymp@users.noreply.github.com>
Date:   Wed Jan 28 14:21:49 2026 -0500

    Product Gallery: Use variation objects instead of arrays for better performance (#62792)

    * Product Gallery: Use variation objects instead of arrays for better performance

    Use `get_available_variations('objects')` instead of the default 'array'
    return type since we only need variation IDs and image IDs. This avoids
    expensive processing (HTML generation, price calculations, dimension
    formatting) that was being discarded.

    Also fixes the previously skipped e2e test for variation image switching
    by ensuring the test interacts with the correct form element.

    * Add changelog entry

diff --git a/plugins/woocommerce/changelog/WOOPLUG-6120-product-gallery-variation-objects b/plugins/woocommerce/changelog/WOOPLUG-6120-product-gallery-variation-objects
new file mode 100644
index 0000000000..e9cca2dc01
--- /dev/null
+++ b/plugins/woocommerce/changelog/WOOPLUG-6120-product-gallery-variation-objects
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Use variation objects instead of arrays in ProductGallery block to avoid unnecessary data processing
diff --git a/plugins/woocommerce/client/blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-large-image/product-gallery-large-image.block_theme.spec.ts b/plugins/woocommerce/client/blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-large-image/product-gallery-large-image.block_theme.spec.ts
index 543fc70dcb..a00e6b208a 100644
--- a/plugins/woocommerce/client/blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-large-image/product-gallery-large-image.block_theme.spec.ts
+++ b/plugins/woocommerce/client/blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-large-image/product-gallery-large-image.block_theme.spec.ts
@@ -162,13 +162,12 @@ test.describe( `${ blockData.name }`, () => {
 		} );
 	} );

-	// TODO: This test is flaky, we will fix it in https://github.com/woocommerce/woocommerce/pull/55246
-	test.skip( 'Renders correct image when selecting a product variation in the Add to Cart with Options block', async ( {
+	test( 'Renders correct image when selecting a product variation in the Add to Cart with Options block', async ( {
 		page,
 		editor,
 		pageObject,
 	} ) => {
-		await pageObject.addProductGalleryBlock( { cleanContent: false } );
+		await pageObject.addProductGalleryBlock( { cleanContent: true } );
 		await pageObject.addAddToCartWithOptionsBlock();

 		const viewerBlock = await pageObject.getViewerBlock( {
@@ -201,7 +200,7 @@ test.describe( `${ blockData.name }`, () => {
 			const variationImageId = await pageObject.getViewerImageId();

 			expect( initialImageId ).not.toEqual( variationImageId );
-		} ).toPass( { timeout: 1_000 } );
+		} ).toPass( { timeout: 5_000 } );
 	} );

 	test.describe( 'Swipe to navigate', () => {
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductGallery.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductGallery.php
index a0f80ef8f2..c94b0bc18e 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductGallery.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductGallery.php
@@ -155,22 +155,15 @@ class ProductGallery extends AbstractBlock {
 			);

 			if ( $product->is_type( ProductType::VARIABLE ) ) {
-				$variations_data           = $product->get_available_variations();
+				$variations_data           = $product->get_available_variations( 'objects' );
 				$formatted_variations_data = array();
 				$has_variation_images      = false;
 				foreach ( $variations_data as $variation ) {
-					if (
-						empty( $variation['variation_id'] )
-						|| ! array_key_exists( 'image_id', $variation )
-					) {
-						continue;
-					}
-
-					$variation_image_id = (int) $variation['image_id'];
+					$variation_image_id = (int) $variation->get_image_id();
 					if ( $variation_image_id ) {
 						$has_variation_images = true;

-						$formatted_variations_data[ $variation['variation_id'] ] = array(
+						$formatted_variations_data[ $variation->get_id() ] = array(
 							'image_id' => $variation_image_id,
 						);
 					}