| @@ -33,8 +33,20 @@ | ||
| 33 | 33 | * |
| 34 | 34 | * @param array $record Product response record. |
| 35 | 35 | */ |
| 36 | 36 | private static function downsize_images( array $record ): array { |
| 37 | + // A VARIATION carries `image` (singular) — WooCommerce's variations controller has no | |
| 38 | + // `images` array, and its `src` is the FULL SIZE file. Without this branch the medium | |
| 39 | + // downsizing silently stops applying to variations and every till pulls full-resolution | |
| 40 | + // originals (#1710). Mirrors what the v1 lane has always done in | |
| 41 | + // `API\V1\Product_Variations_Controller::wcpos_variation_response()`. | |
| 42 | + if ( isset( $record['image'] ) && \is_array( $record['image'] ) && isset( $record['image']['id'] ) ) { | |
| 43 | + $medium = image_downsize( (int) $record['image']['id'], 'medium' ); | |
| 44 | + if ( $medium ) { | |
| 45 | + $record['image']['src'] = $medium[0]; | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 37 | 49 | if ( ! isset( $record['images'] ) || ! \is_array( $record['images'] ) ) { |
| 38 | 50 | return $record; |
| 39 | 51 | } |
| 40 | 52 | foreach ( $record['images'] as $index => $entry ) { |