This commit is contained in:
Albert Juhé Lluveras 2023-03-02 11:16:32 +01:00 committed by GitHub
parent 0c4ad5ec13
commit 4b82793b33
17 changed files with 156 additions and 23 deletions

View File

@ -9,9 +9,11 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
registerBlockType( metadata, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- TypeScript expects some required properties which we already
// registered in PHP.
registerBlockType( 'woocommerce/empty-mini-cart-contents-block', {
icon: {
src: (
<Icon

View File

@ -9,9 +9,11 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
registerBlockType( metadata, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- TypeScript expects some required properties which we already
// registered in PHP.
registerBlockType( 'woocommerce/filled-mini-cart-contents-block', {
icon: {
src: (
<Icon

View File

@ -8,10 +8,12 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
import attributes from './attributes';
registerBlockType( metadata, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- TypeScript expects some required properties which we already
// registered in PHP.
registerBlockType( 'woocommerce/mini-cart-footer-block', {
icon: {
src: (
<Icon

View File

@ -8,9 +8,11 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
registerBlockType( metadata, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- TypeScript expects some required properties which we already
// registered in PHP.
registerBlockType( 'woocommerce/mini-cart-items-block', {
icon: {
src: (
<Icon

View File

@ -8,9 +8,11 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
registerBlockType( metadata, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- TypeScript expects some required properties which we already
// registered in PHP.
registerBlockType( 'woocommerce/mini-cart-products-table-block', {
icon: (
<Icon icon={ list } className="wc-block-editor-components-block-icon" />
),

View File

@ -8,10 +8,12 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
import attributes from './attributes';
registerBlockType( metadata, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- TypeScript expects some required properties which we already
// registered in PHP.
registerBlockType( 'woocommerce/mini-cart-shopping-button-block', {
icon: {
src: (
<Icon

View File

@ -8,9 +8,11 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import metadata from './block.json';
registerBlockType( metadata, {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- TypeScript expects some required properties which we already
// registered in PHP.
registerBlockType( 'woocommerce/mini-cart-title-block', {
icon: {
src: (
<Icon

View File

@ -0,0 +1,14 @@
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
/**
* EmptyMiniCartContentsBlock class.
*/
class EmptyMiniCartContentsBlock extends AbstractInnerBlock {
/**
* Block name.
*
* @var string
*/
protected $block_name = 'empty-mini-cart-contents-block';
}

View File

@ -0,0 +1,14 @@
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
/**
* FilledMiniCartContentsBlock class.
*/
class FilledMiniCartContentsBlock extends AbstractInnerBlock {
/**
* Block name.
*
* @var string
*/
protected $block_name = 'filled-mini-cart-contents-block';
}

View File

@ -363,7 +363,6 @@ class MiniCart extends AbstractBlock {
$cart_controller = $this->get_cart_controller();
$cart = $cart_controller->get_cart_instance();
$cart_contents_count = $cart->get_cart_contents_count();
$cart_contents = $cart->get_cart();
$cart_contents_total = $cart->get_subtotal();
if ( $cart->display_prices_including_tax() ) {

View File

@ -1,10 +1,6 @@
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\Assets;
use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
use Automattic\WooCommerce\StoreApi\Utilities\CartController;
use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
/**
@ -140,4 +136,25 @@ class MiniCartContents extends AbstractBlock {
$parsed_style
);
}
/**
* Get list of Mini Cart block & its inner-block types.
*
* @return array;
*/
public static function get_mini_cart_block_types() {
$block_types = [];
$block_types[] = 'MiniCartContents';
$block_types[] = 'EmptyMiniCartContentsBlock';
$block_types[] = 'FilledMiniCartContentsBlock';
$block_types[] = 'MiniCartFooterBlock';
$block_types[] = 'MiniCartItemsBlock';
$block_types[] = 'MiniCartProductsTableBlock';
$block_types[] = 'MiniCartShoppingButtonBlock';
$block_types[] = 'MiniCartTitleBlock';
return $block_types;
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
/**
* MiniCartFooterBlock class.
*/
class MiniCartFooterBlock extends AbstractInnerBlock {
/**
* Block name.
*
* @var string
*/
protected $block_name = 'mini-cart-footer-block';
}

View File

@ -0,0 +1,14 @@
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
/**
* MiniCartItemsBlock class.
*/
class MiniCartItemsBlock extends AbstractInnerBlock {
/**
* Block name.
*
* @var string
*/
protected $block_name = 'mini-cart-items-block';
}

View File

@ -0,0 +1,14 @@
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
/**
* MiniCartProductsTableBlock class.
*/
class MiniCartProductsTableBlock extends AbstractInnerBlock {
/**
* Block name.
*
* @var string
*/
protected $block_name = 'mini-cart-products-table-block';
}

View File

@ -0,0 +1,14 @@
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
/**
* MiniCartShoppingButtonBlock class.
*/
class MiniCartShoppingButtonBlock extends AbstractInnerBlock {
/**
* Block name.
*
* @var string
*/
protected $block_name = 'mini-cart-shopping-button-block';
}

View File

@ -0,0 +1,14 @@
<?php
namespace Automattic\WooCommerce\Blocks\BlockTypes;
/**
* MiniCartTitleBlock class.
*/
class MiniCartTitleBlock extends AbstractInnerBlock {
/**
* Block name.
*
* @var string
*/
protected $block_name = 'mini-cart-title-block';
}

View File

@ -8,6 +8,7 @@ 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;
use Automattic\WooCommerce\Blocks\BlockTypes\MiniCartContents;
/**
* BlockTypesController class.
@ -182,7 +183,6 @@ final class BlockTypesController {
'FilterWrapper',
'HandpickedProducts',
'MiniCart',
'MiniCartContents',
'StoreNotices',
'PriceFilter',
'ProductAddToCart',
@ -217,7 +217,12 @@ final class BlockTypesController {
'StockFilter',
];
$block_types = array_merge( $block_types, Cart::get_cart_block_types(), Checkout::get_checkout_block_types() );
$block_types = array_merge(
$block_types,
Cart::get_cart_block_types(),
Checkout::get_checkout_block_types(),
MiniCartContents::get_mini_cart_block_types()
);
if ( Package::feature()->is_experimental_build() ) {
$block_types[] = 'SingleProduct';