From a4c78bc6cdd1e8ad89ab309552e71078c6953711 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 13 Oct 2022 14:56:39 +0000 Subject: [PATCH 01/18] Empty commit for release pull request From 5f2e0e058f631f0b2fec8ef3e279bd51146158ec Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:10:10 +0100 Subject: [PATCH 02/18] Added readme.txt changelog entry --- readme.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/readme.txt b/readme.txt index 6eb94e7608b..45189b902b3 100644 --- a/readme.txt +++ b/readme.txt @@ -80,8 +80,16 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ == Changelog == += 8.7.2 - 2022-10-13 = + +#### Bug Fixes + +- Fixed a problem where Custom Order Tables compatibility declaration could fail due to the unpredictable plugin order load. ([7395](https://github.com/woocommerce/woocommerce-blocks/pull/7395)) + = 8.7.1 - 2022-10-12 = +#### Bug Fixes + - Fixed an issue where JavaScript errors would occur when more than one extension tried to filter specific payment methods in the Cart and Checkout blocks. ([7377](https://github.com/woocommerce/woocommerce-blocks/pull/7377)) = 8.7.0 - 2022-10-10 = From b2bb28d51c0c42094e8c03a1470a163d88ae0698 Mon Sep 17 00:00:00 2001 From: Alex Florisca Date: Thu, 13 Oct 2022 15:49:02 +0100 Subject: [PATCH 03/18] Update HPOS compatibility snippet (#7395) --- woocommerce-gutenberg-products-block.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/woocommerce-gutenberg-products-block.php b/woocommerce-gutenberg-products-block.php index 208dc86e9f5..42e82d9edf1 100644 --- a/woocommerce-gutenberg-products-block.php +++ b/woocommerce-gutenberg-products-block.php @@ -25,14 +25,14 @@ } // Declare compatibility with custom order tables for WooCommerce. -if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { - add_action( - 'before_woocommerce_init', - function () { +add_action( + 'before_woocommerce_init', + function () { + if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); } - ); -} + } +); /** * Whether notices must be displayed in the current page (plugins and WooCommerce pages). From dac581917afcae04076fc119044a5d07ca52da5f Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:39:42 +0100 Subject: [PATCH 04/18] 8.7.2 Testing notes --- docs/internal-developers/testing/releases/872.md | 7 +++++++ docs/internal-developers/testing/releases/README.md | 1 + 2 files changed, 8 insertions(+) create mode 100644 docs/internal-developers/testing/releases/872.md diff --git a/docs/internal-developers/testing/releases/872.md b/docs/internal-developers/testing/releases/872.md new file mode 100644 index 00000000000..85632b87f3d --- /dev/null +++ b/docs/internal-developers/testing/releases/872.md @@ -0,0 +1,7 @@ +# Testing notes and ZIP for release 8.7.2 + +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/9778312/woocommerce-gutenberg-products-block.zip) + +## Feature plugin and package inclusion in WooCommerce + +### - Fixed a problem where Custom Order Tables compatibility declaration could fail due to the unpredictable plugin order load. ([7395](https://github.com/woocommerce/woocommerce-blocks/pull/7395)) diff --git a/docs/internal-developers/testing/releases/README.md b/docs/internal-developers/testing/releases/README.md index c0919ae6dd4..a284009be12 100644 --- a/docs/internal-developers/testing/releases/README.md +++ b/docs/internal-developers/testing/releases/README.md @@ -93,6 +93,7 @@ Every release includes specific testing instructions for new features and bug fi - [8.6.0](./860.md) - [8.7.0](./870.md) - [8.7.1](./871.md) + - [8.7.2](./872.md) From 4c25fbc76475f109530434fd8d599bddaa1f7791 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 13 Oct 2022 16:40:36 +0100 Subject: [PATCH 05/18] Update testing notes --- docs/internal-developers/testing/releases/872.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internal-developers/testing/releases/872.md b/docs/internal-developers/testing/releases/872.md index 85632b87f3d..be6a185fcce 100644 --- a/docs/internal-developers/testing/releases/872.md +++ b/docs/internal-developers/testing/releases/872.md @@ -4,4 +4,4 @@ Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github. ## Feature plugin and package inclusion in WooCommerce -### - Fixed a problem where Custom Order Tables compatibility declaration could fail due to the unpredictable plugin order load. ([7395](https://github.com/woocommerce/woocommerce-blocks/pull/7395)) +### Fixed a problem where Custom Order Tables compatibility declaration could fail due to the unpredictable plugin order load ([7395](https://github.com/woocommerce/woocommerce-blocks/pull/7395)) From 85ead2e6fed8400bc71d6dff6d08e04c730e666c Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:43:19 +0100 Subject: [PATCH 06/18] Update testing notes --- docs/internal-developers/testing/releases/872.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/internal-developers/testing/releases/872.md b/docs/internal-developers/testing/releases/872.md index be6a185fcce..9299ecf487f 100644 --- a/docs/internal-developers/testing/releases/872.md +++ b/docs/internal-developers/testing/releases/872.md @@ -5,3 +5,8 @@ Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github. ## Feature plugin and package inclusion in WooCommerce ### Fixed a problem where Custom Order Tables compatibility declaration could fail due to the unpredictable plugin order load ([7395](https://github.com/woocommerce/woocommerce-blocks/pull/7395)) + +#### User Facing Testing + +1. Refer to [High Performance Order Storage Upgrade Recipe Book](https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book) on how to enable HPOS +2. Ensure no incompatibility warnings are displayed regarding the Blocks plugin From de5396a2c3320727dfdea9acd00fb2660fad5a14 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 13 Oct 2022 18:19:19 +0100 Subject: [PATCH 07/18] Bumped version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f3e8eaf3203..6f70a89fbcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@woocommerce/block-library", - "version": "8.7.0-dev", + "version": "8.7.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@woocommerce/block-library", - "version": "8.7.0-dev", + "version": "8.7.2", "hasInstallScript": true, "license": "GPL-3.0+", "dependencies": { diff --git a/package.json b/package.json index 52ddd64b945..e49878a5574 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@woocommerce/block-library", "title": "WooCommerce Blocks", "author": "Automattic", - "version": "8.7.1", + "version": "8.7.2", "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/", "keywords": [ From 4b242de3a1611009c6168049d2466272fe088717 Mon Sep 17 00:00:00 2001 From: Tarun Vijwani Date: Fri, 14 Oct 2022 14:29:06 +0400 Subject: [PATCH 08/18] Refactor force billing: remove forcedBillingAddress from conditions for showBillingFields (#7393) Co-authored-by: Niels Lange --- assets/js/base/context/hooks/use-checkout-address.ts | 3 +-- .../inner-blocks/checkout-billing-address-block/frontend.tsx | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/assets/js/base/context/hooks/use-checkout-address.ts b/assets/js/base/context/hooks/use-checkout-address.ts index 71a5ab7a49b..eb794558539 100644 --- a/assets/js/base/context/hooks/use-checkout-address.ts +++ b/assets/js/base/context/hooks/use-checkout-address.ts @@ -90,8 +90,7 @@ export const useCheckoutAddress = (): CheckoutAddress => { useShippingAsBilling, setUseShippingAsBilling: __internalSetUseShippingAsBilling, showShippingFields: ! forcedBillingAddress && needsShipping, - showBillingFields: - forcedBillingAddress || ! needsShipping || ! useShippingAsBilling, + showBillingFields: ! needsShipping || ! useShippingAsBilling, forcedBillingAddress, }; }; diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/frontend.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/frontend.tsx index 86b4ed1c746..663fb04a652 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/frontend.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/frontend.tsx @@ -38,9 +38,9 @@ const FrontendBlock = ( { showCompanyField, showPhoneField, } = useCheckoutBlockContext(); - const { showBillingFields } = useCheckoutAddress(); + const { showBillingFields, forcedBillingAddress } = useCheckoutAddress(); - if ( ! showBillingFields ) { + if ( ! showBillingFields && ! forcedBillingAddress ) { return null; } From 4627bb5057e572694945fe1a37e478cef2abae00 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Fri, 14 Oct 2022 11:34:10 +0100 Subject: [PATCH 09/18] Updated testing instructions and changelog to include #7393 --- docs/internal-developers/testing/releases/872.md | 10 ++++++++++ readme.txt | 1 + 2 files changed, 11 insertions(+) diff --git a/docs/internal-developers/testing/releases/872.md b/docs/internal-developers/testing/releases/872.md index 9299ecf487f..7379b9690eb 100644 --- a/docs/internal-developers/testing/releases/872.md +++ b/docs/internal-developers/testing/releases/872.md @@ -10,3 +10,13 @@ Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github. 1. Refer to [High Performance Order Storage Upgrade Recipe Book](https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book) on how to enable HPOS 2. Ensure no incompatibility warnings are displayed regarding the Blocks plugin + +### Refactor useCheckoutAddress hook to enable "Use same address for billing" option in Editor ([7393](https://github.com/woocommerce/woocommerce-blocks/pull/7393)) + +#### User Facing Testing + +1. Go to `wp-admin/admin.php?page=wc-settings&tab=shipping§ion=options` page. +2. Enable the `Force shipping to the customer billing address` option and save the changes. +3. Go to Checkout block Editor, and confirm `Use same address for billing` toggle is working as expected. +4. Go to the Checkout block front-end, and confirm shipping address form is not visible. +5. Change the billing address, confirm the shipping address in the order summary gets changed, and shipping methods are updated. diff --git a/readme.txt b/readme.txt index 45189b902b3..3746adab173 100644 --- a/readme.txt +++ b/readme.txt @@ -85,6 +85,7 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ #### Bug Fixes - Fixed a problem where Custom Order Tables compatibility declaration could fail due to the unpredictable plugin order load. ([7395](https://github.com/woocommerce/woocommerce-blocks/pull/7395)) +- Refactor useCheckoutAddress hook to enable "Use same address for billing" option in Editor ([7393](https://github.com/woocommerce/woocommerce-blocks/pull/7393)) = 8.7.1 - 2022-10-12 = From a022233a3135a0646a1ee75e553382e19895a6a3 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Fri, 14 Oct 2022 11:37:54 +0100 Subject: [PATCH 10/18] Updated testing zip --- docs/internal-developers/testing/releases/872.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internal-developers/testing/releases/872.md b/docs/internal-developers/testing/releases/872.md index 7379b9690eb..82ba499435b 100644 --- a/docs/internal-developers/testing/releases/872.md +++ b/docs/internal-developers/testing/releases/872.md @@ -1,6 +1,6 @@ # Testing notes and ZIP for release 8.7.2 -Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/9778312/woocommerce-gutenberg-products-block.zip) +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/9785242/woocommerce-gutenberg-products-block.zip) ## Feature plugin and package inclusion in WooCommerce From 458b153901cc649672c8aed5d4a89e22a9ba9d80 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Fri, 14 Oct 2022 13:13:40 +0100 Subject: [PATCH 11/18] Bumping version strings to new version. --- readme.txt | 2 +- src/Package.php | 2 +- woocommerce-gutenberg-products-block.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.txt b/readme.txt index 3746adab173..2850428c6be 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks Requires at least: 6.0 Tested up to: 6.0 Requires PHP: 7.0 -Stable tag: 8.7.1 +Stable tag: 8.7.2 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/src/Package.php b/src/Package.php index f3fd8408c98..7908c4049ca 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 = '8.7.1'; + $version = '8.7.2'; return new NewPackage( $version, dirname( __DIR__ ), diff --git a/woocommerce-gutenberg-products-block.php b/woocommerce-gutenberg-products-block.php index 42e82d9edf1..40d7321175d 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: 8.7.1 + * Version: 8.7.2 * Author: Automattic * Author URI: https://woocommerce.com * Text Domain: woo-gutenberg-products-block From 723c9f205031d8c92f30bbfe11ecac6ee4cab9fb Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 20 Oct 2022 15:22:56 +0000 Subject: [PATCH 12/18] Empty commit for release pull request From 1a8838c69d4475cdfa70d48e6573e32ca5eb2aa9 Mon Sep 17 00:00:00 2001 From: Thomas Roberts <5656702+opr@users.noreply.github.com> Date: Thu, 20 Oct 2022 16:02:43 +0100 Subject: [PATCH 13/18] Fix wrong keys being sent in `canMakePayment` and customer data showing in the Checkout block in the editor (#7434) * Construct args for canMakePayment with correct keys * When the CheckoutEventsContext mounts, initialize payment store * Destructure useSelect correctly * Dispatch __internalInitializePaymentStore in selector tests * Update selector name to __internalUpdateAvailablePaymentMethods * Remove check for editor when registering checkout store * Add check for when express payment methods have updated too * Ensure billingAddress key exists in canMakePayment arg * Use editor context to know if we're in editor --- .../cart-checkout/checkout-events/index.tsx | 32 +++++ .../payment-methods/test/payment-methods.js | 2 +- assets/js/data/cart/index.ts | 2 +- assets/js/data/checkout/index.ts | 25 +--- assets/js/data/payment/actions.ts | 12 +- .../js/data/payment/check-payment-methods.ts | 117 +++++++++++++++--- assets/js/data/payment/test/selectors.js | 6 +- 7 files changed, 149 insertions(+), 47 deletions(-) diff --git a/assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx b/assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx index 5e3fac07013..c07a0325da0 100644 --- a/assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx +++ b/assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx @@ -16,6 +16,7 @@ import deprecated from '@wordpress/deprecated'; import { useDispatch, useSelect } from '@wordpress/data'; import { CHECKOUT_STORE_KEY, + PAYMENT_STORE_KEY, VALIDATION_STORE_KEY, } from '@woocommerce/block-data'; @@ -28,6 +29,11 @@ import { STATUS } from '../../../../../data/checkout/constants'; import { useStoreEvents } from '../../../hooks/use-store-events'; import { useCheckoutNotices } from '../../../hooks/use-checkout-notices'; import { CheckoutState } from '../../../../../data/checkout/default-state'; +import { + getExpressPaymentMethods, + getPaymentMethods, +} from '../../../../../blocks-registry/payment-methods/registry'; +import { useEditorContext } from '../../editor-context'; type CheckoutEventsContextType = { // Submits the checkout and begins processing. @@ -69,6 +75,32 @@ export const CheckoutEventsProvider = ( { children: React.ReactChildren; redirectUrl: string; } ): JSX.Element => { + const paymentMethods = getPaymentMethods(); + const expressPaymentMethods = getExpressPaymentMethods(); + const { isEditor } = useEditorContext(); + + const { __internalUpdateAvailablePaymentMethods } = + useDispatch( PAYMENT_STORE_KEY ); + + // Update the payment method store when paymentMethods or expressPaymentMethods changes. + // Ensure this happens in the editor even if paymentMethods is empty. This won't happen instantly when the objects + // are updated, but on the next re-render. + useEffect( () => { + if ( + ! isEditor && + Object.keys( paymentMethods ).length === 0 && + Object.keys( expressPaymentMethods ).length === 0 + ) { + return; + } + __internalUpdateAvailablePaymentMethods(); + }, [ + isEditor, + paymentMethods, + expressPaymentMethods, + __internalUpdateAvailablePaymentMethods, + ] ); + const checkoutActions = useDispatch( CHECKOUT_STORE_KEY ); const checkoutState: CheckoutState = useSelect( ( select ) => select( CHECKOUT_STORE_KEY ).getCheckoutState() diff --git a/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js b/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js index 55c5f2af94c..2d29dbb4dd2 100644 --- a/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js +++ b/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js @@ -81,7 +81,7 @@ const registerMockPaymentMethods = () => { ariaLabel: name, } ); } ); - dispatch( PAYMENT_STORE_KEY ).__internalInitializePaymentStore(); + dispatch( PAYMENT_STORE_KEY ).__internalUpdateAvailablePaymentMethods(); }; const resetMockPaymentMethods = () => { diff --git a/assets/js/data/cart/index.ts b/assets/js/data/cart/index.ts index 257752c9ec3..edb93516a56 100644 --- a/assets/js/data/cart/index.ts +++ b/assets/js/data/cart/index.ts @@ -50,7 +50,7 @@ const unsubscribeInitializePaymentStore = registeredStore.subscribe( if ( cartLoaded ) { wpDataDispatch( 'wc/store/payment' - ).__internalInitializePaymentStore(); + ).__internalUpdateAvailablePaymentMethods(); unsubscribeInitializePaymentStore(); } } diff --git a/assets/js/data/checkout/index.ts b/assets/js/data/checkout/index.ts index 53efeae667b..237664d645b 100644 --- a/assets/js/data/checkout/index.ts +++ b/assets/js/data/checkout/index.ts @@ -1,13 +1,7 @@ /** * External dependencies */ -import { - createReduxStore, - register, - subscribe, - select as wpDataSelect, - dispatch as wpDataDispatch, -} from '@wordpress/data'; +import { createReduxStore, register } from '@wordpress/data'; /** * Internal dependencies @@ -17,7 +11,6 @@ import * as selectors from './selectors'; import * as actions from './actions'; import reducer from './reducers'; import { DispatchFromMap, SelectFromMap } from '../mapped-types'; -import { checkPaymentMethodsCanPay } from '../payment/check-payment-methods'; export const config = { reducer, @@ -32,22 +25,6 @@ export const config = { const store = createReduxStore( STORE_KEY, config ); register( store ); -const isEditor = !! wpDataSelect( 'core/editor' ); - -// This is needed to ensure that the payment methods are displayed in the editor -if ( isEditor ) { - const unsubscribeEditor = subscribe( async () => { - await checkPaymentMethodsCanPay(); - await checkPaymentMethodsCanPay( true ); - } ); - - const unsubscribeInitializePaymentStore = subscribe( async () => { - wpDataDispatch( 'wc/store/payment' ).__internalInitializePaymentStore(); - unsubscribeEditor(); - unsubscribeInitializePaymentStore(); - } ); -} - export const CHECKOUT_STORE_KEY = STORE_KEY; declare module '@wordpress/data' { function dispatch( diff --git a/assets/js/data/payment/actions.ts b/assets/js/data/payment/actions.ts index 7fb2181c006..9981343f0a2 100644 --- a/assets/js/data/payment/actions.ts +++ b/assets/js/data/payment/actions.ts @@ -158,13 +158,17 @@ export const __internalRemoveAvailableExpressPaymentMethod = ( /** * The store is initialised once we have checked whether the payment methods registered can pay or not */ -export function __internalInitializePaymentStore() { - return async ( { dispatch } ) => { +export function __internalUpdateAvailablePaymentMethods() { + return async ( { select, dispatch } ) => { const expressRegistered = await checkPaymentMethodsCanPay( true ); const registered = await checkPaymentMethodsCanPay( false ); - if ( registered && expressRegistered ) { - dispatch( __internalSetExpressPaymentMethodsInitialized( true ) ); + const { paymentMethodsInitialized, expressPaymentMethodsInitialized } = + select; + if ( registered && paymentMethodsInitialized ) { dispatch( __internalSetPaymentMethodsInitialized( true ) ); } + if ( expressRegistered && expressPaymentMethodsInitialized ) { + dispatch( __internalSetExpressPaymentMethodsInitialized( true ) ); + } }; } diff --git a/assets/js/data/payment/check-payment-methods.ts b/assets/js/data/payment/check-payment-methods.ts index 842c3e1590f..a92ff91e43c 100644 --- a/assets/js/data/payment/check-payment-methods.ts +++ b/assets/js/data/payment/check-payment-methods.ts @@ -7,7 +7,10 @@ import { } from '@woocommerce/type-defs/payments'; import { CURRENT_USER_IS_ADMIN, getSetting } from '@woocommerce/settings'; import { dispatch, select } from '@wordpress/data'; -import { deriveSelectedShippingRates } from '@woocommerce/base-utils'; +import { + deriveSelectedShippingRates, + emptyHiddenAddressFields, +} from '@woocommerce/base-utils'; import { __, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; @@ -15,6 +18,7 @@ import { getExpressPaymentMethods, getPaymentMethods, } from '@woocommerce/blocks-registry'; +import { previewCart } from '@woocommerce/resource-previews'; /** * Internal dependencies @@ -22,6 +26,15 @@ import { import { STORE_KEY as CART_STORE_KEY } from '../cart/constants'; import { STORE_KEY as PAYMENT_STORE_KEY } from './constants'; import { noticeContexts } from '../../base/context/event-emit'; +import { + EMPTY_CART_ERRORS, + EMPTY_CART_ITEM_ERRORS, + EMPTY_EXTENSIONS, +} from '../../data/constants'; +import { + defaultBillingAddress, + defaultShippingAddress, +} from '../../base/context/providers/cart-checkout/customer/constants'; export const checkPaymentMethodsCanPay = async ( express = false ) => { const isEditor = !! select( 'core/editor' ); @@ -46,19 +59,95 @@ export const checkPaymentMethodsCanPay = async ( express = false ) => { const noticeContext = express ? noticeContexts.EXPRESS_PAYMENTS : noticeContexts.PAYMENTS; - const cart = select( CART_STORE_KEY ).getCartData(); - const selectedShippingMethods = deriveSelectedShippingRates( - cart.shippingRates - ); - const canPayArgument = { - cart, - cartTotals: cart.totals, - cartNeedsShipping: cart.needsShipping, - billingData: cart.billingAddress, - shippingAddress: cart.shippingAddress, - selectedShippingMethods, - paymentRequirements: cart.paymentRequirements, - }; + + let cartForCanPayArgument: Record< string, unknown > = {}; + let canPayArgument: Record< string, unknown > = {}; + + if ( ! isEditor ) { + const store = select( CART_STORE_KEY ); + const cart = store.getCartData(); + const cartErrors = store.getCartErrors(); + const cartTotals = store.getCartTotals(); + const cartIsLoading = ! store.hasFinishedResolution( 'getCartData' ); + const isLoadingRates = store.isCustomerDataUpdating(); + const selectedShippingMethods = deriveSelectedShippingRates( + cart.shippingRates + ); + + cartForCanPayArgument = { + cartCoupons: cart.coupons, + cartItems: cart.items, + crossSellsProducts: cart.crossSells, + cartFees: cart.fees, + cartItemsCount: cart.itemsCount, + cartItemsWeight: cart.itemsWeight, + cartNeedsPayment: cart.needsPayment, + cartNeedsShipping: cart.needsShipping, + cartItemErrors: cart.errors, + cartTotals, + cartIsLoading, + cartErrors, + billingData: emptyHiddenAddressFields( cart.billingAddress ), + billingAddress: emptyHiddenAddressFields( cart.billingAddress ), + shippingAddress: emptyHiddenAddressFields( cart.shippingAddress ), + extensions: cart.extensions, + shippingRates: cart.shippingRates, + isLoadingRates, + cartHasCalculatedShipping: cart.hasCalculatedShipping, + paymentRequirements: cart.paymentRequirements, + receiveCart: dispatch( CART_STORE_KEY ).receiveCart, + }; + + canPayArgument = { + cart: cartForCanPayArgument, + cartTotals: cart.totals, + cartNeedsShipping: cart.needsShipping, + billingData: cart.billingAddress, + billingAddress: cart.billingAddress, + shippingAddress: cart.shippingAddress, + selectedShippingMethods, + paymentRequirements: cart.paymentRequirements, + }; + } else { + cartForCanPayArgument = { + cartCoupons: previewCart.coupons, + cartItems: previewCart.items, + crossSellsProducts: previewCart.cross_sells, + cartFees: previewCart.fees, + cartItemsCount: previewCart.items_count, + cartItemsWeight: previewCart.items_weight, + cartNeedsPayment: previewCart.needs_payment, + cartNeedsShipping: previewCart.needs_shipping, + cartItemErrors: EMPTY_CART_ITEM_ERRORS, + cartTotals: previewCart.totals, + cartIsLoading: false, + cartErrors: EMPTY_CART_ERRORS, + billingData: defaultBillingAddress, + billingAddress: defaultBillingAddress, + shippingAddress: defaultShippingAddress, + extensions: EMPTY_EXTENSIONS, + shippingRates: previewCart.shipping_rates, + isLoadingRates: false, + cartHasCalculatedShipping: previewCart.has_calculated_shipping, + paymentRequirements: previewCart.paymentRequirements, + receiveCart: + typeof previewCart?.receiveCart === 'function' + ? previewCart.receiveCart + : () => undefined, + }; + canPayArgument = { + cart: cartForCanPayArgument, + cartTotals: cartForCanPayArgument.totals, + cartNeedsShipping: cartForCanPayArgument.needsShipping, + billingData: cartForCanPayArgument.billingAddress, + billingAddress: cartForCanPayArgument.billingAddress, + shippingAddress: cartForCanPayArgument.shippingAddress, + selectedShippingMethods: deriveSelectedShippingRates( + cartForCanPayArgument.shippingRates + ), + paymentRequirements: cartForCanPayArgument.paymentRequirements, + }; + } let paymentMethodsOrder; if ( express ) { diff --git a/assets/js/data/payment/test/selectors.js b/assets/js/data/payment/test/selectors.js index 23a1e2e231c..ceaf7089b7d 100644 --- a/assets/js/data/payment/test/selectors.js +++ b/assets/js/data/payment/test/selectors.js @@ -24,7 +24,6 @@ import { CheckoutExpressPayment, SavedPaymentMethodOptions, } from '../../../blocks/cart-checkout-shared/payment-methods'; -import { checkPaymentMethodsCanPay } from '../check-payment-methods'; import { defaultCartState } from '../../cart/default-state'; const originalSelect = jest.requireActual( '@wordpress/data' ).select; @@ -132,8 +131,9 @@ const registerMockPaymentMethods = ( savedCards = true ) => { }, } ); } ); - checkPaymentMethodsCanPay(); - checkPaymentMethodsCanPay( true ); + wpDataFunctions + .dispatch( PAYMENT_STORE_KEY ) + .__internalUpdateAvailablePaymentMethods(); }; const resetMockPaymentMethods = () => { From c6025fcfb5ec229bed0de84fcba9b38fac87a564 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 20 Oct 2022 16:43:01 +0100 Subject: [PATCH 14/18] Updated readme.txt --- readme.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 2850428c6be..014c8ef4734 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks Requires at least: 6.0 Tested up to: 6.0 Requires PHP: 7.0 -Stable tag: 8.7.2 +Stable tag: 8.7.3 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -80,6 +80,11 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ == Changelog == += 8.7.3 - 2022-10-20 = + +#### Bug fixes +- Fixed an issue where the argument passed to `canMakePayment` contained the incorrect keys. Also fixed the current user's customer data appearing in the editor when editing the Checkout block. + = 8.7.2 - 2022-10-13 = #### Bug Fixes From 8a0dcdb1622cd966c85f52b6f69ab9beae9a0ff5 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 20 Oct 2022 16:44:06 +0100 Subject: [PATCH 15/18] Reverted stable tag change on readme.txt --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 014c8ef4734..4c1f7e01bab 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks Requires at least: 6.0 Tested up to: 6.0 Requires PHP: 7.0 -Stable tag: 8.7.3 +Stable tag: 8.7.2 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html From 31f94c6a3d4a2b961dd030cd24239b63a3cfdc74 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 20 Oct 2022 16:53:10 +0100 Subject: [PATCH 16/18] Testing instructions --- .../testing/releases/873.md | 88 +++++++++++++++++++ .../testing/releases/README.md | 1 + 2 files changed, 89 insertions(+) create mode 100644 docs/internal-developers/testing/releases/873.md diff --git a/docs/internal-developers/testing/releases/873.md b/docs/internal-developers/testing/releases/873.md new file mode 100644 index 00000000000..9beb9f1fe80 --- /dev/null +++ b/docs/internal-developers/testing/releases/873.md @@ -0,0 +1,88 @@ +# Testing notes and ZIP for release 8.7.3 + +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/9831749/woocommerce-gutenberg-products-block.zip) + +## Feature plugin and package inclusion in WooCommerce + +### Fix wrong keys being sent in canMakePayment and customer data showing in the Checkout block in the editor ([7434](https://github.com/woocommerce/woocommerce-blocks/pull/7434)) + +#### User Facing Testing + +1. Ensure you can check out using Stripe. Please also try various other payment gateways. +2. If you can, please check out with an express payment method. +3. Open the Checkout block in the editor. Ensure your customer details are not there. +4. Upload this extension [extension-for-testing.zip](https://github.com/woocommerce/woocommerce-blocks/files/9828874/extension-for-testing.zip) to your site and activate it. Ensure you see a payment method called `some-extension-name payment method` on your checkout. (see the notes below for explanation of this testing step!) + +##### 📔 Note + +The extension used in step 4 of the testing registers a payment method and contains the following code in the `canMakePayment` argument: + +```js +canMakePayment: (args) => { + const requiredKeys = [ + 'billingData', + 'billingAddress', + 'cart', + 'cartNeedsShipping', + 'cartTotals', + 'paymentRequirements', + 'selectedShippingMethods', + 'shippingAddress', + ]; + const argKeys = Object.keys(args); + + const requiredCartKeys = [ + 'cartCoupons', + 'cartItems', + 'crossSellsProducts', + 'cartFees', + 'cartItemsCount', + 'cartItemsWeight', + 'cartNeedsPayment', + 'cartNeedsShipping', + 'cartItemErrors', + 'cartTotals', + 'cartIsLoading', + 'cartErrors', + 'billingData', + 'billingAddress', + 'shippingAddress', + 'extensions', + 'shippingRates', + 'isLoadingRates', + 'cartHasCalculatedShipping', + 'paymentRequirements', + 'receiveCart', + ]; + const cartKeys = Object.keys(args.cart); + const requiredTotalsKeys = [ + 'total_items', + 'total_items_tax', + 'total_fees', + 'total_fees_tax', + 'total_discount', + 'total_discount_tax', + 'total_shipping', + 'total_shipping_tax', + 'total_price', + 'total_tax', + 'tax_lines', + 'currency_code', + 'currency_symbol', + 'currency_minor_unit', + 'currency_decimal_separator', + 'currency_thousand_separator', + 'currency_prefix', + 'currency_suffix', + ]; + const totalsKeys = Object.keys(args.cartTotals); + return ( + requiredKeys.every((key) => argKeys.includes(key)) && + requiredTotalsKeys.every((key) => totalsKeys.includes(key)) && + requiredCartKeys.every((key) => cartKeys.includes(key)) + ); + } +``` + +The test here is that all the expected keys are on the argument passed to `canMakePayment`. Testing this on release 8.6.0 should still have this method show up, but it will not show on 8.7.0 where this bug is present. + diff --git a/docs/internal-developers/testing/releases/README.md b/docs/internal-developers/testing/releases/README.md index a284009be12..9bb96e4b723 100644 --- a/docs/internal-developers/testing/releases/README.md +++ b/docs/internal-developers/testing/releases/README.md @@ -94,6 +94,7 @@ Every release includes specific testing instructions for new features and bug fi - [8.7.0](./870.md) - [8.7.1](./871.md) - [8.7.2](./872.md) + - [8.7.3](./873.md) From 35db00bd6b570c48989036b7523c1a155fd0260f Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 20 Oct 2022 16:57:17 +0100 Subject: [PATCH 17/18] Cleaned out testing instructions --- .../testing/releases/873.md | 76 +------------------ 1 file changed, 1 insertion(+), 75 deletions(-) diff --git a/docs/internal-developers/testing/releases/873.md b/docs/internal-developers/testing/releases/873.md index 9beb9f1fe80..ede5b310030 100644 --- a/docs/internal-developers/testing/releases/873.md +++ b/docs/internal-developers/testing/releases/873.md @@ -11,78 +11,4 @@ Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github. 1. Ensure you can check out using Stripe. Please also try various other payment gateways. 2. If you can, please check out with an express payment method. 3. Open the Checkout block in the editor. Ensure your customer details are not there. -4. Upload this extension [extension-for-testing.zip](https://github.com/woocommerce/woocommerce-blocks/files/9828874/extension-for-testing.zip) to your site and activate it. Ensure you see a payment method called `some-extension-name payment method` on your checkout. (see the notes below for explanation of this testing step!) - -##### 📔 Note - -The extension used in step 4 of the testing registers a payment method and contains the following code in the `canMakePayment` argument: - -```js -canMakePayment: (args) => { - const requiredKeys = [ - 'billingData', - 'billingAddress', - 'cart', - 'cartNeedsShipping', - 'cartTotals', - 'paymentRequirements', - 'selectedShippingMethods', - 'shippingAddress', - ]; - const argKeys = Object.keys(args); - - const requiredCartKeys = [ - 'cartCoupons', - 'cartItems', - 'crossSellsProducts', - 'cartFees', - 'cartItemsCount', - 'cartItemsWeight', - 'cartNeedsPayment', - 'cartNeedsShipping', - 'cartItemErrors', - 'cartTotals', - 'cartIsLoading', - 'cartErrors', - 'billingData', - 'billingAddress', - 'shippingAddress', - 'extensions', - 'shippingRates', - 'isLoadingRates', - 'cartHasCalculatedShipping', - 'paymentRequirements', - 'receiveCart', - ]; - const cartKeys = Object.keys(args.cart); - const requiredTotalsKeys = [ - 'total_items', - 'total_items_tax', - 'total_fees', - 'total_fees_tax', - 'total_discount', - 'total_discount_tax', - 'total_shipping', - 'total_shipping_tax', - 'total_price', - 'total_tax', - 'tax_lines', - 'currency_code', - 'currency_symbol', - 'currency_minor_unit', - 'currency_decimal_separator', - 'currency_thousand_separator', - 'currency_prefix', - 'currency_suffix', - ]; - const totalsKeys = Object.keys(args.cartTotals); - return ( - requiredKeys.every((key) => argKeys.includes(key)) && - requiredTotalsKeys.every((key) => totalsKeys.includes(key)) && - requiredCartKeys.every((key) => cartKeys.includes(key)) - ); - } -``` - -The test here is that all the expected keys are on the argument passed to `canMakePayment`. Testing this on release 8.6.0 should still have this method show up, but it will not show on 8.7.0 where this bug is present. - +4. Upload this extension [extension-for-testing.zip](https://github.com/woocommerce/woocommerce-blocks/files/9828874/extension-for-testing.zip) to your site and activate it. Ensure you see a payment method called `some-extension-name payment method` on your checkout. From f475a624fa0cd057e955581df2028930808f15d8 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Thu, 20 Oct 2022 18:09:03 +0100 Subject: [PATCH 18/18] Bumping version strings to new version. --- package.json | 2 +- readme.txt | 2 +- src/Package.php | 2 +- woocommerce-gutenberg-products-block.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e49878a5574..c7b3cdd7da8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@woocommerce/block-library", "title": "WooCommerce Blocks", "author": "Automattic", - "version": "8.7.2", + "version": "8.7.3", "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/", "keywords": [ diff --git a/readme.txt b/readme.txt index 4c1f7e01bab..014c8ef4734 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks Requires at least: 6.0 Tested up to: 6.0 Requires PHP: 7.0 -Stable tag: 8.7.2 +Stable tag: 8.7.3 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/src/Package.php b/src/Package.php index 7908c4049ca..597f82fd298 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 = '8.7.2'; + $version = '8.7.3'; return new NewPackage( $version, dirname( __DIR__ ), diff --git a/woocommerce-gutenberg-products-block.php b/woocommerce-gutenberg-products-block.php index 40d7321175d..0425713115b 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: 8.7.2 + * Version: 8.7.3 * Author: Automattic * Author URI: https://woocommerce.com * Text Domain: woo-gutenberg-products-block