* Return empty result if no products are found

* Add empty response handler

* Update to latest PR

* Pass render prop
This commit is contained in:
Mike Jolley 2019-10-16 14:13:10 +01:00 committed by GitHub
parent e227dff18e
commit 5f4949ac6b
2 changed files with 22 additions and 2 deletions

View File

@ -244,6 +244,21 @@ class ProductByCategoryBlock extends Component {
<ServerSideRender
block={ name }
attributes={ attributes }
EmptyResponsePlaceholder={ () => (
<Placeholder
icon="category"
label={ __(
'Products by Category',
'woo-gutenberg-products-block'
) }
className="wc-block-products-grid wc-block-products-category"
>
{ __(
'No products were found that matched your selection.',
'woo-gutenberg-products-block'
) }
</Placeholder>
) }
/>
) : (
__(

View File

@ -68,8 +68,13 @@ abstract class AbstractProductGrid extends AbstractDynamicBlock {
$this->content = $content;
$this->query_args = $this->parse_query_args();
$products = $this->get_products();
$classes = $this->get_container_classes();
$output = implode( '', array_map( array( $this, 'render_product' ), $products ) );
if ( ! $products ) {
return '';
}
$classes = $this->get_container_classes();
$output = implode( '', array_map( array( $this, 'render_product' ), $products ) );
return sprintf( '<div class="%s"><ul class="wc-block-grid__products">%s</ul></div>', esc_attr( $classes ), $output );
}