Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Release: 6.5.1 (#5439)
Browse files Browse the repository at this point in the history
* Empty commit for release pull request

* Fix saving WooCommerce templates in WP 5.9 beta 3 (#5408)

* fix not found template for the template editor (#5425)

* Check for woocommerce as the theme before rendering with a more user friendly plugin name (#5420)

* Make it so WooCommerce template names are not editable (#5385)

* Make it so WooCommerce template names is not editable

* Remove source='plugin' from templates

* Load required scripts in LegacyTemplate.php render method (#5346)

* Fix reverting WC templates (#5342)

* Update block theme conditionals in BlockTemplateController (#5335)

* Check if the current theme has a product-archive block template in the absence of a product taxonomy block template. (#5380)

* Add archive-product template into block template hieachy

* Add archive-product condition to product tag block template render method

* Move taxonomy hierarchy filter to WC core

* Undo template amends

* Duplicate the themes archive-product template if it has one for taxonomy block templates

* Review feedback

* Use TextDomain instead of Name

* use correct if/else syntax

* Remove unncessary boolean syntax

* Update readme.txt for 6.5.1 changelog

* Testing notes for 6.5.1

* Bumping version strings to new version.

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
Co-authored-by: Luigi Teschio <gigitux@gmail.com>
Co-authored-by: Tom Cafferkey <tjcafferkey@gmail.com>
  • Loading branch information
5 people committed Dec 22, 2021
1 parent bf1dd9e commit 2a4b217
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 37 deletions.
87 changes: 87 additions & 0 deletions docs/testing/releases/651.md
@@ -0,0 +1,87 @@
## Testing notes and ZIP for release 6.6.0

Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-gutenberg-products-block/files/7762015/woocommerce-gutenberg-products-block.zip)

## Feature plugin and package inclusion in WooCommerce

### Fix saving WooCommerce templates in WP 5.9 beta 3 ([5408](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5408))

1. With WP 5.9 beta 3 and Gutenberg disabled, go to Appearance > Editor.
2. Edit one of the WooCommerce templates and try to save it.
3. Verify the template is saved without errors.
4. Repeat the process with Gutenberg enabled and verify it works as well.

### Fixed error reporting block templates do not exist after editing WooCommerce templates on WP 5.8. ([5425](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5425))

Test the following under these scenarios:

- WordPress 5.8 and the Gutenberg plugin
- WordPress 5.9 and the Gutenberg plugin
- WordPress 5.9 without the Gutenberg plugin

1. Open the FSE editor
2. From the sidebar on the left click on Templates.
3. Click on one of these templates Product Category Page, Product Archive Page, Product Archive Page or Single Product Page.
4. Edit the template and save it.
5. Go back (not refresh the page, because you will reproduce a known bug (#5426).
6. Reopen the same template and check if the changes are still there.
7. Check if the template works correctly on the frontend side too.

### Added By template column value is user friendly for modified WooCommerce block templates. ([5420](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5420))

1. Modify one of the WooCommerce block templates via the Site Editor. Save it.
2. Load the templates screen and ensure the Added By column value says WooCommerce and not woocommerce
3. Ensure the modified version of the template loads in the Site Editor and on the frontend.

### Avoid WooCommerce template names being editable. ([5385](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5385))

1. With WC 6.0 beta 3 and a block theme installed, go to Appearance > Editor.
2. Go to the Templates page and edit one of the WooCommerce templates (ie: Single Product Page).
3. Save and refresh the page.
4. Verify the template name is not editable.

### Use the themes product archive block template for product category & product tag pages if the theme does not have more specific templates for those. ([5380](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5380))

Add the following block markup to the following templates so you know which one is getting rendered:

1. woo-blocks/archive-product.html
2. woo-blocks/taxonomy-product_tag.html
3. woo-blocks/taxonomy-product_cat.html

Template:

```
<!-- wp:paragraph -->
<p>Woo Blocks: [template-filename].html</p>
<!-- /wp:paragraph -->
```

1. Install Gutenberg plugin and Blockbase theme to activate Site Editor and FSE.
2. Go to a product category page and check that woo-blocks/taxonomy-product_cat.html is the template being used.
3. Duplicate woo-blocks/archive-product.html into blockbase/block-templates/ and change the markup you added above to say "Blockbase" instead of "Woo Blocks" so we can differentiate.
4. Reload the product category page, product tag page, and main shop page/product archive page and check that the archive-product.html from Blockbase is being loaded.
5. Go into Site Editor > All Templates and check that "Product Archive Page", "Product Category Page" and "Product Tag Page" are all in the list and it states they're being loaded from the Blockbase theme
6. Customise the Product Category Page template and save your changes
7. Reload the product category page on the frontend and check the customised version of this template is being rendered.

### Fixed issue with variable products add to cart error, and gallery not updating to show correct product variant image. ([5346](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5346))

1. Install a Block Theme such as [TT1](https://en-gb.wordpress.org/themes/tt1-blocks/) and the [Gutenberg plugin](https://wordpress.org/plugins/gutenberg/).
2. Load the product page of a variable product.
3. Change some of the options (such as colour) on the variable product and check that the image in the product gallery updates to show the correct image for that variant.
4. Clicking "Add to cart" should successfully add the product to the cart.

### Fix error when reverting WooCommerce templates. ([5342](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5342))

1. With WC 6.0 or later, Gutenberg and a block theme installed, go to Appearance > Editor.
2. Go to the Templates page and edit one of the WooCommerce templates (ie: Single Product Page).
3. In the frontend, verify the changes you just saved are applied.
4. Go back to the Templates page and press on _Clear Customizations_ of the template you just edited.
5. Verify there is no error and the changes have been reverted in the frontend.
6. Repeat the steps above with WP 5.9 beta without Gutenberg enabled.

### Fix: WooCommerce block templates loading for WP 5.9 without Gutenberg plugin. ([5335](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5335))

1. Make sure you have WP 5.9 or above.
2. Install a Block Theme such as [TT1](https://en-gb.wordpress.org/themes/tt1-blocks/).
3. Make sure you can load the list of Block Templates in the Appearance > Site Editor
1 change: 1 addition & 0 deletions docs/testing/releases/README.md
Expand Up @@ -53,3 +53,4 @@ Every release includes specific testing instructions for new features and bug fi
- [6.3.3](./633.md)
- [6.4.0](./640.md)
- [6.5.0](./650.md)
- [6.5.1](./651.md)
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "@woocommerce/block-library",
"title": "WooCommerce Blocks",
"author": "Automattic",
"version": "6.5.0",
"version": "6.5.1",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
"keywords": [
Expand Down
14 changes: 13 additions & 1 deletion readme.txt
Expand Up @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks
Requires at least: 5.8
Tested up to: 5.8
Requires PHP: 7.0
Stable tag: 6.5.0
Stable tag: 6.5.1
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -85,6 +85,18 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/

== Changelog ==

= 6.5.1 - 2021-12-22 =

#### Bug Fixes

- Fixed error reporting block templates do not exist after editing WooCommerce templates on WP 5.8. ([5425](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5425))
- Added By template column value is user friendly for modified WooCommerce block templates. ([5420](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5420))
- Avoid WooCommerce template names being editable. ([5385](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5385))
- Use the themes product archive block template for product category & product tag pages if the theme does not have more specific templates for those. ([5380](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5380))
- Fixed issue with variable products add to cart error, and gallery not updating to show correct product variant image. ([5346](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5346))
- Fix error when reverting WooCommerce templates. ([5342](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5342))
- Fix: WooCommerce block templates loading for WP 5.9 without Gutenberg plugin. ([5335](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5335))

= 6.5.0 - 2021-12-06 =

#### Enhancements
Expand Down
62 changes: 38 additions & 24 deletions src/BlockTemplatesController.php
Expand Up @@ -55,7 +55,7 @@ public function __construct() {
*/
protected function init() {
add_action( 'template_redirect', array( $this, 'render_block_template' ) );
add_filter( 'pre_get_block_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );
add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );
add_filter( 'get_block_templates', array( $this, 'add_block_templates' ), 10, 3 );
add_filter( 'default_wp_template_part_areas', array( $this, 'add_template_part_areas' ) );
add_filter( 'wp_insert_post', array( $this, 'add_mini_cart_content_to_template_part' ), 10, 3 );
Expand All @@ -74,7 +74,13 @@ protected function init() {
* @return mixed|\WP_Block_Template|\WP_Error
*/
public function maybe_return_blocks_template( $template, $id, $template_type ) {
if ( ! function_exists( 'gutenberg_get_block_template' ) ) {
// 'get_block_template' was introduced in WP 5.9. We need to support
// 'gutenberg_get_block_template' for previous versions of WP with
// Gutenberg enabled.
if (
! function_exists( 'gutenberg_get_block_template' ) &&
! function_exists( 'get_block_template' )
) {
return $template;
}
$template_name_parts = explode( '//', $id );
Expand All @@ -84,24 +90,29 @@ public function maybe_return_blocks_template( $template, $id, $template_type ) {
list( , $slug ) = $template_name_parts;

// Remove the filter at this point because if we don't then this function will infinite loop.
remove_filter( 'pre_get_block_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );
remove_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );

// Check if the theme has a saved version of this template before falling back to the woo one. Please note how
// the slug has not been modified at this point, we're still using the default one passed to this hook.
$maybe_template = gutenberg_get_block_template( $id, $template_type );
$maybe_template = function_exists( 'gutenberg_get_block_template' ) ?
gutenberg_get_block_template( $id, $template_type ) :
get_block_template( $id, $template_type );

if ( null !== $maybe_template ) {
add_filter( 'pre_get_block_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );
add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );
return $maybe_template;
}

// Theme-based template didn't exist, try switching the theme to woocommerce and try again. This function has
// been unhooked so won't run again.
add_filter( 'get_block_template', array( $this, 'get_single_block_template' ), 10, 3 );
$maybe_template = gutenberg_get_block_template( 'woocommerce//' . $slug, $template_type );
add_filter( 'get_block_file_template', array( $this, 'get_single_block_template' ), 10, 3 );
$maybe_template = function_exists( 'gutenberg_get_block_template' ) ?
gutenberg_get_block_template( 'woocommerce//' . $slug, $template_type ) :
get_block_template( 'woocommerce//' . $slug, $template_type );

// Re-hook this function, it was only unhooked to stop recursion.
add_filter( 'pre_get_block_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );
remove_filter( 'get_block_template', array( $this, 'get_single_block_template' ), 10, 3 );
add_filter( 'pre_get_block_file_template', array( $this, 'maybe_return_blocks_template' ), 10, 3 );
remove_filter( 'get_block_file_template', array( $this, 'get_single_block_template' ), 10, 3 );
if ( null !== $maybe_template ) {
return $maybe_template;
}
Expand Down Expand Up @@ -155,7 +166,7 @@ public function get_single_block_template( $template, $id, $template_type ) {
* @return array
*/
public function add_block_templates( $query_result, $query, $template_type ) {
if ( ! function_exists( 'gutenberg_supports_block_templates' ) || ! gutenberg_supports_block_templates() ) {
if ( ! BlockTemplateUtils::supports_block_templates() ) {
return $query_result;
}

Expand Down Expand Up @@ -338,21 +349,25 @@ function ( $template ) use ( $template_slug ) {
continue;
}

// If the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template.
if ( 'taxonomy-product_cat' === $template_slug && ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_cat' ) && BlockTemplateUtils::theme_has_template( 'archive-product' ) ) {
$template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html';
$templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true );
continue;
}

// If the theme has an archive-product.html template, but not a taxonomy-product_tag.html template let's use the themes archive-product.html template.
if ( 'taxonomy-product_tag' === $template_slug && ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_tag' ) && BlockTemplateUtils::theme_has_template( 'archive-product' ) ) {
$template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html';
$templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true );
continue;
}

// At this point the template only exists in the Blocks filesystem and has not been saved in the DB,
// or superseded by the theme.
$new_template_item = array(
'slug' => $template_slug,
'id' => 'woocommerce//' . $template_slug,
'path' => $template_file,
'type' => $template_type,
'theme' => 'woocommerce',
'source' => 'plugin',
'title' => BlockTemplateUtils::convert_slug_to_title( $template_slug ),
'description' => '',
'post_types' => array(), // Don't appear in any Edit Post template selector dropdown.
);
$templates[] = (object) $new_template_item;
$templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug );
}

return $templates;
}

Expand All @@ -370,7 +385,6 @@ public function get_block_templates( $slugs = array(), $template_type = 'wp_temp
return array_merge( $templates_from_db, $templates_from_woo );
}


/**
* Gets the directory where templates of a specific template type can be found.
*
Expand Down Expand Up @@ -408,7 +422,7 @@ public function block_template_is_available( $template_name, $template_type = 'w
* Renders the default block template from Woo Blocks if no theme templates exist.
*/
public function render_block_template() {
if ( is_embed() || ! function_exists( 'gutenberg_supports_block_templates' ) || ! gutenberg_supports_block_templates() ) {
if ( is_embed() || ! BlockTemplateUtils::supports_block_templates() ) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions src/BlockTypes/LegacyTemplate.php
Expand Up @@ -34,6 +34,14 @@ protected function render( $attributes, $content ) {
return;
}

// We need to load the scripts here because when using block templates wp_head() gets run after the block template.
// As a result we are trying to enqueue required scripts before we have even registered them.
// See here for more information: https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5328#issuecomment-989013447.
if ( class_exists( 'WC_Frontend_Scripts' ) ) {
$frontend_scripts = new \WC_Frontend_Scripts();
$frontend_scripts::load_scripts();
}

$archive_templates = array( 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag' );

if ( 'single-product' === $attributes['template'] ) {
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Expand Up @@ -106,7 +106,7 @@ public static function container( $reset = false ) {
NewPackage::class,
function ( $container ) {
// leave for automated version bumping.
$version = '6.5.0';
$version = '6.5.1';
return new NewPackage(
$version,
dirname( __DIR__ ),
Expand Down

0 comments on commit 2a4b217

Please sign in to comment.