diff --git a/assets/js/blocks/product-query/constants.ts b/assets/js/blocks/product-query/constants.ts index f4ef7d34a82..ec91fd2f4f1 100644 --- a/assets/js/blocks/product-query/constants.ts +++ b/assets/js/blocks/product-query/constants.ts @@ -1,10 +1,10 @@ /** * External dependencies */ -import { getSetting } from '@woocommerce/settings'; +import { getSetting, getSettingWithCoercion } from '@woocommerce/settings'; import { objectOmit } from '@woocommerce/utils'; import type { InnerBlockTemplate } from '@wordpress/blocks'; - +import { isBoolean } from '@woocommerce/types'; /** * Internal dependencies */ @@ -69,19 +69,25 @@ export const QUERY_DEFAULT_ATTRIBUTES: QueryBlockAttributes = { }, }; +// This is necessary to fix https://github.com/woocommerce/woocommerce-blocks/issues/9884. +const postTemplateHasSupportForGridView = getSettingWithCoercion( + 'post_template_has_support_for_grid_view', + false, + isBoolean +); + export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [ [ 'core/post-template', { __woocommerceNamespace: PRODUCT_TEMPLATE_ID, - layout: { - type: 'grid', - columnsCount: 3, - }, /** * This class is used to add default styles for inner blocks. */ className: 'products-block-post-template', + ...( postTemplateHasSupportForGridView && { + layout: { type: 'grid', columnCount: 3 }, + } ), }, [ [ diff --git a/assets/js/blocks/product-query/variations/related-products.tsx b/assets/js/blocks/product-query/variations/related-products.tsx index 6ff35170b37..7fa859db0a9 100644 --- a/assets/js/blocks/product-query/variations/related-products.tsx +++ b/assets/js/blocks/product-query/variations/related-products.tsx @@ -6,6 +6,8 @@ import { Icon } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { stacks } from '@woocommerce/icons'; import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils'; +import { getSettingWithCoercion } from '@woocommerce/settings'; +import { isBoolean } from '@woocommerce/types'; /** * Internal dependencies @@ -43,6 +45,12 @@ export const BLOCK_ATTRIBUTES = { }, }; +const postTemplateHasSupportForGridView = getSettingWithCoercion( + 'post_template_has_support_for_grid_view', + false, + isBoolean +); + export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [ [ 'core/heading', @@ -55,10 +63,9 @@ export const INNER_BLOCKS_TEMPLATE: InnerBlockTemplate[] = [ 'core/post-template', { __woocommerceNamespace: PRODUCT_TEMPLATE_ID, - layout: { - type: 'grid', - columnsCount: 3, - }, + ...( postTemplateHasSupportForGridView && { + layout: { type: 'grid', columnCount: 3 }, + } ), }, [ [ diff --git a/docs/internal-developers/testing/smoke-testing.md b/docs/internal-developers/testing/smoke-testing.md index 7905ffd7277..251f4d00216 100644 --- a/docs/internal-developers/testing/smoke-testing.md +++ b/docs/internal-developers/testing/smoke-testing.md @@ -174,7 +174,7 @@ Note: some blocks might fail to render because they are based on products having
-
+
diff --git a/patterns/featured-products-5-cols.php b/patterns/featured-products-5-cols.php index dae4ff3743e..db992b2450b 100644 --- a/patterns/featured-products-5-cols.php +++ b/patterns/featured-products-5-cols.php @@ -14,7 +14,7 @@
- +
diff --git a/patterns/product-collections-featured-collection.php b/patterns/product-collections-featured-collection.php index fbb70e5b508..04291c3456d 100644 --- a/patterns/product-collections-featured-collection.php +++ b/patterns/product-collections-featured-collection.php @@ -23,7 +23,7 @@
- + diff --git a/patterns/product-collections-newest-arrivals.php b/patterns/product-collections-newest-arrivals.php index 117e78d8d8f..c372bdcc66e 100644 --- a/patterns/product-collections-newest-arrivals.php +++ b/patterns/product-collections-newest-arrivals.php @@ -31,7 +31,7 @@
- +
diff --git a/patterns/product-featured-2-columns.php b/patterns/product-featured-2-columns.php index 6ce0f3f557e..327a432eb21 100644 --- a/patterns/product-featured-2-columns.php +++ b/patterns/product-featured-2-columns.php @@ -12,7 +12,7 @@
- + diff --git a/src/BlockTypes/ProductQuery.php b/src/BlockTypes/ProductQuery.php index 2edd0a5a956..380f9a34224 100644 --- a/src/BlockTypes/ProductQuery.php +++ b/src/BlockTypes/ProductQuery.php @@ -75,6 +75,38 @@ protected function initialize() { add_filter( 'rest_product_collection_params', array( $this, 'extend_rest_query_allowed_params' ), 10, 1 ); } + /** + * Extra data passed through from server to client for block. + * + * @param array $attributes Any attributes that currently are available from the block. + * Note, this will be empty in the editor context when the block is + * not in the post content on editor load. + */ + protected function enqueue_data( array $attributes = [] ) { + parent::enqueue_data( $attributes ); + + $gutenberg_version = ''; + + if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) { + if ( defined( 'GUTENBERG_VERSION' ) ) { + $gutenberg_version = GUTENBERG_VERSION; + } + + if ( ! $gutenberg_version ) { + $gutenberg_data = get_file_data( + WP_PLUGIN_DIR . '/gutenberg/gutenberg.php', + array( 'Version' => 'Version' ) + ); + $gutenberg_version = $gutenberg_data['Version']; + } + } + + $this->asset_data_registry->add( + 'post_template_has_support_for_grid_view', + version_compare( $gutenberg_version, '16.0', '>=' ) + ); + } + /** * Check if a given block * diff --git a/templates/templates/blockified/archive-product.html b/templates/templates/blockified/archive-product.html index 69f533bffd2..81687d48b5d 100644 --- a/templates/templates/blockified/archive-product.html +++ b/templates/templates/blockified/archive-product.html @@ -18,7 +18,7 @@
- + diff --git a/templates/templates/blockified/product-search-results.html b/templates/templates/blockified/product-search-results.html index 17b39c4bb44..109fb56f4d5 100644 --- a/templates/templates/blockified/product-search-results.html +++ b/templates/templates/blockified/product-search-results.html @@ -16,7 +16,7 @@
- + diff --git a/templates/templates/blockified/single-product.html b/templates/templates/blockified/single-product.html index 501777643c1..0fecbef4636 100644 --- a/templates/templates/blockified/single-product.html +++ b/templates/templates/blockified/single-product.html @@ -53,7 +53,7 @@

Related products

- + diff --git a/templates/templates/blockified/taxonomy-product_attribute.html b/templates/templates/blockified/taxonomy-product_attribute.html index 3bf25ca4931..62d797de82c 100644 --- a/templates/templates/blockified/taxonomy-product_attribute.html +++ b/templates/templates/blockified/taxonomy-product_attribute.html @@ -18,7 +18,7 @@
- + @@ -46,4 +46,4 @@
- + \ No newline at end of file diff --git a/templates/templates/blockified/taxonomy-product_cat.html b/templates/templates/blockified/taxonomy-product_cat.html index 3bf25ca4931..62d797de82c 100644 --- a/templates/templates/blockified/taxonomy-product_cat.html +++ b/templates/templates/blockified/taxonomy-product_cat.html @@ -18,7 +18,7 @@
- + @@ -46,4 +46,4 @@
- + \ No newline at end of file diff --git a/templates/templates/blockified/taxonomy-product_tag.html b/templates/templates/blockified/taxonomy-product_tag.html index 9c6699850d0..1de3af7a0ed 100644 --- a/templates/templates/blockified/taxonomy-product_tag.html +++ b/templates/templates/blockified/taxonomy-product_tag.html @@ -18,7 +18,7 @@
- + @@ -43,4 +43,4 @@
-
+
\ No newline at end of file