From 5d08a97fef365ee29e989854f6a2242b45001e2d Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Tue, 18 Apr 2023 11:02:41 +0200 Subject: [PATCH 01/11] Single Product Template - Compatibility Layer: don't skip custom HTML (#9075) --- .../SingleProductTemplateCompatibility.php | 15 ++++++-- ...ingleProductTemplateCompatibilityTests.php | 37 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Templates/SingleProductTemplateCompatibility.php b/src/Templates/SingleProductTemplateCompatibility.php index bb74c62bb89..5c2e9e4acdf 100644 --- a/src/Templates/SingleProductTemplateCompatibility.php +++ b/src/Templates/SingleProductTemplateCompatibility.php @@ -321,7 +321,7 @@ function( $carry, $item ) { $carry['index'] = $carry['index'] + 1; $block = $item[0]; - if ( 'core/template-part' === $block['blockName'] ) { + if ( 'core/template-part' === $block['blockName'] || self::is_custom_html( $block ) ) { $carry['template'][] = $block; return $carry; } @@ -433,9 +433,6 @@ function( $carry, $block ) { $carry[] = array( $block ); return $carry; } - if ( empty( $block['blockName'] ) ) { - return $carry; - } $last_element_index = count( $carry ) - 1; if ( isset( $carry[ $last_element_index ][0]['blockName'] ) && 'core/template-part' !== $carry[ $last_element_index ][0]['blockName'] ) { $carry[ $last_element_index ][] = $block; @@ -468,6 +465,16 @@ private function inject_hooks_after_the_wrapper( $block_content, $hooks ) { $closing_tag_position + 1, 0 ); + } + + /** + * Plain custom HTML block is parsed as block with an empty blockName with a filled innerHTML. + * + * @param array $block Parse block. + * @return bool + */ + private static function is_custom_html( $block ) { + return empty( $block['blockName'] ) && ! empty( $block['innerHTML'] ); } } diff --git a/tests/php/Templates/SingleProductTemplateCompatibilityTests.php b/tests/php/Templates/SingleProductTemplateCompatibilityTests.php index fd87ba6c5f1..77ac60e13e0 100644 --- a/tests/php/Templates/SingleProductTemplateCompatibilityTests.php +++ b/tests/php/Templates/SingleProductTemplateCompatibilityTests.php @@ -327,4 +327,41 @@ public function test_add_compatibility_layer_with_multiple_blocks_related_to_the $this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' ); } + + /** + * Test that the Single Product Template is wrapped in a div with the correct class if it contains a block related to the Single Product Template and custom HTML isn't removed. + */ + public function test_add_compatibility_layer_if_contains_single_product_blocks_and_custom_HTML_not_removed() { + + $default_single_product_template = ' + + Custom HTML + +
+ +
+ + '; + + $expected_single_product_template = ' + + Custom HTML + +
+ +
+ +
+ +
+ + '; + + $result = SingleProductTemplateCompatibility::add_compatibility_layer( $default_single_product_template ); + + $result_without_withespace = preg_replace( '/\s+/', '', $result ); + $expected_single_product_template_without_whitespace = preg_replace( '/\s+/', '', $expected_single_product_template ); + + $this->assertEquals( $result_without_withespace, $expected_single_product_template_without_whitespace, '' ); + } } From a5d279d24c0aa04b1c11b43ce7e388dbab78c76f Mon Sep 17 00:00:00 2001 From: Manish Menaria Date: Tue, 18 Apr 2023 11:19:59 +0530 Subject: [PATCH 02/11] Fix: tax_query should be calculated only if __woocommerceAttributes is valid (#9049) This commit refactors the update_rest_query method in the ProductQuery.php file to improve code readability. It simplifies conditional expressions by introducing variables for clarity, and uses ternary operators to streamline the logic. --- src/BlockTypes/ProductQuery.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/BlockTypes/ProductQuery.php b/src/BlockTypes/ProductQuery.php index 7013de7b61e..6420019e97e 100644 --- a/src/BlockTypes/ProductQuery.php +++ b/src/BlockTypes/ProductQuery.php @@ -135,16 +135,19 @@ private function merge_tax_queries( ...$queries ) { * @param array $args Query args. * @param WP_REST_Request $request Request. */ - public function update_rest_query( $args, $request ) { - $orderby = $request->get_param( 'orderby' ); - $woo_attributes = $request->get_param( '__woocommerceAttributes' ); - $woo_stock_status = $request->get_param( '__woocommerceStockStatus' ); - $on_sale_query = $request->get_param( '__woocommerceOnSale' ) === 'true' ? $this->get_on_sale_products_query() : array(); - $orderby_query = isset( $orderby ) ? $this->get_custom_orderby_query( $orderby ) : array(); - $attributes_query = is_array( $woo_attributes ) ? $this->get_product_attributes_query( $woo_attributes ) : array(); - $stock_query = is_array( $woo_stock_status ) ? $this->get_stock_status_query( $woo_stock_status ) : array(); - $visibility_query = $this->get_product_visibility_query( $stock_query ); - $tax_query = $this->merge_tax_queries( $attributes_query, $visibility_query ); + public function update_rest_query( $args, $request ): array { + $woo_attributes = $request->get_param( '__woocommerceAttributes' ); + $is_valid_attributes = is_array( $woo_attributes ); + $orderby = $request->get_param( 'orderby' ); + $woo_stock_status = $request->get_param( '__woocommerceStockStatus' ); + $on_sale = $request->get_param( '__woocommerceOnSale' ) === 'true'; + + $on_sale_query = $on_sale ? $this->get_on_sale_products_query() : []; + $orderby_query = $orderby ? $this->get_custom_orderby_query( $orderby ) : []; + $attributes_query = $is_valid_attributes ? $this->get_product_attributes_query( $woo_attributes ) : []; + $stock_query = is_array( $woo_stock_status ) ? $this->get_stock_status_query( $woo_stock_status ) : []; + $visibility_query = is_array( $woo_stock_status ) ? $this->get_product_visibility_query( $stock_query ) : []; + $tax_query = $is_valid_attributes ? $this->merge_tax_queries( $attributes_query, $visibility_query ) : []; return array_merge( $args, $on_sale_query, $orderby_query, $stock_query, $tax_query ); } From 0e3c1831778c5c20d7cfd453ef445e0fb38e22eb Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Mon, 17 Apr 2023 14:23:00 +0200 Subject: [PATCH 03/11] Blockfied Single Product Template: Add support for template for specific product (#9069) --- src/BlockTemplatesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index faf6d49a8ed..2d4315de69d 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -325,7 +325,7 @@ function( $template ) { $template->description = BlockTemplateUtils::get_block_template_description( $template->slug ); } - if ( 'single-product' === $template->slug ) { + if ( str_contains( $template->slug, 'single-product' ) ) { if ( ! is_admin() && ! BlockTemplateUtils::template_has_legacy_template_block( $template ) ) { $new_content = SingleProductTemplateCompatibility::add_compatibility_layer( $template->content ); From 3dbfef25a64af310d3fab08a397da01e0578a122 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Wed, 12 Apr 2023 18:27:02 +0200 Subject: [PATCH 04/11] Product Price Block: remove ProductSelector (#8980) --- .../blocks/product-elements/price/edit.tsx | 59 ++++--------------- 1 file changed, 12 insertions(+), 47 deletions(-) diff --git a/assets/js/atomic/blocks/product-elements/price/edit.tsx b/assets/js/atomic/blocks/product-elements/price/edit.tsx index b45238e9f36..1fe4a4640cf 100644 --- a/assets/js/atomic/blocks/product-elements/price/edit.tsx +++ b/assets/js/atomic/blocks/product-elements/price/edit.tsx @@ -9,14 +9,11 @@ import { import { useEffect } from '@wordpress/element'; import type { BlockAlignment } from '@wordpress/blocks'; import { useSelect } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import Block from './block'; -import { BLOCK_TITLE, BLOCK_ICON } from './constants'; -import { ProductSelector } from '../shared/product-selector'; type UnsupportedAligments = 'wide' | 'full'; type AllowedAlignments = Exclude< BlockAlignment, UnsupportedAligments >; @@ -82,52 +79,20 @@ const PriceEdit = ( { ] ); - const showProductSelector = - ! isDescendentOfQueryLoop && - ! isDescendentOfSingleProductTemplate && - ! attributes.isDescendentOfSingleProductBlock; - - if ( ! showProductSelector ) { - return ( - <> - - { - setAttributes( { textAlign } ); - } } - /> - -
- -
- - ); - } - return ( -
- - - { - setAttributes( { textAlign } ); - } } - /> - + <> + + { + setAttributes( { textAlign } ); + } } + /> + +
- -
+
+ ); }; From 833dd6379684e7fdc8567c6706561d427cb5ecb8 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 18 Apr 2023 09:59:18 +0000 Subject: [PATCH 05/11] Empty commit for release pull request From 3a51dcbfa6867f66d0834f553f8cde533a4a43c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Tue, 18 Apr 2023 12:13:23 +0200 Subject: [PATCH 06/11] Make Woo_Directive_Store PHP 7.3 compatible (#9033) --- src/Interactivity/directives/class-woo-directive-store.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interactivity/directives/class-woo-directive-store.php b/src/Interactivity/directives/class-woo-directive-store.php index 57b8b3c3fc9..3b213d281d3 100644 --- a/src/Interactivity/directives/class-woo-directive-store.php +++ b/src/Interactivity/directives/class-woo-directive-store.php @@ -1,7 +1,7 @@ Date: Tue, 18 Apr 2023 12:48:26 +0200 Subject: [PATCH 07/11] update version --- composer.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/Package.php | 2 +- woocommerce-gutenberg-products-block.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 44d675f4727..e912f0f7235 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://woocommerce.com/", "type": "wordpress-plugin", - "version": "10.0.0", + "version": "10.0.1", "keywords": [ "gutenberg", "woocommerce", diff --git a/package-lock.json b/package-lock.json index 641990e469a..78f85c8ac2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@woocommerce/block-library", - "version": "10.0.0", + "version": "10.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@woocommerce/block-library", - "version": "10.0.0", + "version": "10.0.1", "hasInstallScript": true, "license": "GPL-3.0+", "dependencies": { diff --git a/package.json b/package.json index 79f347a499e..1265b698480 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@woocommerce/block-library", "title": "WooCommerce Blocks", "author": "Automattic", - "version": "10.0.0", + "version": "10.0.1", "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/", "keywords": [ diff --git a/src/Package.php b/src/Package.php index 5d03ed28d63..3498450952c 100644 --- a/src/Package.php +++ b/src/Package.php @@ -109,7 +109,7 @@ public static function container( $reset = false ) { NewPackage::class, function ( $container ) { // leave for automated version bumping. - $version = '10.0.0'; + $version = '10.0.1'; return new NewPackage( $version, dirname( __DIR__ ), diff --git a/woocommerce-gutenberg-products-block.php b/woocommerce-gutenberg-products-block.php index a227d66288a..eb16d36f6c3 100644 --- a/woocommerce-gutenberg-products-block.php +++ b/woocommerce-gutenberg-products-block.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce Blocks * Plugin URI: https://github.com/woocommerce/woocommerce-gutenberg-products-block * Description: WooCommerce blocks for the Gutenberg editor. - * Version: 10.0.0 + * Version: 10.0.1 * Author: Automattic * Author URI: https://woocommerce.com * Text Domain: woo-gutenberg-products-block From 1f9c169adb12d7be8e6b9b2f9df071a5083f7ab6 Mon Sep 17 00:00:00 2001 From: Luigi Date: Tue, 18 Apr 2023 12:48:36 +0200 Subject: [PATCH 08/11] add changelog --- readme.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index c6b88e7ca7a..a75d64fa69b 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks Requires at least: 6.1 Tested up to: 6.2 Requires PHP: 7.3 -Stable tag: 10.0.0 +Stable tag: 10.0.1 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -80,6 +80,14 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ == Changelog == += 10.0.1 - 2023-04-18 = + +#### Bug Fixes + +- Product Price Block: Remove ProductSelector support. ([8980](https://github.com/woocommerce/woocommerce-blocks/pull/8980)) +- Single Product Compatibility Layer: add support for custom HTML Blocks. ([9075](https://github.com/woocommerce/woocommerce-blocks/pull/9075)) +- Fix: tax_query should be calculated only if __woocommerceAttributes is valid. ([9049](https://github.com/woocommerce/woocommerce-blocks/pull/9049)) + = 10.0.0 - 2023-04-11 = #### Enhancements From 9693782cc4801ba6f5bec2361e6afd1ce4ea32ca Mon Sep 17 00:00:00 2001 From: Luigi Date: Tue, 18 Apr 2023 12:56:18 +0200 Subject: [PATCH 09/11] add testing instructions --- .../testing/releases/1001.md | 35 +++++++++++++++++++ .../testing/releases/README.md | 1 + 2 files changed, 36 insertions(+) create mode 100644 docs/internal-developers/testing/releases/1001.md diff --git a/docs/internal-developers/testing/releases/1001.md b/docs/internal-developers/testing/releases/1001.md new file mode 100644 index 00000000000..afe3cf47357 --- /dev/null +++ b/docs/internal-developers/testing/releases/1001.md @@ -0,0 +1,35 @@ +# Testing notes and ZIP for release 10.0.1 + +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/11190253/woocommerce-gutenberg-products-block.zip) + +## WooCommerce Core + +### Single Product Compatibility Layer: add support for custom HTML Blocks. [(9075)](https://github.com/woocommerce/woocommerce-blocks/pull/9075) + +1. Go to Appearance > Editor and in the Single Product template before upgrading to the blockified version, add a HTML Block _outside_ of the Group block as shown in the screenshot below with the contents `

HTML Block here

` (or similar) +2. Save and view this block on the frontend. +3. Return to the template, upgrade it to the blockified version +4. Save and view on the frontend. Be sure that the HTML is visible on the page. + +![Screenshot 2023-04-17 at 14 34 13](https://user-images.githubusercontent.com/8639742/232499923-9ca7cb7a-c4e7-417d-af78-a8b86b87ea10.png) + +### Blockfied Single Product Template: Add support for template for specific product. [(9069)](https://github.com/woocommerce/woocommerce-blocks/pull/9069) + +1. Go to Editor > Manage Templates > Add new > Single Post: Product > Select a product with multiples images +2. Go into your newly created template, and upgrade Classic template placeholder to the Blockified version of the template. +3. Save the template and visit the product on the frontend. +4. Check that gallery thumbnails work. + +* [ ] Do not include in the Testing Notes + +| Before | After | +|--------|--------| +|![Screenshot 2023-04-17 at 10 23 19](https://user-images.githubusercontent.com/8639742/232442575-6c3929f3-bdf2-403b-89dc-4a2f21d00312.png)|image| + +### Product Price Block: remove ProductSelector support. [(8980)](https://github.com/woocommerce/woocommerce-blocks/pull/8980) + +1. Create a post or page. +2. Insert the All Products block. +3. Edit the layout of the All Products block. +4. Check the Product Price inner block doesn't show the product selector. + diff --git a/docs/internal-developers/testing/releases/README.md b/docs/internal-developers/testing/releases/README.md index 3a5228684c9..58c906f3131 100644 --- a/docs/internal-developers/testing/releases/README.md +++ b/docs/internal-developers/testing/releases/README.md @@ -137,6 +137,7 @@ Every release includes specific testing instructions for new features and bug fi - [9.8.4](./984.md) - [9.9.0](./990.md) - [10.0.0](./1000.md) + - [10.0.1](./1001.md) From 9300ca528b5e4ea4abf5b137d750c9ce6ac55221 Mon Sep 17 00:00:00 2001 From: Luigi Date: Tue, 18 Apr 2023 12:57:36 +0200 Subject: [PATCH 10/11] update zip link file testing --- docs/internal-developers/testing/releases/1001.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internal-developers/testing/releases/1001.md b/docs/internal-developers/testing/releases/1001.md index afe3cf47357..5db2c7da978 100644 --- a/docs/internal-developers/testing/releases/1001.md +++ b/docs/internal-developers/testing/releases/1001.md @@ -1,6 +1,6 @@ # Testing notes and ZIP for release 10.0.1 -Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/11190253/woocommerce-gutenberg-products-block.zip) +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/11260936/woocommerce-gutenberg-products-block.zip) ## WooCommerce Core From 427c5ab026102a0937b5d7303c669e562a4ace75 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Tue, 18 Apr 2023 14:14:54 +0200 Subject: [PATCH 11/11] Update docs/internal-developers/testing/releases/1001.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Albert Juhé Lluveras --- docs/internal-developers/testing/releases/1001.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internal-developers/testing/releases/1001.md b/docs/internal-developers/testing/releases/1001.md index 5db2c7da978..75ca4d7a933 100644 --- a/docs/internal-developers/testing/releases/1001.md +++ b/docs/internal-developers/testing/releases/1001.md @@ -15,7 +15,7 @@ Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github. ### Blockfied Single Product Template: Add support for template for specific product. [(9069)](https://github.com/woocommerce/woocommerce-blocks/pull/9069) -1. Go to Editor > Manage Templates > Add new > Single Post: Product > Select a product with multiples images +1. Go to Appearance > Editor > Templates > Add new (plus icon) > Single Item: Product > Select a product with multiples images 2. Go into your newly created template, and upgrade Classic template placeholder to the Blockified version of the template. 3. Save the template and visit the product on the frontend. 4. Check that gallery thumbnails work.