Minor Refactor to Prod Image Backend Render Functions (https://github.com/woocommerce/woocommerce-blocks/pull/7247)
* Refactor Product Image anchor render function. Move closing tag for the anchor into the render function and pass badge and image output into anchor children as args. Also removes duplicate border radius logic from anchor render function, as it is already present on the class render method. * Clean up sprintf args. * Replace deprecated placeholder function. The `woocommerce_placeholder_img_src` function has been depricated since v3.0. This replaces that function with the `wc_placeholder_img_src` function.
This commit is contained in:
parent
6f93c5cf1b
commit
3cfc4ec44c
|
@ -115,21 +115,28 @@ class ProductImage extends AbstractBlock {
|
|||
/**
|
||||
* Render anchor.
|
||||
*
|
||||
* @param \WC_Product $product Product object.
|
||||
* @param array $attributes Attributes.
|
||||
* @param \WC_Product $product Product object.
|
||||
* @param string $on_sale_badge Return value from $render_image.
|
||||
* @param string $product_image Return value from $render_on_sale_badge.
|
||||
* @param array $attributes Attributes.
|
||||
* @return string
|
||||
*/
|
||||
private function render_anchor( $product, $attributes ) {
|
||||
private function render_anchor( $product, $on_sale_badge, $product_image, $attributes ) {
|
||||
$product_permalink = $product->get_permalink();
|
||||
|
||||
$border_radius = StyleAttributesUtils::get_border_radius_class_and_style( $attributes );
|
||||
|
||||
$pointer_events = false === $attributes['showProductLink'] ? 'pointer-events: none;' : '';
|
||||
|
||||
return sprintf( '<a href="%s" style="%s">', $product_permalink, $pointer_events, isset( $border_radius['style'] ) ? $border_radius['style'] : '' );
|
||||
return sprintf(
|
||||
'<a href="%1$s" style="%2$s">%3$s %4$s</a>',
|
||||
$product_permalink,
|
||||
$pointer_events,
|
||||
$on_sale_badge,
|
||||
$product_image
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Render Image.
|
||||
*
|
||||
|
@ -140,7 +147,7 @@ class ProductImage extends AbstractBlock {
|
|||
$image_info = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'woocommerce_thumbnail' );
|
||||
|
||||
if ( ! isset( $image_info[0] ) ) {
|
||||
return sprintf( '<img src="%s" alt="" width="500 height="500" />', woocommerce_placeholder_img_src( 'woocommerce_thumbnail' ) );
|
||||
return sprintf( '<img src="%s" alt="" width="500 height="500" />', wc_placeholder_img_src( 'woocommerce_thumbnail' ) );
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
|
@ -186,18 +193,17 @@ class ProductImage extends AbstractBlock {
|
|||
|
||||
if ( $product ) {
|
||||
return sprintf(
|
||||
'
|
||||
<div class="wc-block-components-product-image wc-block-grid__product-image" style="%s %s">
|
||||
%s
|
||||
%s
|
||||
%s
|
||||
</a>
|
||||
</div>',
|
||||
'<div class="wc-block-components-product-image wc-block-grid__product-image" style="%1$s %2$s">
|
||||
%3$s
|
||||
</div>',
|
||||
isset( $border_radius['style'] ) ? $border_radius['style'] : '',
|
||||
isset( $margin['style'] ) ? $margin['style'] : '',
|
||||
$this->render_anchor( $product, $parsed_attributes ),
|
||||
$this->render_on_sale_badge( $product, $parsed_attributes ),
|
||||
$this->render_image( $product )
|
||||
$this->render_anchor(
|
||||
$product,
|
||||
$this->render_on_sale_badge( $product, $parsed_attributes ),
|
||||
$this->render_image( $product ),
|
||||
$parsed_attributes
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue