Fix image not rendering on the editor and empty styles (https://github.com/woocommerce/woocommerce-blocks/pull/10089)

This commit is contained in:
Alba Rincón 2023-07-04 11:02:35 +02:00 committed by GitHub
parent d6037a2efb
commit 25a5737ec7
2 changed files with 10 additions and 3 deletions

View File

@ -60,8 +60,6 @@
.wc-block-components-product-image {
margin: 0 0 $gap-small;
position: relative;
z-index: -1;
}
.wc-block-product-image__tools-panel .components-input-control {

View File

@ -148,7 +148,16 @@ class ProductImage extends AbstractBlock {
private function render_image( $product, $attributes ) {
$image_size = 'single' === $attributes['imageSizing'] ? 'woocommerce_single' : 'woocommerce_thumbnail';
$image_style = sprintf( 'max-width:none; height:%s; width:%s; object-fit:%s;', $attributes['height'] ?? '', $attributes['width'] ?? '', $attributes['scale'] ?? '' );
$image_style = 'max-width:none;';
if ( ! empty( $attributes['height'] ) ) {
$image_style .= sprintf( 'height:%s;', $attributes['height'] );
}
if ( ! empty( $attributes['width'] ) ) {
$image_style .= sprintf( 'width:%s;', $attributes['width'] );
}
if ( ! empty( $attributes['scale'] ) ) {
$image_style .= sprintf( 'object-fit:%s;', $attributes['scale'] );
}
if ( ! $product->get_image_id() ) {
// The alt text is left empty on purpose, as it's considered a decorative image.