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

Fix Mini Cart missing translations #8591

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/BlockTypes/EmptyMiniCartContentsBlock.php
Original file line number Diff line number Diff line change
@@ -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';
}
14 changes: 14 additions & 0 deletions src/BlockTypes/FilledMiniCartContentsBlock.php
Original file line number Diff line number Diff line change
@@ -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';
}
5 changes: 2 additions & 3 deletions src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ protected function get_markup( $attributes ) {
$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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file are generic cleanup. Unrelated to the other changes in this PR.

$cart_contents_total = $cart->get_subtotal();

if ( $cart->display_prices_including_tax() ) {
Expand All @@ -378,7 +377,7 @@ protected function get_markup( $attributes ) {
$wrapper_styles = $classes_styles['styles'];

$aria_label = sprintf(
/* translators: %1$d is the number of products in the cart. %2$s is the cart total */
/* translators: %1$d is the number of products in the cart. %2$s is the cart total */
_n(
'%1$d item in cart, total price of %2$s',
'%1$d items in cart, total price of %2$s',
Expand All @@ -401,7 +400,7 @@ protected function get_markup( $attributes ) {

if ( is_cart() || is_checkout() ) {
// It is not necessary to load the Mini Cart Block on Cart and Checkout page.
return '<div class="' . $wrapper_classes . '" style="visibility:hidden" aria-hidden="true">
return '<div class="' . $wrapper_classes . '" style="visibility:hidden" aria-hidden="true">
<button class="wc-block-mini-cart__button" aria-label="' . esc_attr( $aria_label ) . '" disabled>' . $button_html . '</button>
</div>';
}
Expand Down
25 changes: 21 additions & 4 deletions src/BlockTypes/MiniCartContents.php
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -140,4 +136,25 @@ function( $property ) {
$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;
}

}
14 changes: 14 additions & 0 deletions src/BlockTypes/MiniCartFooterBlock.php
Original file line number Diff line number Diff line change
@@ -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';
}
14 changes: 14 additions & 0 deletions src/BlockTypes/MiniCartItemsBlock.php
Original file line number Diff line number Diff line change
@@ -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';
}
14 changes: 14 additions & 0 deletions src/BlockTypes/MiniCartProductsTableBlock.php
Original file line number Diff line number Diff line change
@@ -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';
}
14 changes: 14 additions & 0 deletions src/BlockTypes/MiniCartShoppingButtonBlock.php
Original file line number Diff line number Diff line change
@@ -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';
}
14 changes: 14 additions & 0 deletions src/BlockTypes/MiniCartTitleBlock.php
Original file line number Diff line number Diff line change
@@ -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';
}
9 changes: 7 additions & 2 deletions src/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
Expand Down Expand Up @@ -182,7 +183,6 @@ protected function get_block_types() {
'FilterWrapper',
'HandpickedProducts',
'MiniCart',
'MiniCartContents',
'StoreNotices',
'PriceFilter',
'ProductAddToCart',
Expand Down Expand Up @@ -217,7 +217,12 @@ protected function get_block_types() {
'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';
Expand Down