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

Release: 10.0.1 #9084

Merged
merged 12 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
59 changes: 12 additions & 47 deletions assets/js/atomic/blocks/product-elements/price/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 >;
Expand Down Expand Up @@ -82,52 +79,20 @@ const PriceEdit = ( {
]
);

const showProductSelector =
! isDescendentOfQueryLoop &&
! isDescendentOfSingleProductTemplate &&
! attributes.isDescendentOfSingleProductBlock;

if ( ! showProductSelector ) {
return (
<>
<BlockControls>
<AlignmentToolbar
value={ attributes.textAlign }
onChange={ ( textAlign: AllowedAlignments ) => {
setAttributes( { textAlign } );
} }
/>
</BlockControls>
<div { ...blockProps }>
<Block { ...blockAttrs } />
</div>
</>
);
}

return (
<div { ...blockProps }>
<ProductSelector
productId={ attributes.productId }
setAttributes={ setAttributes }
icon={ BLOCK_ICON }
label={ BLOCK_TITLE }
description={ __(
'Choose a product to display its price.',
'woo-gutenberg-products-block'
) }
>
<BlockControls>
<AlignmentToolbar
value={ attributes.textAlign }
onChange={ ( textAlign: AllowedAlignments ) => {
setAttributes( { textAlign } );
} }
/>
</BlockControls>
<>
<BlockControls>
<AlignmentToolbar
value={ attributes.textAlign }
onChange={ ( textAlign: AllowedAlignments ) => {
setAttributes( { textAlign } );
} }
/>
</BlockControls>
<div { ...blockProps }>
<Block { ...blockAttrs } />
</ProductSelector>
</div>
</div>
</>
);
};

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.0.0",
"version": "10.0.1",
"keywords": [
"gutenberg",
"woocommerce",
Expand Down
35 changes: 35 additions & 0 deletions docs/internal-developers/testing/releases/1001.md
Original file line number Diff line number Diff line change
@@ -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/11260936/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 `<h2>HTML Block here</h2>` (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
gigitux marked this conversation as resolved.
Show resolved Hide resolved
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 <!-- Check this box if this PR can't be tested by users (ie: it doesn't include user-facing changes or it can't be tested without manually modifying the code). -->

| Before | After |
|--------|--------|
|![Screenshot 2023-04-17 at 10 23 19](https://user-images.githubusercontent.com/8639742/232442575-6c3929f3-bdf2-403b-89dc-4a2f21d00312.png)|<img width="1194" alt="image" src="https://user-images.githubusercontent.com/4463174/232467549-35a54ad7-e90a-4263-aa5d-afff83838407.png">|

### 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.

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 @@ -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)


<!-- 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.0.0",
"version": "10.0.1",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
"keywords": [
Expand Down
10 changes: 9 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.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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
23 changes: 13 additions & 10 deletions src/BlockTypes/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/Interactivity/directives/class-woo-directive-store.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

class Woo_Directive_Store {
private static array $store = array();
private static $store = array();

static function get_data() {
return self::$store;
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.0.0';
$version = '10.0.1';
return new NewPackage(
$version,
dirname( __DIR__ ),
Expand Down
15 changes: 11 additions & 4 deletions src/Templates/SingleProductTemplateCompatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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'] );
}
}
37 changes: 37 additions & 0 deletions tests/php/Templates/SingleProductTemplateCompatibilityTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<span>Custom HTML</span>
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';

$expected_single_product_template = '
<!-- wp:template-part {"slug":"header","theme":"twentytwentythree","tagName":"header"} /-->
<span>Custom HTML</span>
<!-- wp:group {"className":"woocommerce product", "__wooCommerceIsFirstBlock":true,"__wooCommerceIsLastBlock":true} -->
<div class="wp-block-group woocommerce product">
<!-- wp:group {"layout":{"inherit":true,"type":"constrained"}} -->
<div class="wp-block-group">
<!-- wp:woocommerce/product-image-gallery /-->
</div>
<!-- /wp:group -->
</div>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","theme":"twentytwentythree","tagName":"footer"} /-->';

$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, '' );
}
}
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.0.0
* Version: 10.0.1
* Author: Automattic
* Author URI: https://woocommerce.com
* Text Domain: woo-gutenberg-products-block
Expand Down