From 89a2bc1e0cf6e3dd94cd17ada637e605291abeb5 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Fri, 22 Jul 2022 12:28:52 +0100 Subject: [PATCH 01/22] Try registering the "cart taxes" inner block Registering server side. This example isn't working, but I'm pushing to share it and see what's wrong with this implementation. --- src/BlockTypes/CartOrderSummaryTaxesBlock.php | 42 +++++++++++++++++++ src/BlockTypesController.php | 1 + 2 files changed, 43 insertions(+) create mode 100644 src/BlockTypes/CartOrderSummaryTaxesBlock.php diff --git a/src/BlockTypes/CartOrderSummaryTaxesBlock.php b/src/BlockTypes/CartOrderSummaryTaxesBlock.php new file mode 100644 index 00000000000..38d7b9ffc04 --- /dev/null +++ b/src/BlockTypes/CartOrderSummaryTaxesBlock.php @@ -0,0 +1,42 @@ +get_chunks_paths( $this->chunks_folder ); + $this->register_chunk_translations( array_merge( $chunks ) ); + } +} diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php index d744046c940..43fd053c7a1 100644 --- a/src/BlockTypesController.php +++ b/src/BlockTypesController.php @@ -201,6 +201,7 @@ protected function get_block_types() { if ( Package::feature()->is_feature_plugin_build() ) { $block_types[] = 'Checkout'; $block_types[] = 'Cart'; + $block_types[] = 'CartOrderSummaryTaxesBlock'; } if ( Package::feature()->is_experimental_build() ) { From 713b83564c6a86d33fb590e0181d89e008184d37 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Fri, 22 Jul 2022 19:47:04 +0100 Subject: [PATCH 02/22] Fix registering the cart taxes inner block issue --- .../cart-order-summary-taxes/index.tsx | 20 +++++++++++++++++-- bin/webpack-entries.js | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx index 72010b2cccc..afca96306f2 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx @@ -1,6 +1,7 @@ /** * External dependencies */ +import { __ } from '@wordpress/i18n'; import { totals } from '@woocommerce/icons'; import { Icon } from '@wordpress/icons'; import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; @@ -12,7 +13,9 @@ import { Edit, Save } from './edit'; import attributes from './attributes'; import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { +registerFeaturePluginBlockType( 'woocommerce/cart-order-summary-taxes-block', { + // When a block is registered server side, we should add the block metadata in the settings. + ...metadata, icon: { src: ( ), }, - attributes, + attributes: { + ...metadata.attributes, + ...attributes, + }, + title: __( 'Taxes', 'woo-gutenberg-products-block' ), + description: __( + 'Shows the cart taxes row.', + 'woo-gutenberg-products-block' + ), + // description: _x( + // 'Shows the cart taxes row.', + // 'block description', + // 'woo-gutenberg-products-block' + // ), edit: Edit, save: Save, } ); diff --git a/bin/webpack-entries.js b/bin/webpack-entries.js index b6e9d239f15..ea42c1abc44 100644 --- a/bin/webpack-entries.js +++ b/bin/webpack-entries.js @@ -45,6 +45,9 @@ const blocks = { 'stock-filter': {}, 'active-filters': {}, cart: {}, + 'cart-order-summary-taxes-block': { + customDir: 'cart/inner-blocks/cart-order-summary-taxes', + }, checkout: {}, 'mini-cart': {}, 'mini-cart-contents': { From 21ffbd9bd710321291f27567a5503dd7ce71a479 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Fri, 22 Jul 2022 19:48:19 +0100 Subject: [PATCH 03/22] Update translation script loading --- src/BlockTypes/CartOrderSummaryTaxesBlock.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/BlockTypes/CartOrderSummaryTaxesBlock.php b/src/BlockTypes/CartOrderSummaryTaxesBlock.php index 38d7b9ffc04..d581c51c153 100644 --- a/src/BlockTypes/CartOrderSummaryTaxesBlock.php +++ b/src/BlockTypes/CartOrderSummaryTaxesBlock.php @@ -3,11 +3,8 @@ /** * CartOrderSummaryTaxesBlock class. - * - * @internal */ class CartOrderSummaryTaxesBlock extends AbstractBlock { - /** * Block name. * @@ -15,13 +12,6 @@ class CartOrderSummaryTaxesBlock extends AbstractBlock { */ protected $block_name = 'cart-order-summary-taxes-block'; - /** - * Chunks build folder. - * - * @var string - */ - protected $chunks_folder = 'checkout-order-summary-taxes'; - /** * API version name. * @@ -36,7 +26,6 @@ class CartOrderSummaryTaxesBlock extends AbstractBlock { */ protected function register_block_type_assets() { parent::register_block_type_assets(); - $chunks = $this->get_chunks_paths( $this->chunks_folder ); - $this->register_chunk_translations( array_merge( $chunks ) ); + $this->register_chunk_translations( [ $this->block_name ] ); } } From 18648cee038fd2c6cc5c1474d4dd580ced3aa6f8 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Mon, 25 Jul 2022 15:56:17 +0100 Subject: [PATCH 04/22] Remove unnecessary JS translation The translation should work fine by getting the title & description from the `block.json` file --- .../inner-blocks/cart-order-summary-taxes/index.tsx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx index afca96306f2..290ffeca084 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx @@ -1,7 +1,6 @@ /** * External dependencies */ -import { __ } from '@wordpress/i18n'; import { totals } from '@woocommerce/icons'; import { Icon } from '@wordpress/icons'; import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; @@ -28,16 +27,6 @@ registerFeaturePluginBlockType( 'woocommerce/cart-order-summary-taxes-block', { ...metadata.attributes, ...attributes, }, - title: __( 'Taxes', 'woo-gutenberg-products-block' ), - description: __( - 'Shows the cart taxes row.', - 'woo-gutenberg-products-block' - ), - // description: _x( - // 'Shows the cart taxes row.', - // 'block description', - // 'woo-gutenberg-products-block' - // ), edit: Edit, save: Save, } ); From 06cebc463e7ad586b556bfd038a0c29361f074f6 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Thu, 28 Jul 2022 13:34:44 +0100 Subject: [PATCH 05/22] Put back the initial code in the 'Cart Taxes' inner block We didn't provide the correct `block.json` file path server side, that's why the `metadata` wasn't correctly registered --- .../cart/inner-blocks/cart-order-summary-taxes/index.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx index 290ffeca084..72010b2cccc 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx @@ -12,9 +12,7 @@ import { Edit, Save } from './edit'; import attributes from './attributes'; import metadata from './block.json'; -registerFeaturePluginBlockType( 'woocommerce/cart-order-summary-taxes-block', { - // When a block is registered server side, we should add the block metadata in the settings. - ...metadata, +registerFeaturePluginBlockType( metadata, { icon: { src: ( ), }, - attributes: { - ...metadata.attributes, - ...attributes, - }, + attributes, edit: Edit, save: Save, } ); From 18e3a9820fdd0e935fccadeeb575a1c6701bdb24 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Thu, 28 Jul 2022 13:39:42 +0100 Subject: [PATCH 06/22] Generate `block.json`files for inner blocks This is the first step on fixing the missing translations of `metadata` in `block.json` files --- bin/webpack-configs.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/webpack-configs.js b/bin/webpack-configs.js index b2e8374333d..72ff859f032 100644 --- a/bin/webpack-configs.js +++ b/bin/webpack-configs.js @@ -267,9 +267,6 @@ const getMainConfig = ( options = {} ) => { .at( -2 ); return `./${ blockName }/block.json`; }, - globOptions: { - ignore: [ '**/inner-blocks/**' ], - }, }, ], } ), From 310dd42e872a4a490d6ee48d44255bd12ae7fe01 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Thu, 28 Jul 2022 13:53:36 +0100 Subject: [PATCH 07/22] Set the folder name exactly the same as the inner block name We are doing this first test for the `Cart taxes` inner block. The `Block` & its containing folder need to have the same name for: - Consistency - We use the `Block` name to get the file Path --- .../attributes.tsx | 0 .../block.json | 0 .../block.tsx | 0 .../edit.tsx | 0 .../frontend.tsx | 0 .../index.tsx | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes => cart-order-summary-taxes-block}/attributes.tsx (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes => cart-order-summary-taxes-block}/block.json (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes => cart-order-summary-taxes-block}/block.tsx (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes => cart-order-summary-taxes-block}/edit.tsx (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes => cart-order-summary-taxes-block}/frontend.tsx (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes => cart-order-summary-taxes-block}/index.tsx (100%) diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/attributes.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/attributes.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/attributes.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/attributes.tsx diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/block.json similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/block.json diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/block.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/block.tsx diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/edit.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/edit.tsx diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/frontend.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/frontend.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/frontend.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/frontend.tsx diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/index.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/index.tsx From a24deee2e147d0bcbcbf93d0a02ae93bf008a813 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Thu, 28 Jul 2022 13:54:23 +0100 Subject: [PATCH 08/22] Update imports after folder renaming --- assets/js/blocks/cart/inner-blocks/component-metadata.ts | 2 +- assets/js/blocks/cart/inner-blocks/index.tsx | 2 +- assets/js/blocks/cart/inner-blocks/register-components.ts | 2 +- assets/js/blocks/cart/test/block.js | 2 +- bin/webpack-entries.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/js/blocks/cart/inner-blocks/component-metadata.ts b/assets/js/blocks/cart/inner-blocks/component-metadata.ts index cf979e31355..60ab72dc7d7 100644 --- a/assets/js/blocks/cart/inner-blocks/component-metadata.ts +++ b/assets/js/blocks/cart/inner-blocks/component-metadata.ts @@ -15,7 +15,7 @@ import CART_ORDER_SUMMARY_FEE from './cart-order-summary-fee/block.json'; import CART_ORDER_SUMMARY_DISCOUNT from './cart-order-summary-discount/block.json'; import CART_ORDER_SUMMARY_SHIPPING from './cart-order-summary-shipping/block.json'; import CART_ORDER_SUMMARY_COUPON_FORM from './cart-order-summary-coupon-form/block.json'; -import CART_ORDER_SUMMARY_TAXES from './cart-order-summary-taxes/block.json'; +import CART_ORDER_SUMMARY_TAXES from './cart-order-summary-taxes-block/block.json'; import CART_ORDER_SUMMARY_HEADING from './cart-order-summary-heading/block.json'; export default { diff --git a/assets/js/blocks/cart/inner-blocks/index.tsx b/assets/js/blocks/cart/inner-blocks/index.tsx index 003f6f54634..2acdf52e829 100644 --- a/assets/js/blocks/cart/inner-blocks/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/index.tsx @@ -15,5 +15,5 @@ import './cart-order-summary-fee'; import './cart-order-summary-discount'; import './cart-order-summary-shipping'; import './cart-order-summary-coupon-form'; -import './cart-order-summary-taxes'; +import './cart-order-summary-taxes-block'; import './cart-order-summary-heading'; diff --git a/assets/js/blocks/cart/inner-blocks/register-components.ts b/assets/js/blocks/cart/inner-blocks/register-components.ts index bf4ac082f28..6151e0894f2 100644 --- a/assets/js/blocks/cart/inner-blocks/register-components.ts +++ b/assets/js/blocks/cart/inner-blocks/register-components.ts @@ -185,7 +185,7 @@ registerCheckoutBlock( { () => import( /* webpackChunkName: "cart-blocks/order-summary-taxes" */ - './cart-order-summary-taxes/frontend' + './cart-order-summary-taxes-block/frontend' ) ), } ); diff --git a/assets/js/blocks/cart/test/block.js b/assets/js/blocks/cart/test/block.js index 17f94e2ea7d..82d96ab079e 100644 --- a/assets/js/blocks/cart/test/block.js +++ b/assets/js/blocks/cart/test/block.js @@ -28,7 +28,7 @@ import AcceptedPaymentMethodsIcons from '../inner-blocks/cart-accepted-payment-m import OrderSummaryHeadingBlock from '../inner-blocks/cart-order-summary-heading/frontend'; import OrderSummarySubtotalBlock from '../inner-blocks/cart-order-summary-subtotal/frontend'; import OrderSummaryShippingBlock from '../inner-blocks/cart-order-summary-shipping/frontend'; -import OrderSummaryTaxesBlock from '../inner-blocks/cart-order-summary-taxes/frontend'; +import OrderSummaryTaxesBlock from '../inner-blocks/cart-order-summary-taxes-block/frontend'; const CartBlock = ( { attributes = { diff --git a/bin/webpack-entries.js b/bin/webpack-entries.js index ea42c1abc44..b3565333491 100644 --- a/bin/webpack-entries.js +++ b/bin/webpack-entries.js @@ -46,7 +46,7 @@ const blocks = { 'active-filters': {}, cart: {}, 'cart-order-summary-taxes-block': { - customDir: 'cart/inner-blocks/cart-order-summary-taxes', + customDir: 'cart/inner-blocks/cart-order-summary-taxes-block', }, checkout: {}, 'mini-cart': {}, From 49e207baee3d9e5d0101bccc32168f47ef1fb1b3 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Thu, 28 Jul 2022 15:46:03 +0100 Subject: [PATCH 09/22] Get block name directly from the JSON metadata Getting the block name from the JSON metadata is less error prone than extracting it from the file path. And no need to rename all our `inner-blocks` to get the correct `block.json` path --- bin/webpack-configs.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/webpack-configs.js b/bin/webpack-configs.js index 72ff859f032..9f16254afa7 100644 --- a/bin/webpack-configs.js +++ b/bin/webpack-configs.js @@ -2,6 +2,7 @@ * External dependencies */ const path = require( 'path' ); +const fs = require( 'fs' ); const { kebabCase } = require( 'lodash' ); const RemoveFilesPlugin = require( './remove-files-webpack-plugin' ); const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' ); @@ -262,9 +263,17 @@ const getMainConfig = ( options = {} ) => { { from: './assets/js/blocks/**/block.json', to( { absoluteFilename } ) { - const blockName = absoluteFilename + /** + * Getting the block name from the JSON metadata is less error prone + * than extracting it from the file path. + */ + const JSONFile = fs.readFileSync( + path.resolve( __dirname, absoluteFilename ) + ); + const metadata = JSON.parse( JSONFile.toString() ); + const blockName = metadata.name .split( '/' ) - .at( -2 ); + .at( 1 ); return `./${ blockName }/block.json`; }, }, From b0101b0aab0c8063406cdd319d6b7939c9bcfb5c Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Thu, 28 Jul 2022 18:18:55 +0100 Subject: [PATCH 10/22] Revert folder naming change of `Cart taxes` inner block Since we are getting the `block` name directly from the `block.json` metadata instead of extracting it from the file path, there is no need to keep their names in sync anymore --- .../attributes.tsx | 0 .../block.json | 0 .../block.tsx | 0 .../edit.tsx | 0 .../frontend.tsx | 0 .../index.tsx | 0 assets/js/blocks/cart/inner-blocks/component-metadata.ts | 2 +- assets/js/blocks/cart/inner-blocks/index.tsx | 2 +- assets/js/blocks/cart/inner-blocks/register-components.ts | 2 +- assets/js/blocks/cart/test/block.js | 2 +- bin/webpack-entries.js | 2 +- 11 files changed, 5 insertions(+), 5 deletions(-) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes-block => cart-order-summary-taxes}/attributes.tsx (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes-block => cart-order-summary-taxes}/block.json (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes-block => cart-order-summary-taxes}/block.tsx (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes-block => cart-order-summary-taxes}/edit.tsx (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes-block => cart-order-summary-taxes}/frontend.tsx (100%) rename assets/js/blocks/cart/inner-blocks/{cart-order-summary-taxes-block => cart-order-summary-taxes}/index.tsx (100%) diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/attributes.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/attributes.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/attributes.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/attributes.tsx diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/block.json b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/block.json rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/block.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/block.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.tsx diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/edit.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/edit.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/frontend.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/frontend.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/frontend.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/frontend.tsx diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx similarity index 100% rename from assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes-block/index.tsx rename to assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx diff --git a/assets/js/blocks/cart/inner-blocks/component-metadata.ts b/assets/js/blocks/cart/inner-blocks/component-metadata.ts index 60ab72dc7d7..cf979e31355 100644 --- a/assets/js/blocks/cart/inner-blocks/component-metadata.ts +++ b/assets/js/blocks/cart/inner-blocks/component-metadata.ts @@ -15,7 +15,7 @@ import CART_ORDER_SUMMARY_FEE from './cart-order-summary-fee/block.json'; import CART_ORDER_SUMMARY_DISCOUNT from './cart-order-summary-discount/block.json'; import CART_ORDER_SUMMARY_SHIPPING from './cart-order-summary-shipping/block.json'; import CART_ORDER_SUMMARY_COUPON_FORM from './cart-order-summary-coupon-form/block.json'; -import CART_ORDER_SUMMARY_TAXES from './cart-order-summary-taxes-block/block.json'; +import CART_ORDER_SUMMARY_TAXES from './cart-order-summary-taxes/block.json'; import CART_ORDER_SUMMARY_HEADING from './cart-order-summary-heading/block.json'; export default { diff --git a/assets/js/blocks/cart/inner-blocks/index.tsx b/assets/js/blocks/cart/inner-blocks/index.tsx index 2acdf52e829..003f6f54634 100644 --- a/assets/js/blocks/cart/inner-blocks/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/index.tsx @@ -15,5 +15,5 @@ import './cart-order-summary-fee'; import './cart-order-summary-discount'; import './cart-order-summary-shipping'; import './cart-order-summary-coupon-form'; -import './cart-order-summary-taxes-block'; +import './cart-order-summary-taxes'; import './cart-order-summary-heading'; diff --git a/assets/js/blocks/cart/inner-blocks/register-components.ts b/assets/js/blocks/cart/inner-blocks/register-components.ts index 6151e0894f2..bf4ac082f28 100644 --- a/assets/js/blocks/cart/inner-blocks/register-components.ts +++ b/assets/js/blocks/cart/inner-blocks/register-components.ts @@ -185,7 +185,7 @@ registerCheckoutBlock( { () => import( /* webpackChunkName: "cart-blocks/order-summary-taxes" */ - './cart-order-summary-taxes-block/frontend' + './cart-order-summary-taxes/frontend' ) ), } ); diff --git a/assets/js/blocks/cart/test/block.js b/assets/js/blocks/cart/test/block.js index 82d96ab079e..17f94e2ea7d 100644 --- a/assets/js/blocks/cart/test/block.js +++ b/assets/js/blocks/cart/test/block.js @@ -28,7 +28,7 @@ import AcceptedPaymentMethodsIcons from '../inner-blocks/cart-accepted-payment-m import OrderSummaryHeadingBlock from '../inner-blocks/cart-order-summary-heading/frontend'; import OrderSummarySubtotalBlock from '../inner-blocks/cart-order-summary-subtotal/frontend'; import OrderSummaryShippingBlock from '../inner-blocks/cart-order-summary-shipping/frontend'; -import OrderSummaryTaxesBlock from '../inner-blocks/cart-order-summary-taxes-block/frontend'; +import OrderSummaryTaxesBlock from '../inner-blocks/cart-order-summary-taxes/frontend'; const CartBlock = ( { attributes = { diff --git a/bin/webpack-entries.js b/bin/webpack-entries.js index b3565333491..ea42c1abc44 100644 --- a/bin/webpack-entries.js +++ b/bin/webpack-entries.js @@ -46,7 +46,7 @@ const blocks = { 'active-filters': {}, cart: {}, 'cart-order-summary-taxes-block': { - customDir: 'cart/inner-blocks/cart-order-summary-taxes-block', + customDir: 'cart/inner-blocks/cart-order-summary-taxes', }, checkout: {}, 'mini-cart': {}, From 477896a78965217abfb082fb942e7d140ed38be3 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Thu, 28 Jul 2022 23:52:29 +0100 Subject: [PATCH 11/22] Fix missing translations for the `Cart Subtotal` Block --- src/BlockTypes/CartOrderSummarySubtotalBlock.php | 14 ++++++++++++++ src/BlockTypesController.php | 1 + 2 files changed, 15 insertions(+) create mode 100644 src/BlockTypes/CartOrderSummarySubtotalBlock.php diff --git a/src/BlockTypes/CartOrderSummarySubtotalBlock.php b/src/BlockTypes/CartOrderSummarySubtotalBlock.php new file mode 100644 index 00000000000..6de6f44734e --- /dev/null +++ b/src/BlockTypes/CartOrderSummarySubtotalBlock.php @@ -0,0 +1,14 @@ +is_experimental_build() ) { From f62033f01a5f38dc5bc298cfe76fabc83f087f0b Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Fri, 29 Jul 2022 07:13:16 +0100 Subject: [PATCH 12/22] Register only the client-side settings on the client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the block is registered on the server, you only need to register the client-side settings on the client using the same block’s name. See [docs](https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#javascript-client-side). --- .../cart-order-summary-subtotal/index.tsx | 28 ++++++++++--------- .../cart-order-summary-taxes/index.tsx | 3 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/index.tsx index ce580c46483..1f88b0c559e 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/index.tsx @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/cart-order-summary-subtotal-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx index 72010b2cccc..0ad9966f6dd 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/index.tsx @@ -10,9 +10,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; */ import { Edit, Save } from './edit'; import attributes from './attributes'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { +registerFeaturePluginBlockType( 'woocommerce/cart-order-summary-taxes-block', { icon: { src: ( Date: Fri, 29 Jul 2022 08:43:51 +0100 Subject: [PATCH 13/22] Add schema validation to `block.json` Development is improved by using a defined schema definition file. Supported editors can provide help like tooltips, autocomplete, and schema validation. --- .../cart/inner-blocks/cart-order-summary-subtotal/block.json | 1 + .../blocks/cart/inner-blocks/cart-order-summary-taxes/block.json | 1 + 2 files changed, 2 insertions(+) diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/block.json b/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/block.json index 264fadd033d..aee05b8d5b0 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/block.json +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-subtotal/block.json @@ -26,5 +26,6 @@ }, "parent": [ "woocommerce/cart-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json index 4fa00fc7d32..289675f7405 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/block.json @@ -26,5 +26,6 @@ }, "parent": [ "woocommerce/cart-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } From c5670f6be17c2de2552028dc959bbcb8f4e57055 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Fri, 29 Jul 2022 08:49:11 +0100 Subject: [PATCH 14/22] Use the same `editor_script` as the parent block This prevents WordPress from generating script tags to inexistant inner blocks JS files --- bin/webpack-entries.js | 3 --- .../CartOrderSummarySubtotalBlock.php | 22 +++++++++++++++++++ src/BlockTypes/CartOrderSummaryTaxesBlock.php | 19 ++++++++++------ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/bin/webpack-entries.js b/bin/webpack-entries.js index ea42c1abc44..b6e9d239f15 100644 --- a/bin/webpack-entries.js +++ b/bin/webpack-entries.js @@ -45,9 +45,6 @@ const blocks = { 'stock-filter': {}, 'active-filters': {}, cart: {}, - 'cart-order-summary-taxes-block': { - customDir: 'cart/inner-blocks/cart-order-summary-taxes', - }, checkout: {}, 'mini-cart': {}, 'mini-cart-contents': { diff --git a/src/BlockTypes/CartOrderSummarySubtotalBlock.php b/src/BlockTypes/CartOrderSummarySubtotalBlock.php index 6de6f44734e..f44ac1e9b8e 100644 --- a/src/BlockTypes/CartOrderSummarySubtotalBlock.php +++ b/src/BlockTypes/CartOrderSummarySubtotalBlock.php @@ -11,4 +11,26 @@ class CartOrderSummarySubtotalBlock extends AbstractBlock { * @var string */ protected $block_name = 'cart-order-summary-subtotal-block'; + + /** + * Parent Block name. + * + * @var string + */ + protected $parent_block_name = 'cart'; + + /** + * Get the editor script handle for this block type. + * + * @param string $key Data to get, or default to everything. + * @return array|string; + */ + protected function get_block_type_editor_script( $key = null ) { + $script = [ + 'handle' => 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } } diff --git a/src/BlockTypes/CartOrderSummaryTaxesBlock.php b/src/BlockTypes/CartOrderSummaryTaxesBlock.php index d581c51c153..549c4f02be7 100644 --- a/src/BlockTypes/CartOrderSummaryTaxesBlock.php +++ b/src/BlockTypes/CartOrderSummaryTaxesBlock.php @@ -13,19 +13,24 @@ class CartOrderSummaryTaxesBlock extends AbstractBlock { protected $block_name = 'cart-order-summary-taxes-block'; /** - * API version name. + * Parent Block name. * * @var string */ - protected $api_version = '2'; + protected $parent_block_name = 'cart'; /** - * Register script and style assets for the block type before it is registered. + * Get the editor script handle for this block type. * - * This registers the scripts; it does not enqueue them. + * @param string $key Data to get, or default to everything. + * @return array|string; */ - protected function register_block_type_assets() { - parent::register_block_type_assets(); - $this->register_chunk_translations( [ $this->block_name ] ); + protected function get_block_type_editor_script( $key = null ) { + $script = [ + 'handle' => 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; } } From 83a8b433fe749017f330920db89ab70501426037 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Fri, 29 Jul 2022 09:20:56 +0100 Subject: [PATCH 15/22] Add C&C inner blocks in Cart.php & Checkout.php This is a refactoring to keep the block types controller file less overloaded --- src/BlockTypes/Cart.php | 17 +++++++++++++++++ src/BlockTypes/Checkout.php | 17 +++++++++++++++++ src/BlockTypesController.php | 9 +++------ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/BlockTypes/Cart.php b/src/BlockTypes/Cart.php index 15aad499b34..c3094b4fe87 100644 --- a/src/BlockTypes/Cart.php +++ b/src/BlockTypes/Cart.php @@ -246,4 +246,21 @@ protected function register_block_type_assets() { $this->register_chunk_translations( array_merge( $chunks, $vendor_chunks ) ); } + + /** + * Get list of Cart block & its inner-block types. + * + * @return array; + */ + public static function get_cart_block_types() { + $block_types = []; + + if ( Package::feature()->is_feature_plugin_build() ) { + $block_types[] = 'Cart'; + $block_types[] = 'CartOrderSummaryTaxesBlock'; + $block_types[] = 'CartOrderSummarySubtotalBlock'; + } + + return $block_types; + } } diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php index d8b94f31b05..eec95eae972 100644 --- a/src/BlockTypes/Checkout.php +++ b/src/BlockTypes/Checkout.php @@ -1,6 +1,8 @@ register_chunk_translations( array_merge( $chunks, $vendor_chunks, $shared_chunks ) ); } + + /** + * Get list of Checkout block & its inner-block types. + * + * @return array; + */ + public static function get_checkout_block_types() { + $block_types = []; + + if ( Package::feature()->is_feature_plugin_build() ) { + $block_types[] = 'Checkout'; + } + + return $block_types; + } } diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php index 3a54bcc9f4a..19009e35a10 100644 --- a/src/BlockTypesController.php +++ b/src/BlockTypesController.php @@ -6,6 +6,8 @@ use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry; use Automattic\WooCommerce\Blocks\Assets\Api as AssetApi; use Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry; +use Automattic\WooCommerce\Blocks\BlockTypes\Cart; +use Automattic\WooCommerce\Blocks\BlockTypes\Checkout; /** * BlockTypesController class. @@ -198,12 +200,7 @@ protected function get_block_types() { 'MiniCartContents', ]; - if ( Package::feature()->is_feature_plugin_build() ) { - $block_types[] = 'Checkout'; - $block_types[] = 'Cart'; - $block_types[] = 'CartOrderSummaryTaxesBlock'; - $block_types[] = 'CartOrderSummarySubtotalBlock'; - } + $block_types = array_merge( $block_types, Cart::get_cart_block_types(), Checkout::get_checkout_block_types() ); if ( Package::feature()->is_experimental_build() ) { $block_types[] = 'SingleProduct'; From 7c2aefdcc50be3ae7cefae82770e0a1ddde20ba9 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Fri, 29 Jul 2022 11:42:08 +0100 Subject: [PATCH 16/22] Fix all Cart inner blocks missing translations --- .../block.json | 1 + .../index.tsx | 28 ++++++++------- .../cart-express-payment-block/block.json | 1 + .../cart-express-payment-block/index.tsx | 3 +- .../inner-blocks/cart-items-block/block.json | 1 + .../inner-blocks/cart-items-block/index.tsx | 3 +- .../cart-line-items-block/block.json | 1 + .../cart-line-items-block/index.tsx | 3 +- .../cart-order-summary-block/block.json | 1 + .../cart-order-summary-block/index.tsx | 3 +- .../cart-order-summary-coupon-form/block.json | 1 + .../cart-order-summary-coupon-form/index.tsx | 28 ++++++++------- .../cart-order-summary-discount/block.json | 1 + .../cart-order-summary-discount/index.tsx | 28 ++++++++------- .../cart-order-summary-fee/block.json | 1 + .../cart-order-summary-fee/index.tsx | 3 +- .../cart-order-summary-heading/block.json | 1 + .../cart-order-summary-heading/index.tsx | 28 ++++++++------- .../cart-order-summary-shipping/block.json | 1 + .../cart-order-summary-shipping/index.tsx | 30 ++++++++-------- .../inner-blocks/cart-totals-block/block.json | 1 + .../inner-blocks/cart-totals-block/index.tsx | 3 +- .../inner-blocks/empty-cart-block/block.json | 1 + .../inner-blocks/empty-cart-block/index.tsx | 3 +- .../inner-blocks/filled-cart-block/block.json | 1 + .../inner-blocks/filled-cart-block/index.tsx | 3 +- .../proceed-to-checkout-block/block.json | 1 + .../proceed-to-checkout-block/index.tsx | 3 +- src/BlockTypes/Cart.php | 14 ++++++++ .../CartAcceptedPaymentMethodsBlock.php | 36 +++++++++++++++++++ src/BlockTypes/CartExpressPaymentBlock.php | 36 +++++++++++++++++++ src/BlockTypes/CartItemsBlock.php | 36 +++++++++++++++++++ src/BlockTypes/CartLineItemsBlock.php | 36 +++++++++++++++++++ src/BlockTypes/CartOrderSummaryBlock.php | 36 +++++++++++++++++++ .../CartOrderSummaryCouponFormBlock.php | 36 +++++++++++++++++++ .../CartOrderSummaryDiscountBlock.php | 36 +++++++++++++++++++ src/BlockTypes/CartOrderSummaryFeeBlock.php | 36 +++++++++++++++++++ .../CartOrderSummaryHeadingBlock.php | 36 +++++++++++++++++++ .../CartOrderSummaryShippingBlock.php | 36 +++++++++++++++++++ src/BlockTypes/CartTotalsBlock.php | 36 +++++++++++++++++++ src/BlockTypes/EmptyCartBlock.php | 36 +++++++++++++++++++ src/BlockTypes/FilledCartBlock.php | 36 +++++++++++++++++++ src/BlockTypes/ProceedToCheckoutBlock.php | 36 +++++++++++++++++++ 43 files changed, 617 insertions(+), 84 deletions(-) create mode 100644 src/BlockTypes/CartAcceptedPaymentMethodsBlock.php create mode 100644 src/BlockTypes/CartExpressPaymentBlock.php create mode 100644 src/BlockTypes/CartItemsBlock.php create mode 100644 src/BlockTypes/CartLineItemsBlock.php create mode 100644 src/BlockTypes/CartOrderSummaryBlock.php create mode 100644 src/BlockTypes/CartOrderSummaryCouponFormBlock.php create mode 100644 src/BlockTypes/CartOrderSummaryDiscountBlock.php create mode 100644 src/BlockTypes/CartOrderSummaryFeeBlock.php create mode 100644 src/BlockTypes/CartOrderSummaryHeadingBlock.php create mode 100644 src/BlockTypes/CartOrderSummaryShippingBlock.php create mode 100644 src/BlockTypes/CartTotalsBlock.php create mode 100644 src/BlockTypes/EmptyCartBlock.php create mode 100644 src/BlockTypes/FilledCartBlock.php create mode 100644 src/BlockTypes/ProceedToCheckoutBlock.php diff --git a/assets/js/blocks/cart/inner-blocks/cart-accepted-payment-methods-block/block.json b/assets/js/blocks/cart/inner-blocks/cart-accepted-payment-methods-block/block.json index 6549400fea7..39f3533446f 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-accepted-payment-methods-block/block.json +++ b/assets/js/blocks/cart/inner-blocks/cart-accepted-payment-methods-block/block.json @@ -13,5 +13,6 @@ }, "parent": [ "woocommerce/cart-totals-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/cart/inner-blocks/cart-accepted-payment-methods-block/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-accepted-payment-methods-block/index.tsx index fb892298718..d69772b7ea9 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-accepted-payment-methods-block/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-accepted-payment-methods-block/index.tsx @@ -8,17 +8,19 @@ import { Icon, payment } from '@wordpress/icons'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/cart-accepted-payment-methods-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/block.json b/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/block.json index cf536b5fd8d..f9bfc5cc7dc 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/block.json +++ b/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/block.json @@ -23,5 +23,6 @@ }, "parent": [ "woocommerce/cart-totals-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/index.tsx index e35ae7f5ff3..87bbc0bac7b 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/index.tsx @@ -8,9 +8,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { +registerFeaturePluginBlockType( 'woocommerce/cart-express-payment-block', { icon: { src: ( - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/cart-order-summary-coupon-form-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/block.json b/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/block.json index d407d1aa8f4..cfb3d6c6cb2 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/block.json +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/block.json @@ -26,5 +26,6 @@ }, "parent": [ "woocommerce/cart-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/index.tsx index ce580c46483..34bc4d8d00e 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-discount/index.tsx @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/cart-order-summary-discount-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/block.json b/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/block.json index 42af475387f..27175d16395 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/block.json +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/block.json @@ -26,5 +26,6 @@ }, "parent": [ "woocommerce/cart-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/index.tsx index ce580c46483..a2c81308d84 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-fee/index.tsx @@ -9,9 +9,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { +registerFeaturePluginBlockType( 'woocommerce/cart-order-summary-fee-block', { icon: { src: ( - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/cart-order-summary-heading-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/block.json b/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/block.json index 0cfb01ea522..e6a61cf07c1 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/block.json +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/block.json @@ -22,5 +22,6 @@ }, "parent": [ "woocommerce/cart-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/index.tsx index 72010b2cccc..a347933ee4e 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/index.tsx @@ -10,18 +10,20 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; */ import { Edit, Save } from './edit'; import attributes from './attributes'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - attributes, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/cart-order-summary-shipping-block', + { + icon: { + src: ( + + ), + }, + attributes, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/cart/inner-blocks/cart-totals-block/block.json b/assets/js/blocks/cart/inner-blocks/cart-totals-block/block.json index 234d24ba9a8..80746cb3c4e 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-totals-block/block.json +++ b/assets/js/blocks/cart/inner-blocks/cart-totals-block/block.json @@ -30,5 +30,6 @@ }, "parent": [ "woocommerce/filled-cart-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/cart/inner-blocks/cart-totals-block/index.tsx b/assets/js/blocks/cart/inner-blocks/cart-totals-block/index.tsx index 3d70d65b8a7..f2edd72b721 100644 --- a/assets/js/blocks/cart/inner-blocks/cart-totals-block/index.tsx +++ b/assets/js/blocks/cart/inner-blocks/cart-totals-block/index.tsx @@ -8,9 +8,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { +registerFeaturePluginBlockType( 'woocommerce/cart-totals-block', { icon: { src: ( 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartExpressPaymentBlock.php b/src/BlockTypes/CartExpressPaymentBlock.php new file mode 100644 index 00000000000..89caaa6b6d6 --- /dev/null +++ b/src/BlockTypes/CartExpressPaymentBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartItemsBlock.php b/src/BlockTypes/CartItemsBlock.php new file mode 100644 index 00000000000..167a9c5d2c2 --- /dev/null +++ b/src/BlockTypes/CartItemsBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartLineItemsBlock.php b/src/BlockTypes/CartLineItemsBlock.php new file mode 100644 index 00000000000..990a42e96dc --- /dev/null +++ b/src/BlockTypes/CartLineItemsBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartOrderSummaryBlock.php b/src/BlockTypes/CartOrderSummaryBlock.php new file mode 100644 index 00000000000..8080d713b78 --- /dev/null +++ b/src/BlockTypes/CartOrderSummaryBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartOrderSummaryCouponFormBlock.php b/src/BlockTypes/CartOrderSummaryCouponFormBlock.php new file mode 100644 index 00000000000..93ea98d3c11 --- /dev/null +++ b/src/BlockTypes/CartOrderSummaryCouponFormBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartOrderSummaryDiscountBlock.php b/src/BlockTypes/CartOrderSummaryDiscountBlock.php new file mode 100644 index 00000000000..08e71f1de64 --- /dev/null +++ b/src/BlockTypes/CartOrderSummaryDiscountBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartOrderSummaryFeeBlock.php b/src/BlockTypes/CartOrderSummaryFeeBlock.php new file mode 100644 index 00000000000..1793cda3861 --- /dev/null +++ b/src/BlockTypes/CartOrderSummaryFeeBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartOrderSummaryHeadingBlock.php b/src/BlockTypes/CartOrderSummaryHeadingBlock.php new file mode 100644 index 00000000000..74de0f6a995 --- /dev/null +++ b/src/BlockTypes/CartOrderSummaryHeadingBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartOrderSummaryShippingBlock.php b/src/BlockTypes/CartOrderSummaryShippingBlock.php new file mode 100644 index 00000000000..3b754d95d48 --- /dev/null +++ b/src/BlockTypes/CartOrderSummaryShippingBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/CartTotalsBlock.php b/src/BlockTypes/CartTotalsBlock.php new file mode 100644 index 00000000000..942684d6fe6 --- /dev/null +++ b/src/BlockTypes/CartTotalsBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/EmptyCartBlock.php b/src/BlockTypes/EmptyCartBlock.php new file mode 100644 index 00000000000..92c46543759 --- /dev/null +++ b/src/BlockTypes/EmptyCartBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/FilledCartBlock.php b/src/BlockTypes/FilledCartBlock.php new file mode 100644 index 00000000000..3bdc1f84bfe --- /dev/null +++ b/src/BlockTypes/FilledCartBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} diff --git a/src/BlockTypes/ProceedToCheckoutBlock.php b/src/BlockTypes/ProceedToCheckoutBlock.php new file mode 100644 index 00000000000..9f338dec727 --- /dev/null +++ b/src/BlockTypes/ProceedToCheckoutBlock.php @@ -0,0 +1,36 @@ + 'wc-' . $this->parent_block_name . '-block', + 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), + 'dependencies' => [ 'wc-blocks' ], + ]; + return $key ? $script[ $key ] : $script; + } +} From a9e0d3c697397f13a228c70d39b8424c0e69fa90 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Mon, 1 Aug 2022 12:42:18 +0100 Subject: [PATCH 17/22] Create the "AbstractInnerBlock" class The "Inner Blocks" will use their parent's script, so no need to create new scripts for each one of them And, our "Inner Blocks" should always be registered using the metadata file --- src/BlockTypes/AbstractInnerBlock.php | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/BlockTypes/AbstractInnerBlock.php diff --git a/src/BlockTypes/AbstractInnerBlock.php b/src/BlockTypes/AbstractInnerBlock.php new file mode 100644 index 00000000000..fc92e668e8e --- /dev/null +++ b/src/BlockTypes/AbstractInnerBlock.php @@ -0,0 +1,31 @@ + $this->get_block_type_render_callback(), + 'editor_style' => $this->get_block_type_editor_style(), + 'style' => $this->get_block_type_style(), + ]; + + if ( isset( $this->api_version ) && '2' === $this->api_version ) { + $block_settings['api_version'] = 2; + } + + $metadata_path = $this->asset_api->get_block_metadata_path( $this->block_name ); + // Prefer to register with metadata if the path is set in the block's class. + register_block_type_from_metadata( + $metadata_path, + $block_settings + ); + } +} From 686fe503ff93a8902a86ac3c2b7d41d57ef44fd6 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Mon, 1 Aug 2022 12:43:47 +0100 Subject: [PATCH 18/22] Update the "Inner Blocks" PHP classes --- .../CartAcceptedPaymentMethodsBlock.php | 24 +------------------ src/BlockTypes/CartExpressPaymentBlock.php | 24 +------------------ src/BlockTypes/CartItemsBlock.php | 24 +------------------ src/BlockTypes/CartLineItemsBlock.php | 24 +------------------ src/BlockTypes/CartOrderSummaryBlock.php | 24 +------------------ .../CartOrderSummaryCouponFormBlock.php | 24 +------------------ .../CartOrderSummaryDiscountBlock.php | 24 +------------------ src/BlockTypes/CartOrderSummaryFeeBlock.php | 24 +------------------ .../CartOrderSummaryHeadingBlock.php | 24 +------------------ .../CartOrderSummaryShippingBlock.php | 24 +------------------ .../CartOrderSummarySubtotalBlock.php | 24 +------------------ src/BlockTypes/CartOrderSummaryTaxesBlock.php | 24 +------------------ src/BlockTypes/CartTotalsBlock.php | 24 +------------------ src/BlockTypes/EmptyCartBlock.php | 24 +------------------ src/BlockTypes/FilledCartBlock.php | 24 +------------------ src/BlockTypes/ProceedToCheckoutBlock.php | 24 +------------------ 16 files changed, 16 insertions(+), 368 deletions(-) diff --git a/src/BlockTypes/CartAcceptedPaymentMethodsBlock.php b/src/BlockTypes/CartAcceptedPaymentMethodsBlock.php index f055c211d13..e92e38b678f 100644 --- a/src/BlockTypes/CartAcceptedPaymentMethodsBlock.php +++ b/src/BlockTypes/CartAcceptedPaymentMethodsBlock.php @@ -4,33 +4,11 @@ /** * CartAcceptedPaymentMethodsBlock class. */ -class CartAcceptedPaymentMethodsBlock extends AbstractBlock { +class CartAcceptedPaymentMethodsBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-accepted-payment-methods-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartExpressPaymentBlock.php b/src/BlockTypes/CartExpressPaymentBlock.php index 89caaa6b6d6..d491967c844 100644 --- a/src/BlockTypes/CartExpressPaymentBlock.php +++ b/src/BlockTypes/CartExpressPaymentBlock.php @@ -4,33 +4,11 @@ /** * CartExpressPaymentBlock class. */ -class CartExpressPaymentBlock extends AbstractBlock { +class CartExpressPaymentBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-express-payment-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartItemsBlock.php b/src/BlockTypes/CartItemsBlock.php index 167a9c5d2c2..00902990344 100644 --- a/src/BlockTypes/CartItemsBlock.php +++ b/src/BlockTypes/CartItemsBlock.php @@ -4,33 +4,11 @@ /** * CartItemsBlock class. */ -class CartItemsBlock extends AbstractBlock { +class CartItemsBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-items-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartLineItemsBlock.php b/src/BlockTypes/CartLineItemsBlock.php index 990a42e96dc..c1ff62a15bb 100644 --- a/src/BlockTypes/CartLineItemsBlock.php +++ b/src/BlockTypes/CartLineItemsBlock.php @@ -4,33 +4,11 @@ /** * CartLineItemsBlock class. */ -class CartLineItemsBlock extends AbstractBlock { +class CartLineItemsBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-line-items-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartOrderSummaryBlock.php b/src/BlockTypes/CartOrderSummaryBlock.php index 8080d713b78..48ddf627196 100644 --- a/src/BlockTypes/CartOrderSummaryBlock.php +++ b/src/BlockTypes/CartOrderSummaryBlock.php @@ -4,33 +4,11 @@ /** * CartOrderSummaryBlock class. */ -class CartOrderSummaryBlock extends AbstractBlock { +class CartOrderSummaryBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-order-summary-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartOrderSummaryCouponFormBlock.php b/src/BlockTypes/CartOrderSummaryCouponFormBlock.php index 93ea98d3c11..0a8b5b01f76 100644 --- a/src/BlockTypes/CartOrderSummaryCouponFormBlock.php +++ b/src/BlockTypes/CartOrderSummaryCouponFormBlock.php @@ -4,33 +4,11 @@ /** * CartOrderSummaryCouponFormBlock class. */ -class CartOrderSummaryCouponFormBlock extends AbstractBlock { +class CartOrderSummaryCouponFormBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-order-summary-coupon-form-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartOrderSummaryDiscountBlock.php b/src/BlockTypes/CartOrderSummaryDiscountBlock.php index 08e71f1de64..794863677f0 100644 --- a/src/BlockTypes/CartOrderSummaryDiscountBlock.php +++ b/src/BlockTypes/CartOrderSummaryDiscountBlock.php @@ -4,33 +4,11 @@ /** * CartOrderSummaryDiscountBlock class. */ -class CartOrderSummaryDiscountBlock extends AbstractBlock { +class CartOrderSummaryDiscountBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-order-summary-discount-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartOrderSummaryFeeBlock.php b/src/BlockTypes/CartOrderSummaryFeeBlock.php index 1793cda3861..979446ad298 100644 --- a/src/BlockTypes/CartOrderSummaryFeeBlock.php +++ b/src/BlockTypes/CartOrderSummaryFeeBlock.php @@ -4,33 +4,11 @@ /** * CartOrderSummaryFeeBlock class. */ -class CartOrderSummaryFeeBlock extends AbstractBlock { +class CartOrderSummaryFeeBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-order-summary-fee-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartOrderSummaryHeadingBlock.php b/src/BlockTypes/CartOrderSummaryHeadingBlock.php index 74de0f6a995..3cc5ea2e8db 100644 --- a/src/BlockTypes/CartOrderSummaryHeadingBlock.php +++ b/src/BlockTypes/CartOrderSummaryHeadingBlock.php @@ -4,33 +4,11 @@ /** * CartOrderSummaryHeadingBlock class. */ -class CartOrderSummaryHeadingBlock extends AbstractBlock { +class CartOrderSummaryHeadingBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-order-summary-heading-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartOrderSummaryShippingBlock.php b/src/BlockTypes/CartOrderSummaryShippingBlock.php index 3b754d95d48..5777744062d 100644 --- a/src/BlockTypes/CartOrderSummaryShippingBlock.php +++ b/src/BlockTypes/CartOrderSummaryShippingBlock.php @@ -4,33 +4,11 @@ /** * CartOrderSummaryShippingBlock class. */ -class CartOrderSummaryShippingBlock extends AbstractBlock { +class CartOrderSummaryShippingBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-order-summary-shipping-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartOrderSummarySubtotalBlock.php b/src/BlockTypes/CartOrderSummarySubtotalBlock.php index f44ac1e9b8e..1c9f475c553 100644 --- a/src/BlockTypes/CartOrderSummarySubtotalBlock.php +++ b/src/BlockTypes/CartOrderSummarySubtotalBlock.php @@ -4,33 +4,11 @@ /** * CartOrderSummarySubtotalBlock class. */ -class CartOrderSummarySubtotalBlock extends AbstractBlock { +class CartOrderSummarySubtotalBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-order-summary-subtotal-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartOrderSummaryTaxesBlock.php b/src/BlockTypes/CartOrderSummaryTaxesBlock.php index 549c4f02be7..566c6d4325e 100644 --- a/src/BlockTypes/CartOrderSummaryTaxesBlock.php +++ b/src/BlockTypes/CartOrderSummaryTaxesBlock.php @@ -4,33 +4,11 @@ /** * CartOrderSummaryTaxesBlock class. */ -class CartOrderSummaryTaxesBlock extends AbstractBlock { +class CartOrderSummaryTaxesBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-order-summary-taxes-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/CartTotalsBlock.php b/src/BlockTypes/CartTotalsBlock.php index 942684d6fe6..e5e0204480a 100644 --- a/src/BlockTypes/CartTotalsBlock.php +++ b/src/BlockTypes/CartTotalsBlock.php @@ -4,33 +4,11 @@ /** * CartTotalsBlock class. */ -class CartTotalsBlock extends AbstractBlock { +class CartTotalsBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'cart-totals-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/EmptyCartBlock.php b/src/BlockTypes/EmptyCartBlock.php index 92c46543759..2b3fd6df53f 100644 --- a/src/BlockTypes/EmptyCartBlock.php +++ b/src/BlockTypes/EmptyCartBlock.php @@ -4,33 +4,11 @@ /** * EmptyCartBlock class. */ -class EmptyCartBlock extends AbstractBlock { +class EmptyCartBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'empty-cart-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/FilledCartBlock.php b/src/BlockTypes/FilledCartBlock.php index 3bdc1f84bfe..9991b9b18a7 100644 --- a/src/BlockTypes/FilledCartBlock.php +++ b/src/BlockTypes/FilledCartBlock.php @@ -4,33 +4,11 @@ /** * FilledCartBlock class. */ -class FilledCartBlock extends AbstractBlock { +class FilledCartBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'filled-cart-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } diff --git a/src/BlockTypes/ProceedToCheckoutBlock.php b/src/BlockTypes/ProceedToCheckoutBlock.php index 9f338dec727..5f3f2171537 100644 --- a/src/BlockTypes/ProceedToCheckoutBlock.php +++ b/src/BlockTypes/ProceedToCheckoutBlock.php @@ -4,33 +4,11 @@ /** * ProceedToCheckoutBlock class. */ -class ProceedToCheckoutBlock extends AbstractBlock { +class ProceedToCheckoutBlock extends AbstractInnerBlock { /** * Block name. * * @var string */ protected $block_name = 'proceed-to-checkout-block'; - - /** - * Parent Block name. - * - * @var string - */ - protected $parent_block_name = 'cart'; - - /** - * Get the editor script handle for this block type. - * - * @param string $key Data to get, or default to everything. - * @return array|string; - */ - protected function get_block_type_editor_script( $key = null ) { - $script = [ - 'handle' => 'wc-' . $this->parent_block_name . '-block', - 'path' => $this->asset_api->get_block_asset_build_path( $this->parent_block_name ), - 'dependencies' => [ 'wc-blocks' ], - ]; - return $key ? $script[ $key ] : $script; - } } From 0a9cf4aff0d323ad11acf6753e68a05f59ca02a3 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Mon, 1 Aug 2022 13:07:14 +0100 Subject: [PATCH 19/22] Fix PHP lint erros & update function description --- src/BlockTypes/AbstractInnerBlock.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/BlockTypes/AbstractInnerBlock.php b/src/BlockTypes/AbstractInnerBlock.php index fc92e668e8e..d0ddedf082e 100644 --- a/src/BlockTypes/AbstractInnerBlock.php +++ b/src/BlockTypes/AbstractInnerBlock.php @@ -8,7 +8,8 @@ abstract class AbstractInnerBlock extends AbstractBlock { /** * Registers the block type with WordPress using the metadata file. * - * @return string[] Chunks paths. + * The registration using metadata is now recommended. And it's required for "Inner Blocks" to + * fix the issue of missing translations in the inspector (in the Editor mode) */ protected function register_block_type() { $block_settings = [ From 602ea19f5eba762fd6b30b0c1a9577670d8b9315 Mon Sep 17 00:00:00 2001 From: Saad Tarhi Date: Mon, 1 Aug 2022 14:53:34 +0100 Subject: [PATCH 20/22] Fix missing translations bug for all Checkout Inner Blocks --- .../checkout-actions-block/block.json | 1 + .../checkout-actions-block/index.tsx | 3 +- .../checkout-billing-address-block/block.json | 1 + .../checkout-billing-address-block/index.tsx | 3 +- .../block.json | 1 + .../index.tsx | 30 ++++++++++--------- .../checkout-express-payment-block/block.json | 1 + .../checkout-express-payment-block/index.tsx | 3 +- .../checkout-fields-block/block.json | 1 + .../checkout-fields-block/index.tsx | 3 +- .../checkout-order-note-block/block.json | 1 + .../checkout-order-note-block/index.tsx | 3 +- .../checkout-order-summary-block/block.json | 1 + .../checkout-order-summary-block/index.tsx | 3 +- .../block.json | 1 + .../index.tsx | 28 +++++++++-------- .../block.json | 1 + .../index.tsx | 28 +++++++++-------- .../block.json | 1 + .../checkout-order-summary-discount/index.tsx | 28 +++++++++-------- .../checkout-order-summary-fee/block.json | 1 + .../checkout-order-summary-fee/index.tsx | 28 +++++++++-------- .../block.json | 1 + .../checkout-order-summary-shipping/index.tsx | 28 +++++++++-------- .../block.json | 1 + .../checkout-order-summary-subtotal/index.tsx | 28 +++++++++-------- .../checkout-order-summary-taxes/block.json | 1 + .../checkout-order-summary-taxes/index.tsx | 30 ++++++++++--------- .../checkout-payment-block/block.json | 1 + .../checkout-payment-block/index.tsx | 3 +- .../block.json | 1 + .../checkout-shipping-address-block/index.tsx | 3 +- .../block.json | 1 + .../checkout-shipping-methods-block/index.tsx | 3 +- .../checkout-terms-block/block.json | 1 + .../checkout-terms-block/index.tsx | 3 +- .../checkout-totals-block/block.json | 1 + .../checkout-totals-block/index.tsx | 3 +- src/BlockTypes/Checkout.php | 20 +++++++++++++ src/BlockTypes/CheckoutActionsBlock.php | 14 +++++++++ .../CheckoutBillingAddressBlock.php | 14 +++++++++ .../CheckoutContactInformationBlock.php | 14 +++++++++ .../CheckoutExpressPaymentBlock.php | 14 +++++++++ src/BlockTypes/CheckoutFieldsBlock.php | 14 +++++++++ src/BlockTypes/CheckoutOrderNoteBlock.php | 14 +++++++++ src/BlockTypes/CheckoutOrderSummaryBlock.php | 14 +++++++++ .../CheckoutOrderSummaryCartItemsBlock.php | 14 +++++++++ .../CheckoutOrderSummaryCouponFormBlock.php | 14 +++++++++ .../CheckoutOrderSummaryDiscountBlock.php | 14 +++++++++ .../CheckoutOrderSummaryFeeBlock.php | 14 +++++++++ .../CheckoutOrderSummaryShippingBlock.php | 14 +++++++++ .../CheckoutOrderSummarySubtotalBlock.php | 14 +++++++++ .../CheckoutOrderSummaryTaxesBlock.php | 14 +++++++++ src/BlockTypes/CheckoutPaymentBlock.php | 14 +++++++++ .../CheckoutShippingAddressBlock.php | 14 +++++++++ .../CheckoutShippingMethodsBlock.php | 14 +++++++++ src/BlockTypes/CheckoutTermsBlock.php | 14 +++++++++ src/BlockTypes/CheckoutTotalsBlock.php | 14 +++++++++ 58 files changed, 438 insertions(+), 128 deletions(-) create mode 100644 src/BlockTypes/CheckoutActionsBlock.php create mode 100644 src/BlockTypes/CheckoutBillingAddressBlock.php create mode 100644 src/BlockTypes/CheckoutContactInformationBlock.php create mode 100644 src/BlockTypes/CheckoutExpressPaymentBlock.php create mode 100644 src/BlockTypes/CheckoutFieldsBlock.php create mode 100644 src/BlockTypes/CheckoutOrderNoteBlock.php create mode 100644 src/BlockTypes/CheckoutOrderSummaryBlock.php create mode 100644 src/BlockTypes/CheckoutOrderSummaryCartItemsBlock.php create mode 100644 src/BlockTypes/CheckoutOrderSummaryCouponFormBlock.php create mode 100644 src/BlockTypes/CheckoutOrderSummaryDiscountBlock.php create mode 100644 src/BlockTypes/CheckoutOrderSummaryFeeBlock.php create mode 100644 src/BlockTypes/CheckoutOrderSummaryShippingBlock.php create mode 100644 src/BlockTypes/CheckoutOrderSummarySubtotalBlock.php create mode 100644 src/BlockTypes/CheckoutOrderSummaryTaxesBlock.php create mode 100644 src/BlockTypes/CheckoutPaymentBlock.php create mode 100644 src/BlockTypes/CheckoutShippingAddressBlock.php create mode 100644 src/BlockTypes/CheckoutShippingMethodsBlock.php create mode 100644 src/BlockTypes/CheckoutTermsBlock.php create mode 100644 src/BlockTypes/CheckoutTotalsBlock.php diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/block.json index a110edcc2f2..79ff5324e61 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/block.json @@ -23,5 +23,6 @@ }, "parent": [ "woocommerce/checkout-fields-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/index.tsx index 2d1ab886aea..35742f0adfc 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/index.tsx @@ -9,9 +9,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; */ import attributes from './attributes'; import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { +registerFeaturePluginBlockType( 'woocommerce/checkout-actions-block', { icon: { src: ( - ), - }, - attributes, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/checkout-contact-information-block', + { + icon: { + src: ( + + ), + }, + attributes, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/block.json index 58b9807dd4d..6c14d00aefe 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/block.json @@ -27,5 +27,6 @@ }, "parent": [ "woocommerce/checkout-fields-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/index.tsx index e35ae7f5ff3..8b9e69c4b9d 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/index.tsx @@ -8,9 +8,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { +registerFeaturePluginBlockType( 'woocommerce/checkout-express-payment-block', { icon: { src: ( - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/checkout-order-summary-cart-items-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.json index e02fd415ed3..0aac398caf1 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.json @@ -25,5 +25,6 @@ }, "parent": [ "woocommerce/checkout-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/index.tsx index 5badfa89545..28441776d35 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/index.tsx @@ -8,17 +8,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/checkout-order-summary-coupon-form-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.json index 6807f1ae351..25a304e8e04 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.json @@ -26,5 +26,6 @@ }, "parent": [ "woocommerce/checkout-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/index.tsx index ce580c46483..fb206bd1ee6 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/index.tsx @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/checkout-order-summary-discount-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/block.json index bca03d2d395..9201ac68b5c 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/block.json @@ -26,5 +26,6 @@ }, "parent": [ "woocommerce/checkout-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/index.tsx index ce580c46483..419b02a8e2c 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-fee/index.tsx @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/checkout-order-summary-fee-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-shipping/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-shipping/block.json index f7bfd5a4b97..b9350d81b50 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-shipping/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-shipping/block.json @@ -22,5 +22,6 @@ }, "parent": [ "woocommerce/checkout-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-shipping/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-shipping/index.tsx index ce580c46483..4303d250fbd 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-shipping/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-shipping/index.tsx @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/checkout-order-summary-shipping-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/block.json index 395ded30be5..cc0eaab1ae8 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/block.json @@ -26,5 +26,6 @@ }, "parent": [ "woocommerce/checkout-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/index.tsx index ce580c46483..b20dfefaf4c 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-subtotal/index.tsx @@ -9,17 +9,19 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; * Internal dependencies */ import { Edit, Save } from './edit'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/checkout-order-summary-subtotal-block', + { + icon: { + src: ( + + ), + }, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/block.json index 69f733ceb9f..24658d4ba11 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/block.json @@ -26,5 +26,6 @@ }, "parent": [ "woocommerce/checkout-order-summary-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/index.tsx index 72010b2cccc..a0af3bcf598 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/index.tsx @@ -10,18 +10,20 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; */ import { Edit, Save } from './edit'; import attributes from './attributes'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { - icon: { - src: ( - - ), - }, - attributes, - edit: Edit, - save: Save, -} ); +registerFeaturePluginBlockType( + 'woocommerce/checkout-order-summary-taxes-block', + { + icon: { + src: ( + + ), + }, + attributes, + edit: Edit, + save: Save, + } +); diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/block.json b/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/block.json index 4ed9a01d442..94169b163c8 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/block.json +++ b/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/block.json @@ -23,5 +23,6 @@ }, "parent": [ "woocommerce/checkout-fields-block" ], "textdomain": "woo-gutenberg-products-block", + "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2 } diff --git a/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/index.tsx b/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/index.tsx index 2384e91a1f8..136c00f1b52 100644 --- a/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/index.tsx +++ b/assets/js/blocks/checkout/inner-blocks/checkout-payment-block/index.tsx @@ -9,9 +9,8 @@ import { registerFeaturePluginBlockType } from '@woocommerce/block-settings'; */ import { Edit, Save } from './edit'; import attributes from './attributes'; -import metadata from './block.json'; -registerFeaturePluginBlockType( metadata, { +registerFeaturePluginBlockType( 'woocommerce/checkout-payment-block', { icon: { src: ( is_feature_plugin_build() ) { $block_types[] = 'Checkout'; + $block_types[] = 'Checkout'; + $block_types[] = 'CheckoutActionsBlock'; + $block_types[] = 'CheckoutBillingAddressBlock'; + $block_types[] = 'CheckoutContactInformationBlock'; + $block_types[] = 'CheckoutExpressPaymentBlock'; + $block_types[] = 'CheckoutFieldsBlock'; + $block_types[] = 'CheckoutOrderNoteBlock'; + $block_types[] = 'CheckoutOrderSummaryBlock'; + $block_types[] = 'CheckoutOrderSummaryCartItemsBlock'; + $block_types[] = 'CheckoutOrderSummaryCouponFormBlock'; + $block_types[] = 'CheckoutOrderSummaryDiscountBlock'; + $block_types[] = 'CheckoutOrderSummaryFeeBlock'; + $block_types[] = 'CheckoutOrderSummaryShippingBlock'; + $block_types[] = 'CheckoutOrderSummarySubtotalBlock'; + $block_types[] = 'CheckoutOrderSummaryTaxesBlock'; + $block_types[] = 'CheckoutPaymentBlock'; + $block_types[] = 'CheckoutShippingAddressBlock'; + $block_types[] = 'CheckoutShippingMethodsBlock'; + $block_types[] = 'CheckoutTermsBlock'; + $block_types[] = 'CheckoutTotalsBlock'; } return $block_types; diff --git a/src/BlockTypes/CheckoutActionsBlock.php b/src/BlockTypes/CheckoutActionsBlock.php new file mode 100644 index 00000000000..67e132b8720 --- /dev/null +++ b/src/BlockTypes/CheckoutActionsBlock.php @@ -0,0 +1,14 @@ + Date: Mon, 1 Aug 2022 15:38:26 +0100 Subject: [PATCH 21/22] Update src/BlockTypes/Checkout.php Co-authored-by: Seghir Nadir --- src/BlockTypes/Checkout.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php index 09b9e753473..57778ee0d9b 100644 --- a/src/BlockTypes/Checkout.php +++ b/src/BlockTypes/Checkout.php @@ -423,7 +423,6 @@ public static function get_checkout_block_types() { $block_types = []; if ( Package::feature()->is_feature_plugin_build() ) { - $block_types[] = 'Checkout'; $block_types[] = 'Checkout'; $block_types[] = 'CheckoutActionsBlock'; $block_types[] = 'CheckoutBillingAddressBlock'; From b220e4937665119c139a01f43f0149111c95444b Mon Sep 17 00:00:00 2001 From: Nadir Seghir Date: Mon, 1 Aug 2022 15:51:54 +0100 Subject: [PATCH 22/22] skip lazy loaded scripts --- src/BlockTypes/AbstractInnerBlock.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/BlockTypes/AbstractInnerBlock.php b/src/BlockTypes/AbstractInnerBlock.php index d0ddedf082e..3b992d5f77b 100644 --- a/src/BlockTypes/AbstractInnerBlock.php +++ b/src/BlockTypes/AbstractInnerBlock.php @@ -5,6 +5,14 @@ * AbstractInnerBlock class. */ abstract class AbstractInnerBlock extends AbstractBlock { + + /** + * Is this inner block lazy loaded? this helps us know if we should load its frontend script ot not. + * + * @var boolean + */ + protected $is_lazy_loaded = true; + /** * Registers the block type with WordPress using the metadata file. * @@ -29,4 +37,21 @@ protected function register_block_type() { $block_settings ); } + + /** + * For lazy loaded inner blocks, we don't want to enqueue the script but rather leave it for webpack to do that. + * + * @see $this->register_block_type() + * @param string $key Data to get, or default to everything. + * @return array|string|null + */ + protected function get_block_type_script( $key = null ) { + + if ( $this->is_lazy_loaded ) { + return null; + } + + return parent::get_block_type_script( $key ); + } + }