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

Release: 10.8.1 #10485

Merged
merged 6 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions assets/js/atomic/utils/register-block-single-product-template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { isNumber } from '@woocommerce/types';
import {
BlockAttributes,
BlockConfiguration,
Expand All @@ -16,8 +17,10 @@ import { subscribe, select } from '@wordpress/data';
// Creating a local cache to prevent multiple registration tries.
const blocksRegistered = new Set();

function parseTemplateId( templateId: string | undefined ) {
return templateId?.split( '//' )[ 1 ];
function parseTemplateId( templateId: string | number | undefined ) {
// With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230
const parsedTemplateId = isNumber( templateId ) ? undefined : templateId;
return parsedTemplateId?.split( '//' )[ 1 ];
}

export const registerBlockSingleProductTemplate = ( {
Expand All @@ -40,7 +43,11 @@ export const registerBlockSingleProductTemplate = ( {
subscribe( () => {
const previousTemplateId = currentTemplateId;
const store = select( 'core/edit-site' );
currentTemplateId = parseTemplateId( store?.getEditedPostId() );

// With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230
currentTemplateId = parseTemplateId(
store?.getEditedPostId() as string | number | undefined
);
const hasChangedTemplate = previousTemplateId !== currentTemplateId;
const hasTemplateId = Boolean( currentTemplateId );

Expand Down
10 changes: 9 additions & 1 deletion assets/js/blocks/classic-template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { store as noticesStore } from '@wordpress/notices';
import { useEntityRecord } from '@wordpress/core-data';
import { debounce } from '@woocommerce/base-utils';
import { woo } from '@woocommerce/icons';
import { isNumber } from '@woocommerce/types';

/**
* Internal dependencies
Expand Down Expand Up @@ -417,7 +418,14 @@ let currentTemplateId: string | undefined;
subscribe( () => {
const previousTemplateId = currentTemplateId;
const store = select( 'core/edit-site' );
currentTemplateId = store?.getEditedPostId() as string | undefined;
// With GB 16.3.0 the return type can be a number: https://github.com/WordPress/gutenberg/issues/53230
const editedPostId = store?.getEditedPostId() as
| string
| number
| undefined;

currentTemplateId = isNumber( editedPostId ) ? undefined : editedPostId;

const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ];

if ( parsedTemplate === null || parsedTemplate === undefined ) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://woocommerce.com/",
"type": "wordpress-plugin",
"version": "10.8.0",
"version": "10.8.1",
"keywords": [
"gutenberg",
"woocommerce",
Expand Down
23 changes: 23 additions & 0 deletions docs/internal-developers/testing/releases/1081.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Testing notes and ZIP for release 10.8.1

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

## WooCommerce Core

### Classic Template block registration: add defensive type handling [#10475](https://github.com/woocommerce/woocommerce-blocks/pull/10475)

1. Ensure that you have installed Gutenberg 16.3.0.
2. Open the Site Editor.
3. Click on the navigation.
4. Click on the pencil (to edit button).
5. Ensure that the Site Editor doesn't crash

| Before | After |
|--------|--------|
| <video src=https://github.com/woocommerce/woocommerce-blocks/assets/4463174/86ce276e-e372-40e1-8142-cfde84e32bd6 /> | <video src=https://github.com/woocommerce/woocommerce-blocks/assets/4463174/e655eab3-6339-47c9-8447-d9b06c55b795/> |

### Update check for active cart template and migration routine [#10462](https://github.com/woocommerce/woocommerce-blocks/pull/10462)

1. Go to Pages > Cart and edit the page. It will load the site editor. Add some text below the header, for example. Feel free to add anything for testing purposes. Save the template.
2. Add an item to your cart and then load the Cart page on the front end. Ensure your changes from step 1 are visible.
3. Go to the WP Dasboard, then WooCommerce > Settings > Advanced and change the cart page slug to something different. Repeat step 2 and ensure it still works with your change visible. Ensure the path to the Cart page shown in your browser is the one you updated it to.
1 change: 1 addition & 0 deletions docs/internal-developers/testing/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Every release includes specific testing instructions for new features and bug fi
- [10.6.1](./1061.md)
- [10.7.0](./1070.md)
- [10.8.0](./1080.md)
- [10.8.1](./1081.md)


<!-- FEEDBACK -->
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@woocommerce/block-library",
"title": "WooCommerce Blocks",
"author": "Automattic",
"version": "10.8.0",
"version": "10.8.1",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
"keywords": [
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks
Requires at least: 6.2
Tested up to: 6.2
Requires PHP: 7.3
Stable tag: 10.8.0
Stable tag: 10.8.1
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

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

== Changelog ==

= 10.8.1 - 2023-08-07 =

#### Bug Fixes

- Classic Template block registration: Add defensive type handling. ([10475](https://github.com/woocommerce/woocommerce-blocks/pull/10475))
- Fixed an issue where modifications to the Cart/Checkout templates made in the site editor would not be visible on the front end. [#10462](https://github.com/woocommerce/woocommerce-blocks/pull/10462)

= 10.8.0 - 2023-07-31 =

#### Enhancements
Expand Down
34 changes: 26 additions & 8 deletions src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ protected function migrate_page( $page_id, $page ) {
// Use the page template if it exists, which we'll use over our default template if found.
$existing_page_template = BlockTemplateUtils::get_block_template( get_stylesheet() . '//page', 'wp_template' );

if ( $existing_page_template && ! empty( $existing_page_template->content ) ) {
if ( $existing_page_template && ! empty( $existing_page_template->content ) && strstr( $existing_page_template->content, 'wp:post-content' ) ) {
// Massage the original content into something we can use. Replace post content with a group block.
$pattern = '/(<!--\s*)wp:post-content(.*?)(\/-->)/';
$replacement = '
Expand All @@ -835,15 +835,33 @@ protected function migrate_page( $page_id, $page ) {
$template_content = $this->get_default_migrate_page_template( $page );
}

$request = new \WP_REST_Request( 'POST', '/wp/v2/templates/woocommerce/woocommerce//' . $page_id );
$request->set_body_params(
$new_page_template = BlockTemplateUtils::get_block_template( 'woocommerce/woocommerce//' . $page_id, 'wp_template' );

// Check template validity--template must exist, and custom template must not be present already.
if ( ! $new_page_template || $new_page_template->wp_id ) {
update_option( 'has_migrated_' . $page_id, '1' );
return;
}

$new_page_template_id = wp_insert_post(
[
'id' => 'woocommerce/woocommerce//' . $page_id,
'content' => $template_content,
]
'post_name' => $new_page_template->slug,
'post_type' => 'wp_template',
'post_status' => 'publish',
'tax_input' => array(
'wp_theme' => $new_page_template->theme,
),
'meta_input' => array(
'origin' => $new_page_template->source,
),
'post_content' => $template_content,
],
true
);
rest_get_server()->dispatch( $request );
update_option( 'has_migrated_' . $page_id, '1' );

if ( ! is_wp_error( $new_page_template_id ) ) {
update_option( 'has_migrated_' . $page_id, '1' );
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function container( $reset = false ) {
NewPackage::class,
function ( $container ) {
// leave for automated version bumping.
$version = '10.8.0';
$version = '10.8.1';
return new NewPackage(
$version,
dirname( __DIR__ ),
Expand Down
3 changes: 2 additions & 1 deletion src/Templates/CartTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static function get_placeholder_page() {
*/
protected function is_active_template() {
global $post;
return $post instanceof \WP_Post && get_option( 'woocommerce_cart_page_endpoint' ) === $post->post_name;
$placeholder = $this->get_placeholder_page();
return null !== $placeholder && $post instanceof \WP_Post && $placeholder->post_name === $post->post_name;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Templates/CheckoutTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static function get_template_title() {
*/
public function is_active_template() {
global $post;
return $post instanceof \WP_Post && get_option( 'woocommerce_checkout_page_endpoint' ) === $post->post_name;
$placeholder = $this->get_placeholder_page();
return null !== $placeholder && $post instanceof \WP_Post && $placeholder->post_name === $post->post_name;
}
}
2 changes: 1 addition & 1 deletion woocommerce-gutenberg-products-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.8.0
* Version: 10.8.1
* Author: Automattic
* Author URI: https://woocommerce.com
* Text Domain: woo-gutenberg-products-block
Expand Down