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

Commit

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

* Fix state validation to compare state codes, and only validate if a country is given (#5132)

* Only get valid states from wc if there is a country

* Shared validation logic which uses keys

* Fix 'Country is required' error on the Cart block when updating shipping address (#5129)

* Fix  error on the Cart block

* Created a cartIsHydrated variable in useStoreCart hook and used this to update the billing address in the internal state of the useCustomerData hook

* Fix the country is required error on the Cart page using refs

* Separate api calls to update shipping and billingUpdate billing and shipping addresses only when needed in API calls

* Remove redundant check for customerDataToUpdate

* remove use of refs in initial values

Co-authored-by: Nadir Seghir <[email protected]>

* Make order note block removable (#5139)

* unforce order note

* show block in inserter

* Mini Cart block fatal error caused by append_script_and_deps_src (#5142)

* Remove unused use statements

* Fix types for $script

* `get_script_from_handle` might return null so handle this case to prevent errors

* Missing escaping

* Replace do_action_deprecated with the WC equivalent (#5151)

* Remove feature gate condition for Legacy Template block (#5158)

* Update readme.txt

* Update testing instructions

* Bumping version strings to new version.

Co-authored-by: github-actions <[email protected]>
Co-authored-by: Mike Jolley <[email protected]>
Co-authored-by: Alex Florisca <[email protected]>
Co-authored-by: Nadir Seghir <[email protected]>
Co-authored-by: Thomas Roberts <[email protected]>
Co-authored-by: Albert Juhé Lluveras <[email protected]>
Co-authored-by: Niels Lange <[email protected]>
  • Loading branch information
8 people authored Nov 17, 2021
1 parent 4c8d74f commit b0ad2b5
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 76 deletions.
1 change: 1 addition & 0 deletions assets/js/base/context/hooks/cart/use-store-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export const useStoreCart = (
const cartIsLoading = ! store.hasFinishedResolution(
'getCartData'
);

const shippingRatesLoading = store.isCustomerDataUpdating();
const { receiveCart } = dispatch( storeKey );
const billingAddress = decodeValues( cartData.billingAddress );
Expand Down
70 changes: 55 additions & 15 deletions assets/js/base/context/hooks/use-customer-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import {
pluckAddress,
pluckEmail,
} from '@woocommerce/base-utils';
import type {
import {
CartResponseBillingAddress,
CartResponseShippingAddress,
BillingAddressShippingAddress,
CartBillingAddress,
CartShippingAddress,
} from '@woocommerce/types';

declare type CustomerData = {
Expand Down Expand Up @@ -92,6 +95,26 @@ export const useCustomerData = (): {
shippingAddress: initialShippingAddress,
} );

// We only want to update the local state once, otherwise the data on the checkout page gets overwritten
// with the initial state of the addresses here
const [ hasCustomerDataSynced, setHasCustomerDataSynced ] = useState<
boolean
>( false );

if (
! hasCustomerDataSynced &&
shouldUpdateAddressStore(
customerData.shippingAddress,
initialShippingAddress
)
) {
setCustomerData( {
billingData: initialBillingAddress,
shippingAddress: initialShippingAddress,
} );
setHasCustomerDataSynced( true );
}

// Store values last sent to the server in a ref to avoid requests unless important fields are changed.
const previousCustomerData = useRef< CustomerData >( customerData );

Expand Down Expand Up @@ -146,23 +169,40 @@ export const useCustomerData = (): {
*/
useEffect( () => {
// Only push updates when enough fields are populated.
if (
! shouldUpdateAddressStore(
previousCustomerData.current.billingData,
debouncedCustomerData.billingData
) &&
! shouldUpdateAddressStore(
previousCustomerData.current.shippingAddress,
debouncedCustomerData.shippingAddress
)
) {
const shouldUpdateBillingAddress = shouldUpdateAddressStore(
previousCustomerData.current.billingData,
debouncedCustomerData.billingData
);

const shouldUpdateShippingAddress = shouldUpdateAddressStore(
previousCustomerData.current.shippingAddress,
debouncedCustomerData.shippingAddress
);

if ( ! shouldUpdateBillingAddress && ! shouldUpdateShippingAddress ) {
return;
}

const customerDataToUpdate:
| Partial< BillingAddressShippingAddress >
| Record<
keyof BillingAddressShippingAddress,
CartBillingAddress | CartShippingAddress
> = {};

if ( shouldUpdateBillingAddress ) {
customerDataToUpdate.billing_address =
debouncedCustomerData.billingData;
}
if ( shouldUpdateShippingAddress ) {
customerDataToUpdate.shipping_address =
debouncedCustomerData.shippingAddress;
}

previousCustomerData.current = debouncedCustomerData;
updateCustomerData( {
billing_address: debouncedCustomerData.billingData,
shipping_address: debouncedCustomerData.shippingAddress,
} )
updateCustomerData(
customerDataToUpdate as Partial< BillingAddressShippingAddress >
)
.then( () => {
removeNotice( 'checkout' );
} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"align": false,
"html": false,
"multiple": false,
"reusable": false,
"inserter": false
"reusable": false
},
"attributes": {
"className": {
Expand All @@ -19,7 +18,7 @@
"lock": {
"type": "object",
"default": {
"remove": true,
"remove": false,
"move": true
}
}
Expand Down
10 changes: 2 additions & 8 deletions assets/js/data/cart/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import type {
Cart,
CartResponse,
CartResponseItem,
CartBillingAddress,
CartShippingAddress,
ExtensionCartUpdateArgs,
BillingAddressShippingAddress,
} from '@woocommerce/types';
import { ReturnOrGeneratorYieldUnion } from '@automattic/data-stores';
import { camelCase, mapKeys } from 'lodash';
Expand Down Expand Up @@ -463,11 +462,6 @@ export function* selectShippingRate(
return true;
}

type BillingAddressShippingAddress = {
billing_address: CartBillingAddress;
shipping_address: CartShippingAddress;
};

/**
* Updates the shipping and/or billing address for the customer and returns an
* updated cart.
Expand All @@ -476,7 +470,7 @@ type BillingAddressShippingAddress = {
* billing_address and shipping_address.
*/
export function* updateCustomerData(
customerData: BillingAddressShippingAddress
customerData: Partial< BillingAddressShippingAddress >
): Generator< unknown, boolean, { response: CartResponse } > {
yield updatingCustomerData( true );

Expand Down
5 changes: 5 additions & 0 deletions assets/js/types/type-defs/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,8 @@ export interface ExtensionCartUpdateArgs {
data: Record< string, unknown >;
namespace: string;
}

export interface BillingAddressShippingAddress {
billing_address: CartBillingAddress;
shipping_address: CartShippingAddress;
}
10 changes: 0 additions & 10 deletions docs/testing/releases/630.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.

⚠️ Please note that some strings are not translated in the frontend. This problem will be addressed with ([5112](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5112)).

### Fix ‘Country is required’ error on the Cart block when updating shipping address ([5129](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5129))

1. Add a product to the cart and go to the cart page.
2. Provide a shipping address in the shipping calculator and click the `Update` button.
3. Provide a shipping address from a different country and click the `Update` button again.
4. Verify that the new shipping address is visible.
5. Verify that the error `Country is required` is not visible.
6. Go to the checkout page and verify that the new shipping address is visible.
7. Finalize the order and verify that the new shipping address is visible on the order details.

### Make order note block removable ([5139](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5139))

1. Create a test page, add the Checkout block and save the page.
Expand Down
15 changes: 15 additions & 0 deletions docs/testing/releases/631.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Testing notes and ZIP for release 6.3.1

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

## Feature Plugin

### Fix ‘Country is required’ error on the Cart block when updating shipping address ([5129](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5129))

1. Add a product to the cart and go to the cart page.
2. Provide a shipping address in the shipping calculator and click the `Update` button.
3. Provide a shipping address from a different country and click the `Update` button again.
4. Verify that the new shipping address is visible.
5. Verify that the error `Country is required` is not visible.
6. Go to the checkout page and verify that the new shipping address is visible.
7. Finalize the order and verify that the new shipping address is visible on the order details.
1 change: 1 addition & 0 deletions docs/testing/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ Every release includes specific testing instructions for new features and bug fi
- [6.1.0](./610.md)
- [6.2.0](./620.md)
- [6.3.0](./630.md)
- [6.3.1](./631.md)
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": "6.3.0",
"version": "6.3.1",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
"keywords": [
Expand Down
13 changes: 9 additions & 4 deletions 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: 5.8
Tested up to: 5.8
Requires PHP: 7.0
Stable tag: 6.3.0
Stable tag: 6.3.1
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

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

== Changelog ==

= 6.3.1 - 2021-11-17 =

#### Bug Fixes

- Fix 'Country is required' error on the Cart block when updating shipping address ([5129](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5129))
- Fix state validation to compare state codes, and only validate if a country is given ([5132](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5132))
- Make order note block removable ([5139](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5139))

= 6.3.0 - 2021-11-16 =

#### Enhancements
Expand All @@ -107,12 +115,9 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/

#### Bug Fixes

- Fix 'Country is required' error on the Cart block when updating shipping address ([5129](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5129))
- Fix label alignment of the product search in the editor. ([5072](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5072))
- Fix sale badge alignment on smaller screen. ([5061](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5061))
- Fix state validation to compare state codes, and only validate if a country is given ([5132](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5132))
- FSE: Fix missing `is_custom` property for WooCommerce block template objects. ([5067](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5067))
- Make order note block removable ([5139](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5139))
- Replace incorrect with correct text domain. ([5020](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5020))
- Scripts using `wc-settings` or script that depend on it would be enqueued in the footer if they're enqueued in the header. ([5059](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5059))

Expand Down
35 changes: 19 additions & 16 deletions src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes;

use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\Assets;
use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;

Expand Down Expand Up @@ -102,7 +100,10 @@ protected function enqueue_data( array $attributes = [] ) {

foreach ( $payment_methods as $payment_method ) {
$payment_method_script = $this->get_script_from_handle( $payment_method );
$this->append_script_and_deps_src( $payment_method_script );

if ( ! is_null( $payment_method_script ) ) {
$this->append_script_and_deps_src( $payment_method_script );
}
}

$this->scripts_to_lazy_load['wc-block-mini-cart-component-frontend'] = array(
Expand Down Expand Up @@ -140,7 +141,7 @@ protected function hydrate_from_api() {
*
* @param string $handle Handle of the script.
*
* @return array Array containing the script data.
* @return \_WP_Dependency|null Object containing the script data if found, or null.
*/
protected function get_script_from_handle( $handle ) {
$wp_scripts = wp_scripts();
Expand All @@ -149,28 +150,30 @@ protected function get_script_from_handle( $handle ) {
return $script;
}
}

return '';
return null;
}

/**
* Recursively appends a scripts and its dependencies into the
* scripts_to_lazy_load array.
* Recursively appends a scripts and its dependencies into the scripts_to_lazy_load array.
*
* @param string $script Array containing script data.
* @param \_WP_Dependency $script Object containing script data.
*/
protected function append_script_and_deps_src( $script ) {
$wp_scripts = wp_scripts();

// This script and its dependencies have already been appended.
if ( array_key_exists( $script->handle, $this->scripts_to_lazy_load ) ) {
if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) ) {
return;
}

if ( count( $script->deps ) > 0 ) {
if ( count( $script->deps ) ) {
foreach ( $script->deps as $dep ) {
if ( ! array_key_exists( $dep, $this->scripts_to_lazy_load ) ) {
$dep_script = $this->get_script_from_handle( $dep );
$this->append_script_and_deps_src( $dep_script );

if ( ! is_null( $dep_script ) ) {
$this->append_script_and_deps_src( $dep_script );
}
}
}
}
Expand Down Expand Up @@ -252,26 +255,26 @@ protected function get_markup() {
</clipPath>
</defs>
</svg>';
$button_html = '<span class="wc-block-mini-cart__amount">' . wp_strip_all_tags( wc_price( $cart_contents_total ) ) . '</span>
$button_html = '<span class="wc-block-mini-cart__amount">' . esc_html( wp_strip_all_tags( wc_price( $cart_contents_total ) ) ) . '</span>
<span class="wc-block-mini-cart__quantity-badge">
' . $icon . '
<span class="wc-block-mini-cart__badge">' . $cart_contents_count . '</span>
</span>';

if ( is_cart() || is_checkout() ) {
return '<div class="wc-block-mini-cart">
<button class="wc-block-mini-cart__button" aria-label="' . $aria_label . '" disabled>' . $button_html . '</button>
<button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '" disabled>' . $button_html . '</button>
</div>';
}

return '<div class="wc-block-mini-cart">
<button class="wc-block-mini-cart__button" aria-label="' . $aria_label . '">' . $button_html . '</button>
<button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '">' . $button_html . '</button>
<div class="wc-block-mini-cart__drawer is-loading is-mobile wc-block-components-drawer__screen-overlay wc-block-components-drawer__screen-overlay--is-hidden" aria-hidden="true">
<div class="components-modal__frame wc-block-components-drawer">
<div class="components-modal__content">
<div class="components-modal__header">
<div class="components-modal__header-heading-container">
<h1 id="components-modal-header-1" class="components-modal__header-heading">' . $title . '</h1>
<h1 id="components-modal-header-1" class="components-modal__header-heading">' . wp_kses_post( $title ) . '</h1>
</div>
</div>'
. $this->get_cart_contents_markup( $cart_contents ) .
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function container( $reset = false ) {
NewPackage::class,
function ( $container ) {
// leave for automated version bumping.
$version = '6.3.0';
$version = '6.3.1';
return new NewPackage(
$version,
dirname( __DIR__ ),
Expand Down
6 changes: 3 additions & 3 deletions src/StoreApi/Routes/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected function get_route_post_response( \WP_REST_Request $request ) {
* @param \WC_Order $order Order object.
* @deprecated 6.3.0 Use woocommerce_blocks_checkout_order_processed instead.
*/
do_action_deprecated(
wc_do_deprecated_action(
'__experimental_woocommerce_blocks_checkout_order_processed',
array(
$this->order,
Expand Down Expand Up @@ -423,7 +423,7 @@ private function create_or_update_draft_order() {
*
* @deprecated 6.3.0 Use woocommerce_blocks_checkout_update_order_meta instead.
*/
do_action_deprecated(
wc_do_deprecated_action(
'__experimental_woocommerce_blocks_checkout_update_order_meta',
array(
$this->order,
Expand Down Expand Up @@ -528,7 +528,7 @@ private function update_order_from_request( \WP_REST_Request $request ) {
*
* @deprecated 6.3.0 Use woocommerce_blocks_checkout_update_order_from_request instead.
*/
do_action_deprecated(
wc_do_deprecated_action(
'__experimental_woocommerce_blocks_checkout_update_order_from_request',
array(
$this->order,
Expand Down
Loading

0 comments on commit b0ad2b5

Please sign in to comment.