diff --git a/assets/js/blocks/cart-checkout/cart-i2/attributes.js b/assets/js/blocks/cart-checkout/cart-i2/attributes.js
deleted file mode 100644
index 8e4da47fb07..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/attributes.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * External dependencies
- */
-import { getSetting } from '@woocommerce/settings';
-
-export const blockName = 'woocommerce/cart-i2';
-export const blockAttributes = {
- isPreview: {
- type: 'boolean',
- default: false,
- save: false,
- },
- hasDarkControls: {
- type: 'boolean',
- default: getSetting( 'hasDarkEditorStyleSupport', false ),
- },
-};
diff --git a/assets/js/blocks/cart-checkout/cart-i2/block.js b/assets/js/blocks/cart-checkout/cart-i2/block.js
deleted file mode 100644
index f847bb11f38..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/block.js
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-import { CART_STORE_KEY as storeKey } from '@woocommerce/block-data';
-import { dispatch } from '@wordpress/data';
-import { useStoreCart } from '@woocommerce/base-context/hooks';
-import { useEffect } from '@wordpress/element';
-import LoadingMask from '@woocommerce/base-components/loading-mask';
-import { ValidationContextProvider } from '@woocommerce/base-context';
-import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
-import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
-import { translateJQueryEventToNative } from '@woocommerce/base-utils';
-import withScrollToTop from '@woocommerce/base-hocs/with-scroll-to-top';
-import {
- StoreNoticesProvider,
- StoreSnackbarNoticesProvider,
- CartProvider,
-} from '@woocommerce/base-context/providers';
-import { SlotFillProvider } from '@woocommerce/blocks-checkout';
-
-/**
- * Internal dependencies
- */
-import { CartBlockContext } from './context';
-import './style.scss';
-
-const reloadPage = () => void window.location.reload( true );
-
-const Cart = ( { children, attributes } ) => {
- const { cartIsLoading } = useStoreCart();
- const { hasDarkControls } = attributes;
-
- return (
-
-
-
- { children }
-
-
-
- );
-};
-
-const ScrollOnError = ( { scrollToTop } ) => {
- useEffect( () => {
- const invalidateCartData = () => {
- dispatch( storeKey ).invalidateResolutionForStore();
- scrollToTop();
- };
-
- // Make it so we can read jQuery events triggered by WC Core elements.
- const removeJQueryAddedToCartEvent = translateJQueryEventToNative(
- 'added_to_cart',
- 'wc-blocks_added_to_cart'
- );
- const removeJQueryRemovedFromCartEvent = translateJQueryEventToNative(
- 'removed_from_cart',
- 'wc-blocks_removed_from_cart'
- );
-
- document.body.addEventListener(
- 'wc-blocks_added_to_cart',
- invalidateCartData
- );
- document.body.addEventListener(
- 'wc-blocks_removed_from_cart',
- invalidateCartData
- );
-
- return () => {
- removeJQueryAddedToCartEvent();
- removeJQueryRemovedFromCartEvent();
-
- document.body.removeEventListener(
- 'wc-blocks_added_to_cart',
- invalidateCartData
- );
- document.body.removeEventListener(
- 'wc-blocks_removed_from_cart',
- invalidateCartData
- );
- };
- }, [ scrollToTop ] );
-
- return null;
-};
-const Block = ( { attributes, children, scrollToTop } ) => (
-
- { __( 'Reload the page', 'woo-gutenberg-products-block' ) }
-
- }
- showErrorMessage={ CURRENT_USER_IS_ADMIN }
- >
-
-
-
-
- { children }
-
-
-
-
-
-
-);
-export default withScrollToTop( Block );
diff --git a/assets/js/blocks/cart-checkout/cart-i2/cart-line-items-table/cart-line-item-row.tsx b/assets/js/blocks/cart-checkout/cart-i2/cart-line-items-table/cart-line-item-row.tsx
deleted file mode 100644
index 2cf2248dda2..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/cart-line-items-table/cart-line-item-row.tsx
+++ /dev/null
@@ -1,309 +0,0 @@
-/**
- * External dependencies
- */
-import classnames from 'classnames';
-import { __ } from '@wordpress/i18n';
-import QuantitySelector from '@woocommerce/base-components/quantity-selector';
-import ProductPrice from '@woocommerce/base-components/product-price';
-import ProductName from '@woocommerce/base-components/product-name';
-import {
- useStoreCartItemQuantity,
- useStoreEvents,
- useStoreCart,
-} from '@woocommerce/base-context/hooks';
-import {
- ProductBackorderBadge,
- ProductImage,
- ProductLowStockBadge,
- ProductMetadata,
- ProductSaleBadge,
-} from '@woocommerce/base-components/cart-checkout';
-import {
- getCurrencyFromPriceResponse,
- Currency,
-} from '@woocommerce/price-format';
-import {
- __experimentalApplyCheckoutFilter,
- mustContain,
-} from '@woocommerce/blocks-checkout';
-import Dinero from 'dinero.js';
-import { useMemo } from '@wordpress/element';
-import type { CartItem } from '@woocommerce/type-defs/cart';
-import { objectHasProp } from '@woocommerce/types';
-import { getSetting } from '@woocommerce/settings';
-
-/**
- * Convert a Dinero object with precision to store currency minor unit.
- *
- * @param {Dinero} priceObject Price object to convert.
- * @param {Object} currency Currency data.
- * @return {number} Amount with new minor unit precision.
- */
-const getAmountFromRawPrice = (
- priceObject: Dinero.Dinero,
- currency: Currency
-) => {
- return priceObject.convertPrecision( currency.minorUnit ).getAmount();
-};
-
-const productPriceValidation = ( value ) => mustContain( value, ' ' );
-
-/**
- * Cart line item table row component.
- *
- * @param {Object} props
- * @param {CartItem|Object} props.lineItem
- */
-const CartLineItemRow = ( {
- lineItem,
-}: {
- lineItem: CartItem | Record< string, never >;
-} ): JSX.Element => {
- const {
- name: initialName = '',
- catalog_visibility: catalogVisibility = 'visible',
- short_description: shortDescription = '',
- description: fullDescription = '',
- low_stock_remaining: lowStockRemaining = null,
- show_backorder_badge: showBackorderBadge = false,
- quantity_limit: quantityLimit = 99,
- permalink = '',
- images = [],
- variation = [],
- item_data: itemData = [],
- prices = {
- currency_code: 'USD',
- currency_minor_unit: 2,
- currency_symbol: '$',
- currency_prefix: '$',
- currency_suffix: '',
- currency_decimal_separator: '.',
- currency_thousand_separator: ',',
- price: '0',
- regular_price: '0',
- sale_price: '0',
- price_range: null,
- raw_prices: {
- precision: 6,
- price: '0',
- regular_price: '0',
- sale_price: '0',
- },
- },
- totals = {
- currency_code: 'USD',
- currency_minor_unit: 2,
- currency_symbol: '$',
- currency_prefix: '$',
- currency_suffix: '',
- currency_decimal_separator: '.',
- currency_thousand_separator: ',',
- line_subtotal: '0',
- line_subtotal_tax: '0',
- },
- extensions,
- } = lineItem;
-
- const {
- quantity,
- setItemQuantity,
- removeItem,
- isPendingDelete,
- } = useStoreCartItemQuantity( lineItem );
- const { dispatchStoreEvent } = useStoreEvents();
-
- // Prepare props to pass to the __experimentalApplyCheckoutFilter filter.
- // We need to pluck out receiveCart.
- // eslint-disable-next-line no-unused-vars
- const { receiveCart, ...cart } = useStoreCart();
- const arg = useMemo(
- () => ( {
- context: 'cart',
- cartItem: lineItem,
- cart,
- } ),
- [ lineItem, cart ]
- );
- const priceCurrency = getCurrencyFromPriceResponse( prices );
- const name = __experimentalApplyCheckoutFilter( {
- filterName: 'itemName',
- defaultValue: initialName,
- extensions,
- arg,
- } );
-
- const regularAmountSingle = Dinero( {
- amount: parseInt( prices.raw_prices.regular_price, 10 ),
- precision: prices.raw_prices.precision,
- } );
- const purchaseAmountSingle = Dinero( {
- amount: parseInt( prices.raw_prices.price, 10 ),
- precision: prices.raw_prices.precision,
- } );
- const saleAmountSingle = regularAmountSingle.subtract(
- purchaseAmountSingle
- );
- const saleAmount = saleAmountSingle.multiply( quantity );
- const totalsCurrency = getCurrencyFromPriceResponse( totals );
- let lineSubtotal = parseInt( totals.line_subtotal, 10 );
- if ( getSetting( 'displayCartPricesIncludingTax', false ) ) {
- lineSubtotal += parseInt( totals.line_subtotal_tax, 10 );
- }
- const subtotalPrice = Dinero( {
- amount: lineSubtotal,
- precision: totalsCurrency.minorUnit,
- } );
-
- const firstImage = images.length ? images[ 0 ] : {};
- const isProductHiddenFromCatalog =
- catalogVisibility === 'hidden' || catalogVisibility === 'search';
-
- // Allow extensions to filter how the price is displayed. Ie: prepending or appending some values.
-
- const productPriceFormat = __experimentalApplyCheckoutFilter( {
- filterName: 'cartItemPrice',
- defaultValue: ' ',
- extensions,
- arg,
- validation: productPriceValidation,
- } );
-
- const subtotalPriceFormat = __experimentalApplyCheckoutFilter( {
- filterName: 'subtotalPriceFormat',
- defaultValue: ' ',
- extensions,
- arg,
- validation: productPriceValidation,
- } );
-
- const saleBadgePriceFormat = __experimentalApplyCheckoutFilter( {
- filterName: 'saleBadgePriceFormat',
- defaultValue: ' ',
- extensions,
- arg,
- validation: productPriceValidation,
- } );
-
- return (
-
- { /* If the image has no alt text, this link is unnecessary and can be hidden. */ }
-
- { /* We don't need to make it focusable, because product name has the same link. */ }
- { isProductHiddenFromCatalog ? (
-
- ) : (
-
-
-
- ) }
-
-
-
- { showBackorderBadge ? (
-
- ) : (
- !! lowStockRemaining && (
-
- )
- ) }
-
-
-
-
-
-
-
-
- {
- setItemQuantity( newQuantity );
- dispatchStoreEvent( 'cart-set-item-quantity', {
- product: lineItem,
- quantity: newQuantity,
- } );
- } }
- itemName={ name }
- />
- {
- removeItem();
- dispatchStoreEvent( 'cart-remove-item', {
- product: lineItem,
- quantity,
- } );
- } }
- disabled={ isPendingDelete }
- >
- { __( 'Remove item', 'woo-gutenberg-products-block' ) }
-
-
-
-
-
-
-
- { quantity > 1 && (
-
- ) }
-
-
-
- );
-};
-
-export default CartLineItemRow;
diff --git a/assets/js/blocks/cart-checkout/cart-i2/cart-line-items-table/index.tsx b/assets/js/blocks/cart-checkout/cart-i2/cart-line-items-table/index.tsx
deleted file mode 100644
index 17aa98e9378..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/cart-line-items-table/index.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-import { CartResponseItem } from '@woocommerce/type-defs/cart-response';
-
-/**
- * Internal dependencies
- */
-import CartLineItemRow from './cart-line-item-row';
-
-const placeholderRows = [ ...Array( 3 ) ].map( ( _x, i ) => (
-
-) );
-
-interface CartLineItemsTableProps {
- lineItems: CartResponseItem[];
- isLoading: boolean;
-}
-
-const CartLineItemsTable = ( {
- lineItems = [],
- isLoading = false,
-}: CartLineItemsTableProps ): JSX.Element => {
- const products = isLoading
- ? placeholderRows
- : lineItems.map( ( lineItem ) => {
- return (
-
- );
- } );
-
- return (
-
-
-
-
-
- { __( 'Product', 'woo-gutenberg-products-block' ) }
-
-
-
-
- { __( 'Details', 'woo-gutenberg-products-block' ) }
-
-
-
-
- { __( 'Total', 'woo-gutenberg-products-block' ) }
-
-
-
-
- { products }
-
- );
-};
-
-export default CartLineItemsTable;
diff --git a/assets/js/blocks/cart-checkout/cart-i2/edit.tsx b/assets/js/blocks/cart-checkout/cart-i2/edit.tsx
deleted file mode 100644
index 3a871b908b9..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/edit.tsx
+++ /dev/null
@@ -1,207 +0,0 @@
-/* tslint:disable */
-/**
- * External dependencies
- */
-import classnames from 'classnames';
-import { __ } from '@wordpress/i18n';
-import { CartCheckoutFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt';
-import {
- useBlockProps,
- InnerBlocks,
- InspectorControls,
- BlockControls,
-} from '@wordpress/block-editor';
-import { PanelBody, ToggleControl, Notice } from '@wordpress/components';
-import { CartCheckoutCompatibilityNotice } from '@woocommerce/editor-components/compatibility-notices';
-import { CART_PAGE_ID } from '@woocommerce/block-settings';
-import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
-import {
- EditorProvider,
- useEditorContext,
- CartProvider,
-} from '@woocommerce/base-context';
-import { createInterpolateElement } from '@wordpress/element';
-import { getAdminLink } from '@woocommerce/settings';
-import { previewCart } from '@woocommerce/resource-previews';
-import { Icon, filledCart, removeCart } from '@woocommerce/icons';
-
-/**
- * Internal dependencies
- */
-import './editor.scss';
-import {
- addClassToBody,
- useViewSwitcher,
- useBlockPropsWithLocking,
-} from '../shared';
-import type { Attributes } from './types';
-import { CartBlockContext } from './context';
-
-// This is adds a class to body to signal if the selected block is locked
-addClassToBody();
-
-// Array of allowed block names.
-const ALLOWED_BLOCKS: string[] = [
- 'woocommerce/filled-cart-block',
- 'woocommerce/empty-cart-block',
-];
-
-const BlockSettings = ( {
- attributes,
- setAttributes,
-}: {
- attributes: Attributes;
- setAttributes: ( attributes: Record< string, unknown > ) => undefined;
-} ): JSX.Element => {
- const { hasDarkControls } = attributes;
- const { currentPostId } = useEditorContext();
- return (
-
- { currentPostId !== CART_PAGE_ID && (
-
- { createInterpolateElement(
- __(
- 'If you would like to use this block as your default cart you must update your page settings in WooCommerce .',
- 'woo-gutenberg-products-block'
- ),
- {
- a: (
- // eslint-disable-next-line jsx-a11y/anchor-has-content
-
- ),
- }
- ) }
-
- ) }
-
-
- setAttributes( {
- hasDarkControls: ! hasDarkControls,
- } )
- }
- />
-
-
-
- );
-};
-
-/**
- * Component to handle edit mode of "Cart Block".
- */
-export const Edit = ( {
- className,
- attributes,
- setAttributes,
- clientId,
-}: {
- className: string;
- attributes: Attributes;
- setAttributes: ( attributes: Record< string, unknown > ) => undefined;
- clientId: string;
-} ): JSX.Element => {
- const { hasDarkControls } = attributes;
- const { currentView, component: ViewSwitcherComponent } = useViewSwitcher(
- clientId,
- [
- {
- view: 'woocommerce/filled-cart-block',
- label: __( 'Filled Cart', 'woo-gutenberg-products-block' ),
- icon: ,
- },
- {
- view: 'woocommerce/empty-cart-block',
- label: __( 'Empty Cart', 'woo-gutenberg-products-block' ),
- icon: ,
- },
- ]
- );
- const defaultTemplate = [
- [ 'woocommerce/filled-cart-block', {}, [] ],
- [ 'woocommerce/empty-cart-block', {}, [] ],
- ];
- const blockProps = useBlockPropsWithLocking( {
- className: classnames( className, 'wp-block-woocommerce-cart', {
- 'is-editor-preview': attributes.isPreview,
- } ),
- } );
-
- return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- );
-};
-
-export const Save = (): JSX.Element => {
- return (
-
-
-
- );
-};
diff --git a/assets/js/blocks/cart-checkout/cart-i2/editor.scss b/assets/js/blocks/cart-checkout/cart-i2/editor.scss
deleted file mode 100644
index d39e5532fbb..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/editor.scss
+++ /dev/null
@@ -1,22 +0,0 @@
-.wc-block-cart__page-notice {
- margin: 0;
-}
-
-body.wc-lock-selected-block--move {
- .block-editor-block-mover__move-button-container,
- .block-editor-block-mover {
- display: none;
- }
-}
-
-body.wc-lock-selected-block--remove {
- .block-editor-block-settings-menu__popover {
- .components-menu-group:last-child {
- display: none;
- }
- .components-menu-group:nth-last-child(2) {
- margin-bottom: -12px;
- }
- }
-}
-
diff --git a/assets/js/blocks/cart-checkout/cart-i2/frontend.js b/assets/js/blocks/cart-checkout/cart-i2/frontend.js
deleted file mode 100644
index 3de8c392f5a..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/frontend.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * External dependencies
- */
-import {
- withStoreCartApiHydration,
- withRestApiHydration,
-} from '@woocommerce/block-hocs';
-import { getValidBlockAttributes } from '@woocommerce/base-utils';
-import { Children, cloneElement, isValidElement } from '@wordpress/element';
-import { useStoreCart } from '@woocommerce/base-context';
-import { getRegisteredBlockComponents } from '@woocommerce/blocks-registry';
-
-import { renderParentBlock } from '@woocommerce/atomic-utils';
-
-/**
- * Internal dependencies
- */
-import './inner-blocks/register-components';
-import Block from './block';
-import { blockName, blockAttributes } from './attributes';
-
-const getProps = ( el ) => {
- return {
- attributes: getValidBlockAttributes(
- blockAttributes,
- !! el ? el.dataset : {}
- ),
- };
-};
-
-const Wrapper = ( { children } ) => {
- // we need to pluck out receiveCart.
- // eslint-disable-next-line no-unused-vars
- const { extensions, receiveCart, ...cart } = useStoreCart();
- return Children.map( children, ( child ) => {
- if ( isValidElement( child ) ) {
- const componentProps = {
- extensions,
- cart,
- };
- return cloneElement( child, componentProps );
- }
- return child;
- } );
-};
-
-renderParentBlock( {
- Block: withStoreCartApiHydration( withRestApiHydration( Block ) ),
- blockName,
- selector: '.wp-block-woocommerce-cart-i2',
- getProps,
- blockMap: getRegisteredBlockComponents( blockName ),
- blockWrapper: Wrapper,
-} );
diff --git a/assets/js/blocks/cart-checkout/cart-i2/index.js b/assets/js/blocks/cart-checkout/cart-i2/index.js
deleted file mode 100644
index 51dc5716b85..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/index.js
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-import { Icon, cart } from '@woocommerce/icons';
-import { registerExperimentalBlockType } from '@woocommerce/block-settings';
-
-/**
- * Internal dependencies
- */
-import { Edit, Save } from './edit';
-import './style.scss';
-import { blockName, blockAttributes } from './attributes';
-import './inner-blocks';
-
-/**
- * Register and run the Cart block.
- */
-const settings = {
- title: __( 'Cart i2', 'woo-gutenberg-products-block' ),
- icon: {
- src: ,
- foreground: '#7f54b3',
- },
- category: 'woocommerce',
- keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
- description: __( 'Shopping cart.', 'woo-gutenberg-products-block' ),
- supports: {
- align: false,
- html: false,
- multiple: false,
- __experimentalExposeControlsToChildren: true,
- },
- example: {
- attributes: {
- isPreview: true,
- },
- },
- attributes: blockAttributes,
- edit: Edit,
- save: Save,
-};
-
-registerExperimentalBlockType( blockName, settings );
diff --git a/assets/js/blocks/cart-checkout/cart-i2/style.scss b/assets/js/blocks/cart-checkout/cart-i2/style.scss
deleted file mode 100644
index 4743d1366d1..00000000000
--- a/assets/js/blocks/cart-checkout/cart-i2/style.scss
+++ /dev/null
@@ -1,56 +0,0 @@
-.wp-block-woocommerce-cart-i2 {
- margin-bottom: 3em;
-
- .wc-block-cart-items {
- @include with-translucent-border(0 0 1px);
-
- th {
- padding: 0.25rem $gap 0.25rem 0;
- white-space: nowrap;
- }
- td {
- @include with-translucent-border(1px 0 0);
- padding: $gap 0 $gap $gap;
- vertical-align: top;
- }
- th:last-child {
- padding-right: 0;
- }
- td:last-child {
- padding-right: $gap;
- }
- }
-
- .wc-block-cart__sidebar {
- & > div:not(.wc-block-components-totals-wrapper) {
- margin-left: $gap;
- margin-right: $gap;
- }
- }
-
- .wc-block-components-radio-control__input {
- left: 0;
- }
-
- .wc-block-cart__totals-title {
- @include text-heading();
- @include font-size(smaller);
- display: block;
- font-weight: 600;
- padding: 0.25rem 0;
- text-align: right;
- text-transform: uppercase;
- }
-
- .wc-block-components-sidebar {
- .wc-block-components-shipping-calculator,
- .wc-block-components-shipping-rates-control__package:not(.wc-block-components-panel) {
- padding-left: $gap;
- padding-right: $gap;
- }
- }
-
- .wc-block-cart__payment-options {
- padding: $gap 0 0;
- }
-}
diff --git a/assets/js/blocks/cart-checkout/cart/attributes.js b/assets/js/blocks/cart-checkout/cart/attributes.js
index dadbb2d57e1..0dbd93be053 100644
--- a/assets/js/blocks/cart-checkout/cart/attributes.js
+++ b/assets/js/blocks/cart-checkout/cart/attributes.js
@@ -3,12 +3,18 @@
*/
import { getSetting } from '@woocommerce/settings';
-const blockAttributes = {
+export const blockName = 'woocommerce/cart';
+export const blockAttributes = {
isPreview: {
type: 'boolean',
default: false,
save: false,
},
+ hasDarkControls: {
+ type: 'boolean',
+ default: getSetting( 'hasDarkEditorStyleSupport', false ),
+ },
+ // Deprecated - here for v1 migration support
isShippingCalculatorEnabled: {
type: 'boolean',
default: getSetting( 'isShippingCalculatorEnabled', true ),
@@ -17,14 +23,8 @@ const blockAttributes = {
type: 'number',
default: 0,
},
- hasDarkControls: {
- type: 'boolean',
- default: getSetting( 'hasDarkEditorStyleSupport', false ),
- },
showRateAfterTaxName: {
type: 'boolean',
default: true,
},
};
-
-export default blockAttributes;
diff --git a/assets/js/blocks/cart-checkout/cart/block.js b/assets/js/blocks/cart-checkout/cart/block.js
index d84762c57ca..5e508049199 100644
--- a/assets/js/blocks/cart-checkout/cart/block.js
+++ b/assets/js/blocks/cart-checkout/cart/block.js
@@ -1,37 +1,52 @@
/**
* External dependencies
*/
+import { __ } from '@wordpress/i18n';
import { CART_STORE_KEY as storeKey } from '@woocommerce/block-data';
import { dispatch } from '@wordpress/data';
import { useStoreCart } from '@woocommerce/base-context/hooks';
-import { useEffect, RawHTML } from '@wordpress/element';
+import { useEffect } from '@wordpress/element';
import LoadingMask from '@woocommerce/base-components/loading-mask';
import { ValidationContextProvider } from '@woocommerce/base-context';
-import {
- dispatchEvent,
- translateJQueryEventToNative,
-} from '@woocommerce/base-utils';
+import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
+import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
+import { translateJQueryEventToNative } from '@woocommerce/base-utils';
import withScrollToTop from '@woocommerce/base-hocs/with-scroll-to-top';
+import {
+ StoreNoticesProvider,
+ StoreSnackbarNoticesProvider,
+ CartProvider,
+} from '@woocommerce/base-context/providers';
+import { SlotFillProvider } from '@woocommerce/blocks-checkout';
/**
* Internal dependencies
*/
-import FullCart from './full-cart';
+import { CartBlockContext } from './context';
+import './style.scss';
-const EmptyCart = ( { content } ) => {
- useEffect( () => {
- dispatchEvent( 'wc-blocks_render_blocks_frontend', {
- element: document.body.querySelector(
- '.wp-block-woocommerce-cart'
- ),
- } );
- }, [] );
- return { content } ;
-};
+const reloadPage = () => void window.location.reload( true );
-const Block = ( { emptyCart, attributes, scrollToTop } ) => {
- const { cartItems, cartIsLoading } = useStoreCart();
+const Cart = ( { children, attributes } ) => {
+ const { cartIsLoading } = useStoreCart();
+ const { hasDarkControls } = attributes;
+ return (
+
+
+
+ { children }
+
+
+
+ );
+};
+
+const ScrollOnError = ( { scrollToTop } ) => {
useEffect( () => {
const invalidateCartData = ( e ) => {
const eventDetail = e.detail;
@@ -75,19 +90,32 @@ const Block = ( { emptyCart, attributes, scrollToTop } ) => {
};
}, [ scrollToTop ] );
- return (
- <>
- { ! cartIsLoading && cartItems.length === 0 ? (
-
- ) : (
-
-
-
-
-
- ) }
- >
- );
+ return null;
};
-
+const Block = ( { attributes, children, scrollToTop } ) => (
+
+ { __( 'Reload the page', 'woo-gutenberg-products-block' ) }
+
+ }
+ showErrorMessage={ CURRENT_USER_IS_ADMIN }
+ >
+
+
+
+
+ { children }
+
+
+
+
+
+
+);
export default withScrollToTop( Block );
diff --git a/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-item-row.tsx b/assets/js/blocks/cart-checkout/cart/cart-line-items-table/cart-line-item-row.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart/full-cart/cart-line-item-row.tsx
rename to assets/js/blocks/cart-checkout/cart/cart-line-items-table/cart-line-item-row.tsx
diff --git a/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-items-table.tsx b/assets/js/blocks/cart-checkout/cart/cart-line-items-table/index.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart/full-cart/cart-line-items-table.tsx
rename to assets/js/blocks/cart-checkout/cart/cart-line-items-table/index.tsx
diff --git a/assets/js/blocks/cart-checkout/cart/checkout-button/index.tsx b/assets/js/blocks/cart-checkout/cart/checkout-button/index.tsx
deleted file mode 100644
index edd75e97212..00000000000
--- a/assets/js/blocks/cart-checkout/cart/checkout-button/index.tsx
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-import { useState, useEffect } from '@wordpress/element';
-import { PaymentMethodIcons } from '@woocommerce/base-components/cart-checkout';
-import Button from '@woocommerce/base-components/button';
-import { CHECKOUT_URL } from '@woocommerce/block-settings';
-import { useCheckoutContext } from '@woocommerce/base-context';
-import { usePaymentMethods } from '@woocommerce/base-context/hooks';
-import { usePositionRelativeToViewport } from '@woocommerce/base-hooks';
-import type {
- PaymentMethods,
- PaymentMethodIcons as PaymentMethodIconsType,
-} from '@woocommerce/type-defs/payments';
-
-/**
- * Internal dependencies
- */
-import './style.scss';
-
-const getIconsFromPaymentMethods = (
- paymentMethods: PaymentMethods
-): PaymentMethodIconsType => {
- return Object.values( paymentMethods ).reduce( ( acc, paymentMethod ) => {
- if ( paymentMethod.icons !== null ) {
- acc = acc.concat( paymentMethod.icons );
- }
- return acc;
- }, [] as PaymentMethodIconsType );
-};
-
-/**
- * Checkout button rendered in the full cart page.
- *
- * @param {Object} props Incoming props for the component.
- * @param {string} props.link What the button is linked to.
- */
-const CheckoutButton = ( { link }: { link: string } ): JSX.Element => {
- const { isCalculating } = useCheckoutContext();
- const [
- positionReferenceElement,
- positionRelativeToViewport,
- ] = usePositionRelativeToViewport();
- const [ showSpinner, setShowSpinner ] = useState( false );
- const { paymentMethods } = usePaymentMethods();
-
- useEffect( () => {
- // Add a listener to remove the spinner on the checkout button, so the saved page snapshot does not
- // contain the spinner class. See https://archive.is/lOEW0 for why this is needed for Safari.
-
- if (
- typeof global.addEventListener !== 'function' ||
- typeof global.removeEventListener !== 'function'
- ) {
- return;
- }
-
- const hideSpinner = () => {
- setShowSpinner( false );
- };
-
- global.addEventListener( 'pageshow', hideSpinner );
-
- return () => {
- global.removeEventListener( 'pageshow', hideSpinner );
- };
- }, [] );
-
- const submitContainerContents = (
- <>
- setShowSpinner( true ) }
- showSpinner={ showSpinner }
- >
- { __( 'Proceed to Checkout', 'woo-gutenberg-products-block' ) }
-
-
- >
- );
-
- return (
-
- { positionReferenceElement }
- { /* The non-sticky container must always be visible because it gives height to its parent, which is required to calculate when it becomes visible in the viewport. */ }
-
- { submitContainerContents }
-
- { /* If the positionReferenceElement is below the viewport, display the sticky container. */ }
- { positionRelativeToViewport === 'below' && (
-
- { submitContainerContents }
-
- ) }
-
- );
-};
-
-export default CheckoutButton;
diff --git a/assets/js/blocks/cart-checkout/cart/checkout-button/style.scss b/assets/js/blocks/cart-checkout/cart/checkout-button/style.scss
deleted file mode 100644
index 84bf7a2ea72..00000000000
--- a/assets/js/blocks/cart-checkout/cart/checkout-button/style.scss
+++ /dev/null
@@ -1,56 +0,0 @@
-.wc-block-cart__submit {
- position: relative;
-}
-
-.wc-block-cart__submit-container {
- padding-bottom: $gap;
-}
-
-.wc-block-cart__submit-button {
- width: 100%;
- margin: 0 0 $gap;
-
- &:last-child {
- margin-bottom: 0;
- }
-}
-
-.is-mobile,
-.is-small,
-.is-medium {
- .wc-block-cart__submit-container:not(.wc-block-cart__submit-container--sticky) {
- padding-left: 0;
- padding-right: 0;
- padding-top: 0;
- }
-}
-
-@include breakpoint(">782px") {
- .wc-block-cart__submit-container--sticky {
- display: none;
- }
-}
-
-@include breakpoint("<782px") {
- .wc-block-cart__submit-container--sticky {
- background: $white;
- bottom: 0;
- left: 0;
- padding: $gap;
- position: fixed;
- width: 100%;
- z-index: 9999;
-
- &::before {
- box-shadow: 0 -10px 20px 10px currentColor;
- color: transparentize($gray-400, 0.5);
- content: "";
- height: 100%;
- left: 0;
- position: absolute;
- right: 0;
- top: 0;
- }
- }
-}
-
diff --git a/assets/js/blocks/cart-checkout/cart-i2/context.ts b/assets/js/blocks/cart-checkout/cart/context.ts
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/context.ts
rename to assets/js/blocks/cart-checkout/cart/context.ts
diff --git a/assets/js/blocks/cart-checkout/cart/edit.js b/assets/js/blocks/cart-checkout/cart/edit.js
index 8a64b980bbd..933f6af1169 100644
--- a/assets/js/blocks/cart-checkout/cart/edit.js
+++ b/assets/js/blocks/cart-checkout/cart/edit.js
@@ -1,20 +1,18 @@
+/* tslint:disable */
/**
* External dependencies
*/
import classnames from 'classnames';
import { __ } from '@wordpress/i18n';
import { CartCheckoutFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt';
-import { InspectorControls } from '@wordpress/block-editor';
import {
- Disabled,
- PanelBody,
- ToggleControl,
- Notice,
-} from '@wordpress/components';
-import PropTypes from 'prop-types';
+ useBlockProps,
+ InnerBlocks,
+ InspectorControls,
+ BlockControls,
+} from '@wordpress/block-editor';
+import { PanelBody, ToggleControl, Notice } from '@wordpress/components';
import { CartCheckoutCompatibilityNotice } from '@woocommerce/editor-components/compatibility-notices';
-import ViewSwitcher from '@woocommerce/editor-components/view-switcher';
-import PageSelector from '@woocommerce/editor-components/page-selector';
import { CART_PAGE_ID } from '@woocommerce/block-settings';
import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary';
import {
@@ -22,26 +20,35 @@ import {
useEditorContext,
CartProvider,
} from '@woocommerce/base-context';
-import { createInterpolateElement, useRef } from '@wordpress/element';
-import { getAdminLink, getSetting } from '@woocommerce/settings';
+import { createInterpolateElement } from '@wordpress/element';
+import { getAdminLink } from '@woocommerce/settings';
import { previewCart } from '@woocommerce/resource-previews';
+import { Icon, filledCart, removeCart } from '@woocommerce/icons';
/**
* Internal dependencies
*/
-import Block from './block.js';
-import EmptyCartEdit from './empty-cart-edit';
import './editor.scss';
+import {
+ addClassToBody,
+ useViewSwitcher,
+ useBlockPropsWithLocking,
+ useForcedLayout,
+} from '../shared';
+import { CartBlockContext } from './context';
+
+// This is adds a class to body to signal if the selected block is locked
+addClassToBody();
+
+// Array of allowed block names.
+const ALLOWED_BLOCKS = [
+ 'woocommerce/filled-cart-block',
+ 'woocommerce/empty-cart-block',
+];
const BlockSettings = ( { attributes, setAttributes } ) => {
- const {
- isShippingCalculatorEnabled,
- checkoutPageId,
- hasDarkControls,
- showRateAfterTaxName,
- } = attributes;
+ const { hasDarkControls } = attributes;
const { currentPostId } = useEditorContext();
- const { current: savedCheckoutPageId } = useRef( checkoutPageId );
return (
{ currentPostId !== CART_PAGE_ID && (
@@ -70,75 +77,6 @@ const BlockSettings = ( { attributes, setAttributes } ) => {
) }
) }
- { getSetting( 'shippingEnabled', true ) && (
-
-
- setAttributes( {
- isShippingCalculatorEnabled: ! isShippingCalculatorEnabled,
- } )
- }
- />
-
- ) }
- { getSetting( 'taxesEnabled' ) &&
- getSetting( 'displayItemizedTaxes', false ) &&
- ! getSetting( 'displayCartPricesIncludingTax', false ) && (
-
-
- setAttributes( {
- showRateAfterTaxName: ! showRateAfterTaxName,
- } )
- }
- />
-
- ) }
- { ! (
- currentPostId === CART_PAGE_ID && savedCheckoutPageId === 0
- ) && (
-
- setAttributes( { checkoutPageId: id } )
- }
- labels={ {
- title: __(
- 'Proceed to Checkout button',
- 'woo-gutenberg-products-block'
- ),
- default: __(
- 'WooCommerce Checkout Page',
- 'woo-gutenberg-products-block'
- ),
- } }
- />
- ) }
{
);
};
-/**
- * Component to handle edit mode of "Cart Block".
- *
- * Note: We need to always render `` in the editor. Otherwise,
- * if the user saves the page without having triggered the 'Empty Cart'
- * view, inner blocks would not be saved and they wouldn't be visible
- * in the frontend.
- *
- * @param {Object} props Incoming props for the component.
- * @param {string} props.className CSS class used.
- * @param {Object} props.attributes Attributes available.
- * @param {function(any):any} props.setAttributes Setter for attributes.
- */
-const CartEditor = ( { className, attributes, setAttributes } ) => {
+export const Edit = ( { className, attributes, setAttributes, clientId } ) => {
+ const { hasDarkControls } = attributes;
+ const { currentView, component: ViewSwitcherComponent } = useViewSwitcher(
+ clientId,
+ [
+ {
+ view: 'woocommerce/filled-cart-block',
+ label: __( 'Filled Cart', 'woo-gutenberg-products-block' ),
+ icon: ,
+ },
+ {
+ view: 'woocommerce/empty-cart-block',
+ label: __( 'Empty Cart', 'woo-gutenberg-products-block' ),
+ icon: ,
+ },
+ ]
+ );
+ const defaultTemplate = [
+ [ 'woocommerce/filled-cart-block', {}, [] ],
+ [ 'woocommerce/empty-cart-block', {}, [] ],
+ ];
+ const blockProps = useBlockPropsWithLocking( {
+ className: classnames( className, 'wp-block-woocommerce-cart', {
+ 'is-editor-preview': attributes.isPreview,
+ } ),
+ } );
+ useForcedLayout( {
+ clientId,
+ registeredBlocks: ALLOWED_BLOCKS,
+ defaultTemplate,
+ } );
return (
-
-
(
-
- { currentView === 'full' && (
- <>
-
-
-
-
-
-
-
-
-
- >
- ) }
- { currentView === 'empty' && }
-
+
+
+ showErrorMessage={ true }
+ errorMessagePrefix={ __(
+ 'Error message:',
+ 'woo-gutenberg-products-block'
+ ) }
+ >
+
+
+
+
+
+
+
+
+
+
+
+
);
};
-CartEditor.propTypes = {
- className: PropTypes.string,
+export const Save = () => {
+ return (
+
+
+
+ );
};
-
-export default CartEditor;
diff --git a/assets/js/blocks/cart-checkout/cart/editor.scss b/assets/js/blocks/cart-checkout/cart/editor.scss
index c8bb25f59bd..d39e5532fbb 100644
--- a/assets/js/blocks/cart-checkout/cart/editor.scss
+++ b/assets/js/blocks/cart-checkout/cart/editor.scss
@@ -2,7 +2,21 @@
margin: 0;
}
-.wp-block-woocommerce-cart.is-editor-preview {
- max-height: 1000px;
- overflow: hidden;
+body.wc-lock-selected-block--move {
+ .block-editor-block-mover__move-button-container,
+ .block-editor-block-mover {
+ display: none;
+ }
}
+
+body.wc-lock-selected-block--remove {
+ .block-editor-block-settings-menu__popover {
+ .components-menu-group:last-child {
+ display: none;
+ }
+ .components-menu-group:nth-last-child(2) {
+ margin-bottom: -12px;
+ }
+ }
+}
+
diff --git a/assets/js/blocks/cart-checkout/cart/empty-cart-edit/icon-data-uri.js b/assets/js/blocks/cart-checkout/cart/empty-cart-edit/icon-data-uri.js
deleted file mode 100644
index d5082ec4a4e..00000000000
--- a/assets/js/blocks/cart-checkout/cart/empty-cart-edit/icon-data-uri.js
+++ /dev/null
@@ -1 +0,0 @@
-export default 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzgiIGhlaWdodD0iMzgiIHZpZXdCb3g9IjAgMCAzOCAzOCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTE5IDBDOC41MDQwMyAwIDAgOC41MDQwMyAwIDE5QzAgMjkuNDk2IDguNTA0MDMgMzggMTkgMzhDMjkuNDk2IDM4IDM4IDI5LjQ5NiAzOCAxOUMzOCA4LjUwNDAzIDI5LjQ5NiAwIDE5IDBaTTI1LjEyOSAxMi44NzFDMjYuNDg1MSAxMi44NzEgMjcuNTgwNiAxMy45NjY1IDI3LjU4MDYgMTUuMzIyNkMyNy41ODA2IDE2LjY3ODYgMjYuNDg1MSAxNy43NzQyIDI1LjEyOSAxNy43NzQyQzIzLjc3MyAxNy43NzQyIDIyLjY3NzQgMTYuNjc4NiAyMi42Nzc0IDE1LjMyMjZDMjIuNjc3NCAxMy45NjY1IDIzLjc3MyAxMi44NzEgMjUuMTI5IDEyLjg3MVpNMTEuNjQ1MiAzMS4yNTgxQzkuNjE0OTIgMzEuMjU4MSA3Ljk2Nzc0IDI5LjY0OTIgNy45Njc3NCAyNy42NTczQzcuOTY3NzQgMjYuMTI1IDEwLjE1MTIgMjMuMDI5OCAxMS4xNTQ4IDIxLjY5NjhDMTEuNCAyMS4zNjczIDExLjg5MDMgMjEuMzY3MyAxMi4xMzU1IDIxLjY5NjhDMTMuMTM5MSAyMy4wMjk4IDE1LjMyMjYgMjYuMTI1IDE1LjMyMjYgMjcuNjU3M0MxNS4zMjI2IDI5LjY0OTIgMTMuNjc1NCAzMS4yNTgxIDExLjY0NTIgMzEuMjU4MVpNMTIuODcxIDE3Ljc3NDJDMTEuNTE0OSAxNy43NzQyIDEwLjQxOTQgMTYuNjc4NiAxMC40MTk0IDE1LjMyMjZDMTAuNDE5NCAxMy45NjY1IDExLjUxNDkgMTIuODcxIDEyLjg3MSAxMi44NzFDMTQuMjI3IDEyLjg3MSAxNS4zMjI2IDEzLjk2NjUgMTUuMzIyNiAxNS4zMjI2QzE1LjMyMjYgMTYuNjc4NiAxNC4yMjcgMTcuNzc0MiAxMi44NzEgMTcuNzc0MlpNMjUuOTEwNSAyOS41ODc5QzI0LjE5NDQgMjcuNTM0NyAyMS42NzM4IDI2LjM1NDggMTkgMjYuMzU0OEMxNy4zNzU4IDI2LjM1NDggMTcuMzc1OCAyMy45MDMyIDE5IDIzLjkwMzJDMjIuNDAxNiAyMy45MDMyIDI1LjYxMTcgMjUuNDA0OCAyNy43ODc1IDI4LjAyNUMyOC44NDQ4IDI5LjI4MTUgMjYuOTI5NCAzMC44MjE0IDI1LjkxMDUgMjkuNTg3OVoiIGZpbGw9ImJsYWNrIi8+Cjwvc3ZnPgo=';
diff --git a/assets/js/blocks/cart-checkout/cart/empty-cart-edit/index.js b/assets/js/blocks/cart-checkout/cart/empty-cart-edit/index.js
deleted file mode 100644
index 8e82550636c..00000000000
--- a/assets/js/blocks/cart-checkout/cart/empty-cart-edit/index.js
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * External dependencies
- */
-import { __, sprintf } from '@wordpress/i18n';
-import { InnerBlocks } from '@wordpress/block-editor';
-import { SHOP_URL } from '@woocommerce/block-settings';
-import PropTypes from 'prop-types';
-
-/**
- * Internal dependencies
- */
-import iconDataUri from './icon-data-uri.js';
-import './style.scss';
-
-const templateItemBrowseStore = SHOP_URL
- ? [
- 'core/paragraph',
- {
- align: 'center',
- content: sprintf(
- /* translators: %s is the link to the store product directory. */
- __(
- 'Browse store .',
- 'woo-gutenberg-products-block'
- ),
- SHOP_URL
- ),
- dropCap: false,
- },
- ]
- : null;
-
-const templateItems = [
- [
- 'core/image',
- {
- align: 'center',
- url: iconDataUri,
- sizeSlug: 'small',
- },
- ],
- [
- 'core/heading',
- {
- textAlign: 'center',
- content: __(
- 'Your cart is currently empty!',
- 'woo-gutenberg-products-block'
- ),
- level: 2,
- className: 'wc-block-cart__empty-cart__title',
- },
- ],
- templateItemBrowseStore,
- [
- 'core/separator',
- {
- className: 'is-style-dots',
- },
- ],
- [
- 'core/heading',
- {
- textAlign: 'center',
- content: __( 'New in store', 'woo-gutenberg-products-block' ),
- level: 2,
- },
- ],
- [
- 'woocommerce/product-new',
- {
- columns: 3,
- rows: 1,
- },
- ],
-].filter( Boolean );
-
-/**
- * Component to handle edit mode for the Cart block when cart is empty.
- *
- * @param {Object} props Incoming props for the component.
- * @param {boolean} props.hidden Whether this component is hidden or not.
- */
-const EmptyCartEdit = ( { hidden = false } ) => {
- return (
-
-
-
- );
-};
-
-EmptyCartEdit.propTypes = {
- hidden: PropTypes.bool,
-};
-
-export default EmptyCartEdit;
diff --git a/assets/js/blocks/cart-checkout/cart/empty-cart-edit/style.scss b/assets/js/blocks/cart-checkout/cart/empty-cart-edit/style.scss
deleted file mode 100644
index e0c402f6ee1..00000000000
--- a/assets/js/blocks/cart-checkout/cart/empty-cart-edit/style.scss
+++ /dev/null
@@ -1,4 +0,0 @@
-.wc-block-cart__empty-cart__title,
-.editor-styles-wrapper .wc-block-cart__empty-cart__title {
- font-size: inherit;
-}
diff --git a/assets/js/blocks/cart-checkout/cart/frontend.js b/assets/js/blocks/cart-checkout/cart/frontend.js
index 014aeb8036f..5c203a92653 100644
--- a/assets/js/blocks/cart-checkout/cart/frontend.js
+++ b/assets/js/blocks/cart-checkout/cart/frontend.js
@@ -5,70 +5,50 @@ import {
withStoreCartApiHydration,
withRestApiHydration,
} from '@woocommerce/block-hocs';
-import { __ } from '@wordpress/i18n';
-import {
- StoreNoticesProvider,
- StoreSnackbarNoticesProvider,
- CartProvider,
-} from '@woocommerce/base-context/providers';
-import { SlotFillProvider } from '@woocommerce/blocks-checkout';
-import { CURRENT_USER_IS_ADMIN } from '@woocommerce/settings';
-import {
- renderFrontend,
- getValidBlockAttributes,
-} from '@woocommerce/base-utils';
+import { getValidBlockAttributes } from '@woocommerce/base-utils';
+import { Children, cloneElement, isValidElement } from '@wordpress/element';
+import { useStoreCart } from '@woocommerce/base-context';
+import { getRegisteredBlockComponents } from '@woocommerce/blocks-registry';
+
+import { renderParentBlock } from '@woocommerce/atomic-utils';
+
/**
* Internal dependencies
*/
-import Block from './block.js';
-import blockAttributes from './attributes';
-
-const reloadPage = () => void window.location.reload( true );
-/**
- * Wrapper component to supply API data and show empty cart view as needed.
- *
- * @param {*} props
- */
-const CartFrontend = ( props ) => {
- return (
-
-
-
-
-
-
-
-
-
- );
-};
+import './inner-blocks/register-components';
+import Block from './block';
+import { blockName, blockAttributes } from './attributes';
const getProps = ( el ) => {
return {
- emptyCart: el.innerHTML,
- attributes: getValidBlockAttributes( blockAttributes, el.dataset ),
+ attributes: getValidBlockAttributes(
+ blockAttributes,
+ !! el ? el.dataset : {}
+ ),
};
};
-const getErrorBoundaryProps = () => {
- return {
- header: __( 'Something went wrong…', 'woo-gutenberg-products-block' ),
- text: __(
- 'The cart has encountered an unexpected error. If the error persists, please get in touch with us for help.',
- 'woo-gutenberg-products-block'
- ),
- showErrorMessage: CURRENT_USER_IS_ADMIN,
- button: (
-
- { __( 'Reload the page', 'woo-gutenberg-products-block' ) }
-
- ),
- };
+const Wrapper = ( { children } ) => {
+ // we need to pluck out receiveCart.
+ // eslint-disable-next-line no-unused-vars
+ const { extensions, receiveCart, ...cart } = useStoreCart();
+ return Children.map( children, ( child ) => {
+ if ( isValidElement( child ) ) {
+ const componentProps = {
+ extensions,
+ cart,
+ };
+ return cloneElement( child, componentProps );
+ }
+ return child;
+ } );
};
-renderFrontend( {
+renderParentBlock( {
+ Block: withStoreCartApiHydration( withRestApiHydration( Block ) ),
+ blockName,
selector: '.wp-block-woocommerce-cart',
- Block: withStoreCartApiHydration( withRestApiHydration( CartFrontend ) ),
getProps,
- getErrorBoundaryProps,
+ blockMap: getRegisteredBlockComponents( blockName ),
+ blockWrapper: Wrapper,
} );
diff --git a/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-items-title.tsx b/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-items-title.tsx
deleted file mode 100644
index d8605a87073..00000000000
--- a/assets/js/blocks/cart-checkout/cart/full-cart/cart-line-items-title.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * External dependencies
- */
-import { _n, sprintf } from '@wordpress/i18n';
-import Title from '@woocommerce/base-components/title';
-
-const CartLineItemsTitle = ( {
- itemCount = 1,
-}: {
- itemCount: number;
-} ): JSX.Element => {
- return (
-
- { sprintf(
- /* translators: %d is the count of items in the cart. */
- _n(
- 'Your cart (%d item)',
- 'Your cart (%d items)',
- itemCount,
- 'woo-gutenberg-products-block'
- ),
- itemCount
- ) }
-
- );
-};
-
-export default CartLineItemsTitle;
diff --git a/assets/js/blocks/cart-checkout/cart/full-cart/index.tsx b/assets/js/blocks/cart-checkout/cart/full-cart/index.tsx
deleted file mode 100644
index 9331ded98df..00000000000
--- a/assets/js/blocks/cart-checkout/cart/full-cart/index.tsx
+++ /dev/null
@@ -1,212 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-import {
- TotalsCoupon,
- TotalsDiscount,
- TotalsFooterItem,
- TotalsShipping,
-} from '@woocommerce/base-components/cart-checkout';
-import {
- Subtotal,
- TotalsFees,
- TotalsTaxes,
- TotalsWrapper,
- ExperimentalOrderMeta,
- ExperimentalDiscountsMeta,
-} from '@woocommerce/blocks-checkout';
-import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
-import {
- useStoreCartCoupons,
- useStoreCart,
- useStoreNotices,
-} from '@woocommerce/base-context/hooks';
-import classnames from 'classnames';
-import {
- Sidebar,
- SidebarLayout,
- Main,
-} from '@woocommerce/base-components/sidebar-layout';
-import Title from '@woocommerce/base-components/title';
-import { getSetting } from '@woocommerce/settings';
-import { useEffect } from '@wordpress/element';
-import { decodeEntities } from '@wordpress/html-entities';
-
-/**
- * Internal dependencies
- */
-import CheckoutButton from '../checkout-button';
-import CartLineItemsTitle from './cart-line-items-title';
-import CartLineItemsTable from './cart-line-items-table';
-import { CartExpressPayment } from '../../payment-methods';
-import './style.scss';
-
-interface CartAttributes {
- hasDarkControls: boolean;
- isShippingCalculatorEnabled: boolean;
- checkoutPageId: number;
- isPreview: boolean;
- showRateAfterTaxName: boolean;
-}
-
-interface CartProps {
- attributes: CartAttributes;
-}
-/**
- * Component that renders the Cart block when user has something in cart aka "full".
- *
- * @param {Object} props Incoming props for the component.
- * @param {Object} props.attributes Incoming attributes for block.
- */
-const Cart = ( { attributes }: CartProps ): JSX.Element => {
- const {
- isShippingCalculatorEnabled,
- hasDarkControls,
- showRateAfterTaxName,
- } = attributes;
-
- const {
- cartItems,
- cartFees,
- cartTotals,
- cartIsLoading,
- cartItemsCount,
- cartItemErrors,
- cartNeedsPayment,
- cartNeedsShipping,
- } = useStoreCart();
-
- const {
- applyCoupon,
- removeCoupon,
- isApplyingCoupon,
- isRemovingCoupon,
- appliedCoupons,
- } = useStoreCartCoupons();
-
- const { addErrorNotice } = useStoreNotices();
-
- // Ensures any cart errors listed in the API response get shown.
- useEffect( () => {
- cartItemErrors.forEach( ( error ) => {
- addErrorNotice( decodeEntities( error.message ), {
- isDismissible: true,
- id: error.code,
- } );
- } );
- }, [ addErrorNotice, cartItemErrors ] );
-
- const totalsCurrency = getCurrencyFromPriceResponse( cartTotals );
-
- const cartClassName = classnames( 'wc-block-cart', {
- 'wc-block-cart--is-loading': cartIsLoading,
- 'has-dark-controls': hasDarkControls,
- } );
-
- // Prepare props to pass to the ExperimentalOrderMeta slot fill.
- // We need to pluck out receiveCart.
- // eslint-disable-next-line no-unused-vars
- const { extensions, receiveCart, ...cart } = useStoreCart();
- const slotFillProps = {
- extensions,
- cart,
- };
-
- const discountsSlotFillProps = {
- extensions,
- cart,
- };
-
- return (
- <>
-
-
-
-
-
-
-
- { __( 'Cart totals', 'woo-gutenberg-products-block' ) }
-
-
-
-
-
-
- { getSetting( 'couponsEnabled', true ) && (
-
-
-
- ) }
-
- { cartNeedsShipping && (
-
-
-
- ) }
- { ! getSetting( 'displayCartPricesIncludingTax', false ) &&
- parseInt( cartTotals.total_tax, 10 ) > 0 && (
-
-
-
- ) }
-
-
-
-
-
-
-
- { cartNeedsPayment && }
-
-
-
-
- >
- );
-};
-
-export default Cart;
diff --git a/assets/js/blocks/cart-checkout/cart/full-cart/style.scss b/assets/js/blocks/cart-checkout/cart/full-cart/style.scss
deleted file mode 100644
index e3ddb16c43b..00000000000
--- a/assets/js/blocks/cart-checkout/cart/full-cart/style.scss
+++ /dev/null
@@ -1,264 +0,0 @@
-.wc-block-cart {
- .wc-block-components-shipping-calculator {
- white-space: nowrap;
- }
-
- .wc-block-components-address-form {
- .wc-block-components-text-input,
- .wc-block-components-country-input,
- .wc-block-components-state-input {
- &:first-of-type {
- margin-top: 0;
- }
- }
- }
-}
-
-table.wc-block-cart-items,
-table.wc-block-cart-items th,
-table.wc-block-cart-items td {
- // Override Storefront theme gray table background.
- background: none !important;
- // Remove borders on default themes.
- border: 0;
- margin: 0;
-}
-
-.editor-styles-wrapper table.wc-block-cart-items,
-table.wc-block-cart-items {
- width: 100%;
-
- .wc-block-cart-items__header {
- @include font-size(smaller);
- text-transform: uppercase;
-
- .wc-block-cart-items__header-image {
- width: 100px;
- }
- .wc-block-cart-items__header-product {
- visibility: hidden;
- }
- .wc-block-cart-items__header-total {
- width: 100px;
- text-align: right;
- }
- }
- .wc-block-cart-items__row {
- .wc-block-cart-item__image img {
- width: 100%;
- margin: 0;
- }
- .wc-block-cart-item__quantity {
- .wc-block-cart-item__remove-link {
- @include link-button;
- @include font-size(smaller);
-
- text-transform: none;
- white-space: nowrap;
- }
- }
- .wc-block-components-product-name {
- display: block;
- max-width: max-content;
- }
- .wc-block-cart-item__total {
- @include font-size(regular);
- text-align: right;
- line-height: inherit;
- }
- .wc-block-components-product-metadata {
- margin-bottom: 0.75em;
- }
-
- &.is-disabled {
- opacity: 0.5;
- pointer-events: none;
- transition: opacity 200ms ease;
- }
- }
-}
-
-.wc-block-cart {
- .wc-block-components-totals-taxes,
- .wc-block-components-totals-footer-item {
- margin: 0;
- }
-}
-
-// Loading placeholder state.
-.wc-block-cart--is-loading,
-.wc-block-mini-cart__drawer.is-loading {
- th span,
- h2 span {
- @include placeholder();
- @include force-content();
- min-width: 84px;
- display: inline-block;
- }
- h2 span {
- min-width: 33%;
- }
- .wc-block-components-product-price,
- .wc-block-components-product-metadata,
- .wc-block-components-quantity-selector {
- @include placeholder();
- }
- .wc-block-components-product-name {
- @include placeholder();
- @include force-content();
- min-width: 84px;
- display: inline-block;
- }
- .wc-block-components-product-metadata {
- margin-top: 0.25em;
- min-width: 8em;
- }
- .wc-block-cart-item__remove-link {
- visibility: hidden;
- }
- .wc-block-cart-item__image > a {
- @include placeholder();
- display: block;
- }
- .wc-block-components-product-price {
- @include force-content();
- max-width: 3em;
- display: block;
- margin-top: 0.25em;
- }
- .wc-block-cart__sidebar .components-card {
- @include placeholder();
- @include force-content();
- min-height: 460px;
- }
-}
-.wc-block-components-sidebar-layout.wc-block-cart--skeleton {
- display: none;
-}
-.is-loading + .wc-block-components-sidebar-layout.wc-block-cart--skeleton {
- display: flex;
-}
-
-.wc-block-cart-item__total-price-and-sale-badge-wrapper {
- display: flex;
- flex-direction: column;
- align-items: flex-end;
-
- .wc-block-components-sale-badge {
- margin-top: $gap-smallest;
- }
-}
-
-.is-small,
-.is-mobile {
- .wc-block-cart-item__total {
- .wc-block-components-sale-badge {
- display: none;
- }
- }
-}
-
-.is-medium,
-.is-small,
-.is-mobile {
- &.wc-block-cart {
- .wc-block-components-sidebar {
- .wc-block-cart__totals-title {
- display: none;
- }
- }
- }
- table.wc-block-cart-items {
- td {
- padding: 0;
- }
- .wc-block-cart-items__header {
- display: none;
- }
- .wc-block-cart-item__remove-link {
- display: none;
- }
- .wc-block-cart-items__row {
- @include with-translucent-border(0 0 1px);
- display: grid;
- grid-template-columns: 80px 132px;
- padding: $gap 0;
-
- .wc-block-cart-item__image {
- grid-column-start: 1;
- grid-row-start: 1;
- padding-right: $gap;
- }
- .wc-block-cart-item__product {
- grid-column-start: 2;
- grid-column-end: 4;
- grid-row-start: 1;
- justify-self: stretch;
- padding: 0 $gap $gap 0;
- }
- .wc-block-cart-item__quantity {
- grid-column-start: 1;
- grid-row-start: 2;
- vertical-align: bottom;
- padding-right: $gap;
- align-self: end;
- padding-top: $gap;
- }
- .wc-block-cart-item__total {
- grid-row-start: 1;
-
- .wc-block-components-formatted-money-amount {
- display: inline-block;
- }
- }
- }
- }
-}
-
-.is-large.wp-block-woocommerce-cart {
- .wc-block-cart-items {
- @include with-translucent-border(0 0 1px);
-
- th {
- padding: 0.25rem $gap 0.25rem 0;
- white-space: nowrap;
- }
- td {
- @include with-translucent-border(1px 0 0);
- padding: $gap 0 $gap $gap;
- vertical-align: top;
- }
- th:last-child {
- padding-right: 0;
- }
- td:last-child {
- padding-right: $gap;
- }
- }
-
- .wc-block-components-radio-control__input {
- left: 0;
- }
-
- .wc-block-cart__totals-title {
- @include text-heading();
- @include font-size(smaller);
- display: block;
- font-weight: 600;
- padding: 0.25rem 0;
- text-align: right;
- text-transform: uppercase;
- }
-
- .wc-block-components-sidebar {
- .wc-block-components-shipping-calculator,
- .wc-block-components-shipping-rates-control__package:not(.wc-block-components-panel) {
- padding-left: $gap;
- padding-right: $gap;
- }
- }
-
- .wc-block-cart__payment-options {
- padding: $gap;
- }
-}
diff --git a/assets/js/blocks/cart-checkout/cart/index.js b/assets/js/blocks/cart-checkout/cart/index.js
index 3e4b084697e..8fb9631e24c 100644
--- a/assets/js/blocks/cart-checkout/cart/index.js
+++ b/assets/js/blocks/cart-checkout/cart/index.js
@@ -2,16 +2,18 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
+import classnames from 'classnames';
import { InnerBlocks } from '@wordpress/block-editor';
import { Icon, cart } from '@woocommerce/icons';
-import classnames from 'classnames';
import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
+import { createBlock } from '@wordpress/blocks';
/**
* Internal dependencies
*/
-import edit from './edit';
+import { Edit, Save } from './edit';
import './style.scss';
-import blockAttributes from './attributes';
+import { blockName, blockAttributes } from './attributes';
+import './inner-blocks';
/**
* Register and run the Cart block.
@@ -29,6 +31,7 @@ const settings = {
align: [ 'wide', 'full' ],
html: false,
multiple: false,
+ __experimentalExposeControlsToChildren: true,
},
example: {
attributes: {
@@ -36,16 +39,70 @@ const settings = {
},
},
attributes: blockAttributes,
- edit,
-
- // Save the props to post content.
- save( { attributes } ) {
- return (
-
-
-
- );
- },
+ edit: Edit,
+ save: Save,
+ // Migrates v1 to v2 checkout.
+ deprecated: [
+ {
+ attributes: blockAttributes,
+ save: ( { attributes } ) => {
+ return (
+
+
+
+ );
+ },
+ migrate: ( attributes, innerBlocks ) => {
+ const {
+ isShippingCalculatorEnabled,
+ showRateAfterTaxName,
+ checkoutPageId,
+ } = attributes;
+ return [
+ attributes,
+ [
+ createBlock( 'woocommerce/filled-cart-block', {}, [
+ createBlock( 'woocommerce/cart-items-block' ),
+ createBlock( 'woocommerce/cart-totals-block', {}, [
+ createBlock(
+ 'woocommerce/cart-order-summary-block',
+ {
+ isShippingCalculatorEnabled,
+ showRateAfterTaxName,
+ }
+ ),
+ createBlock(
+ 'woocommerce/cart-express-payment-block'
+ ),
+ createBlock(
+ 'woocommerce/proceed-to-checkout-block',
+ { checkoutPageId }
+ ),
+ createBlock(
+ 'woocommerce/cart-accepted-payment-methods-block'
+ ),
+ ] ),
+ ] ),
+ createBlock(
+ 'woocommerce/empty-cart-block',
+ {},
+ innerBlocks
+ ),
+ ],
+ ];
+ },
+ isEligible: ( _, innerBlocks ) => {
+ return ! innerBlocks.find(
+ ( block ) => block.name === 'woocommerce/filled-cart-block'
+ );
+ },
+ },
+ ],
};
-registerFeaturePluginBlockType( 'woocommerce/cart', settings );
+registerFeaturePluginBlockType( blockName, settings );
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/block.json
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/block.json
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/block.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/block.tsx
similarity index 73%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/block.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/block.tsx
index 6f7c549d38f..46711e65077 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/block.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/block.tsx
@@ -3,21 +3,20 @@
*/
import { PaymentMethodIcons } from '@woocommerce/base-components/cart-checkout';
import { usePaymentMethods } from '@woocommerce/base-context/hooks';
-
-/**
- * Internal dependencies
- */
-import type PaymentMethodConfig from '../../../../../blocks-registry/payment-methods/payment-method-config';
+import type {
+ PaymentMethods,
+ PaymentMethodIcons as PaymentMethodIconsType,
+} from '@woocommerce/type-defs/payments';
const getIconsFromPaymentMethods = (
- paymentMethods: PaymentMethodConfig[]
-) => {
+ paymentMethods: PaymentMethods
+): PaymentMethodIconsType => {
return Object.values( paymentMethods ).reduce( ( acc, paymentMethod ) => {
if ( paymentMethod.icons !== null ) {
acc = acc.concat( paymentMethod.icons );
}
return acc;
- }, [] );
+ }, [] as PaymentMethodIconsType );
};
const Block = (): JSX.Element => {
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/edit.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/edit.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/frontend.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/frontend.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/frontend.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/frontend.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/index.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-accepted-payment-methods-block/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-accepted-payment-methods-block/index.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/block.json
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/block.json
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/block.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/block.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/block.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/block.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/edit.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/edit.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/editor.scss b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/editor.scss
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/editor.scss
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/editor.scss
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/index.tsx
similarity index 70%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/index.tsx
index 239e7897c98..4be55d59f63 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-express-payment-block/index.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-express-payment-block/index.tsx
@@ -2,7 +2,7 @@
* External dependencies
*/
import { Icon, card } from '@woocommerce/icons';
-import { registerExperimentalBlockType } from '@woocommerce/block-settings';
+import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
@@ -10,7 +10,7 @@ import { registerExperimentalBlockType } from '@woocommerce/block-settings';
import { Edit, Save } from './edit';
import metadata from './block.json';
-registerExperimentalBlockType( metadata, {
+registerFeaturePluginBlockType( metadata, {
icon: {
src: ,
foreground: '#7f54b3',
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/block.json
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/block.json
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/edit.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/edit.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/frontend.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/frontend.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/frontend.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/frontend.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/index.tsx
similarity index 70%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/index.tsx
index cbe5a0f4ded..fa2a199ed84 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/index.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-items-block/index.tsx
@@ -2,7 +2,7 @@
* External dependencies
*/
import { Icon, column } from '@wordpress/icons';
-import { registerExperimentalBlockType } from '@woocommerce/block-settings';
+import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
@@ -10,7 +10,7 @@ import { registerExperimentalBlockType } from '@woocommerce/block-settings';
import { Edit, Save } from './edit';
import metadata from './block.json';
-registerExperimentalBlockType( metadata, {
+registerFeaturePluginBlockType( metadata, {
icon: {
src: ,
foreground: '#7f54b3',
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/block.json
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/block.json
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/block.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/block.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/block.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/block.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/edit.tsx
similarity index 80%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/edit.tsx
index 02e80d12571..b66efd4944b 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-line-items-block/edit.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/edit.tsx
@@ -2,6 +2,7 @@
* External dependencies
*/
import { useBlockProps } from '@wordpress/block-editor';
+import { Disabled } from '@wordpress/components';
/**
* Internal dependencies
@@ -13,7 +14,9 @@ export const Edit = (): JSX.Element => {
return (
-
+
+
+
);
};
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/index.tsx
similarity index 70%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/index.tsx
index cbe5a0f4ded..fa2a199ed84 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-items-block/index.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-line-items-block/index.tsx
@@ -2,7 +2,7 @@
* External dependencies
*/
import { Icon, column } from '@wordpress/icons';
-import { registerExperimentalBlockType } from '@woocommerce/block-settings';
+import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
@@ -10,7 +10,7 @@ import { registerExperimentalBlockType } from '@woocommerce/block-settings';
import { Edit, Save } from './edit';
import metadata from './block.json';
-registerExperimentalBlockType( metadata, {
+registerFeaturePluginBlockType( metadata, {
icon: {
src: ,
foreground: '#7f54b3',
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/attributes.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/attributes.tsx
similarity index 71%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/attributes.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/attributes.tsx
index ecb4a15c3b4..5a449d32bfa 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/attributes.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/attributes.tsx
@@ -4,6 +4,10 @@
import { getSetting } from '@woocommerce/settings';
export default {
+ isShippingCalculatorEnabled: {
+ type: 'boolean',
+ default: getSetting( 'isShippingCalculatorEnabled', true ),
+ },
showRateAfterTaxName: {
type: 'boolean',
default: getSetting( 'displayCartPricesIncludingTax', false ),
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/block.json
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/block.json
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/block.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/block.tsx
similarity index 97%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/block.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/block.tsx
index a8f338bad26..13209e2296e 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/block.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/block.tsx
@@ -50,7 +50,7 @@ const Block = ( {
// Prepare props to pass to the ExperimentalOrderMeta slot fill.
// We need to pluck out receiveCart.
// eslint-disable-next-line no-unused-vars
- const { extensions, ...cart } = useStoreCart();
+ const { extensions, receiveCart, ...cart } = useStoreCart();
const slotFillProps = {
extensions,
cart,
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/edit.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/edit.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/frontend.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/frontend.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/frontend.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/frontend.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/index.tsx
similarity index 74%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/index.tsx
index b18e405ea71..9925750013f 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-order-summary-block/index.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-order-summary-block/index.tsx
@@ -2,7 +2,7 @@
* External dependencies
*/
import { Icon, totals } from '@woocommerce/icons';
-import { registerExperimentalBlockType } from '@woocommerce/block-settings';
+import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
@@ -11,7 +11,7 @@ import { Edit, Save } from './edit';
import attributes from './attributes';
import metadata from './block.json';
-registerExperimentalBlockType( metadata, {
+registerFeaturePluginBlockType( metadata, {
icon: {
src: ,
foreground: '#7f54b3',
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/block.json
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/block.json
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/edit.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/edit.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/frontend.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/frontend.tsx
similarity index 89%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/frontend.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/frontend.tsx
index b5f68b9fc89..db443a385e1 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/frontend.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/frontend.tsx
@@ -11,7 +11,7 @@ import './style.scss';
const FrontendBlock = ( {
children,
}: {
- children: JSX.Element;
+ children: JSX.Element | JSX.Element[];
} ): JSX.Element => {
return { children } ;
};
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/index.tsx
similarity index 70%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/index.tsx
index cbe5a0f4ded..fa2a199ed84 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/index.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/index.tsx
@@ -2,7 +2,7 @@
* External dependencies
*/
import { Icon, column } from '@wordpress/icons';
-import { registerExperimentalBlockType } from '@woocommerce/block-settings';
+import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
@@ -10,7 +10,7 @@ import { registerExperimentalBlockType } from '@woocommerce/block-settings';
import { Edit, Save } from './edit';
import metadata from './block.json';
-registerExperimentalBlockType( metadata, {
+registerFeaturePluginBlockType( metadata, {
icon: {
src: ,
foreground: '#7f54b3',
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/style.scss b/assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/style.scss
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/cart-totals-block/style.scss
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/cart-totals-block/style.scss
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/empty-cart-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/empty-cart-block/block.json
similarity index 87%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/empty-cart-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/empty-cart-block/block.json
index 0119c8fe7f2..001b468af3d 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/empty-cart-block/block.json
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/empty-cart-block/block.json
@@ -5,7 +5,7 @@
"description": "Contains blocks that are displayed when the cart is empty.",
"category": "woocommerce",
"supports": {
- "align": false,
+ "align": [ "wide", "full" ],
"html": false,
"multiple": false,
"reusable": false,
@@ -20,7 +20,7 @@
}
}
},
- "parent": [ "woocommerce/cart-i2" ],
+ "parent": [ "woocommerce/cart" ],
"textdomain": "woo-gutenberg-products-block",
"apiVersion": 2
}
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/empty-cart-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/empty-cart-block/edit.tsx
similarity index 98%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/empty-cart-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/empty-cart-block/edit.tsx
index 80f67b0f1ba..78dc6abdb09 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/empty-cart-block/edit.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/empty-cart-block/edit.tsx
@@ -13,6 +13,7 @@ import { SHOP_URL } from '@woocommerce/block-settings';
*/
import { useForcedLayout, getAllowedBlocks } from '../../../shared';
import iconDataUri from './icon-data-uri.js';
+import './style.scss';
const browseStoreTemplate = SHOP_URL
? [
@@ -94,7 +95,6 @@ export const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {
hidden={ currentView !== 'woocommerce/empty-cart-block' }
>
,
foreground: '#7f54b3',
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/empty-cart-block/style.scss b/assets/js/blocks/cart-checkout/cart/inner-blocks/empty-cart-block/style.scss
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/empty-cart-block/style.scss
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/empty-cart-block/style.scss
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/block.json
similarity index 88%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/block.json
index 3eeea67ac5d..3165c8215b5 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/block.json
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/block.json
@@ -5,7 +5,7 @@
"description": "Contains blocks that are displayed when the cart contains products.",
"category": "woocommerce",
"supports": {
- "align": false,
+ "align": [ "wide", "full" ],
"html": false,
"multiple": false,
"reusable": false,
@@ -20,7 +20,7 @@
}
}
},
- "parent": [ "woocommerce/cart-i2" ],
+ "parent": [ "woocommerce/cart" ],
"textdomain": "woo-gutenberg-products-block",
"apiVersion": 2
}
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/edit.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/edit.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/editor.scss b/assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/editor.scss
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/editor.scss
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/editor.scss
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/frontend.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/frontend.tsx
similarity index 96%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/frontend.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/frontend.tsx
index 9951e381d7a..34f9bfef672 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/frontend.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/frontend.tsx
@@ -15,7 +15,7 @@ import { useCartBlockContext } from '../../context';
const FrontendBlock = ( {
children,
}: {
- children: JSX.Element;
+ children: JSX.Element | JSX.Element[];
} ): JSX.Element | null => {
const { cartItems, cartIsLoading, cartItemErrors } = useStoreCart();
const { hasDarkControls } = useCartBlockContext();
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/index.tsx
similarity index 71%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/index.tsx
index 6ba3a6d388a..79b213cd6a3 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/filled-cart-block/index.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/filled-cart-block/index.tsx
@@ -2,7 +2,7 @@
* External dependencies
*/
import { Icon, filledCart } from '@woocommerce/icons';
-import { registerExperimentalBlockType } from '@woocommerce/block-settings';
+import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
@@ -10,7 +10,7 @@ import { registerExperimentalBlockType } from '@woocommerce/block-settings';
import { Edit, Save } from './edit';
import metadata from './block.json';
-registerExperimentalBlockType( metadata, {
+registerFeaturePluginBlockType( metadata, {
icon: {
src: ,
foreground: '#7f54b3',
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/index.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/index.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/attributes.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/attributes.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/attributes.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/attributes.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/block.json b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/block.json
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/block.json
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/block.json
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/block.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/block.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/block.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/block.tsx
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/edit.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/edit.tsx
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/edit.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/edit.tsx
diff --git a/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/frontend.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/frontend.tsx
new file mode 100644
index 00000000000..37602e61842
--- /dev/null
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/frontend.tsx
@@ -0,0 +1,12 @@
+/**
+ * External dependencies
+ */
+import withFilteredAttributes from '@woocommerce/base-hocs/with-filtered-attributes';
+
+/**
+ * Internal dependencies
+ */
+import Block from './block';
+import attributes from './attributes';
+
+export default withFilteredAttributes( attributes )( Block );
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/index.tsx b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/index.tsx
similarity index 73%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/index.tsx
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/index.tsx
index c103d035902..189e452ee5c 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/index.tsx
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/index.tsx
@@ -2,7 +2,7 @@
* External dependencies
*/
import { Icon, button } from '@wordpress/icons';
-import { registerExperimentalBlockType } from '@woocommerce/block-settings';
+import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
/**
* Internal dependencies
@@ -11,7 +11,7 @@ import attributes from './attributes';
import { Edit, Save } from './edit';
import metadata from './block.json';
-registerExperimentalBlockType( metadata, {
+registerFeaturePluginBlockType( metadata, {
icon: {
src: ,
foreground: '#7f54b3',
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/style.scss b/assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/style.scss
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/proceed-to-checkout-block/style.scss
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/proceed-to-checkout-block/style.scss
diff --git a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/register-components.ts b/assets/js/blocks/cart-checkout/cart/inner-blocks/register-components.ts
similarity index 99%
rename from assets/js/blocks/cart-checkout/cart-i2/inner-blocks/register-components.ts
rename to assets/js/blocks/cart-checkout/cart/inner-blocks/register-components.ts
index 74b480be354..09de5c2e619 100644
--- a/assets/js/blocks/cart-checkout/cart-i2/inner-blocks/register-components.ts
+++ b/assets/js/blocks/cart-checkout/cart/inner-blocks/register-components.ts
@@ -89,7 +89,7 @@ registerCheckoutBlock( {
metadata: cartOrderSummaryMetadata,
component: lazy( () =>
import(
- /* webpackChunkName: "cart-blocks/order-summary" */ './cart-order-summary-block/block'
+ /* webpackChunkName: "cart-blocks/order-summary" */ './cart-order-summary-block/frontend'
)
),
} );
diff --git a/assets/js/blocks/cart-checkout/cart/style.scss b/assets/js/blocks/cart-checkout/cart/style.scss
index 8c72f08fdfd..245141feff7 100644
--- a/assets/js/blocks/cart-checkout/cart/style.scss
+++ b/assets/js/blocks/cart-checkout/cart/style.scss
@@ -1,7 +1,273 @@
-.wp-block-woocommerce-cart.is-loading {
+.wc-block-cart {
+ .wc-block-components-shipping-calculator {
+ white-space: nowrap;
+ }
+
+ .wc-block-components-address-form {
+ .wc-block-components-text-input,
+ .wc-block-components-country-input,
+ .wc-block-components-state-input {
+ &:first-of-type {
+ margin-top: 0;
+ }
+ }
+ }
+}
+
+table.wc-block-cart-items,
+table.wc-block-cart-items th,
+table.wc-block-cart-items td {
+ // Override Storefront theme gray table background.
+ background: none !important;
+ // Remove borders on default themes.
+ border: 0;
+ margin: 0;
+}
+
+.editor-styles-wrapper table.wc-block-cart-items,
+table.wc-block-cart-items {
+ width: 100%;
+
+ .wc-block-cart-items__header {
+ @include font-size(smaller);
+ text-transform: uppercase;
+
+ .wc-block-cart-items__header-image {
+ width: 100px;
+ }
+ .wc-block-cart-items__header-product {
+ visibility: hidden;
+ }
+ .wc-block-cart-items__header-total {
+ width: 100px;
+ text-align: right;
+ }
+ }
+ .wc-block-cart-items__row {
+ .wc-block-cart-item__image img {
+ width: 100%;
+ margin: 0;
+ }
+ .wc-block-cart-item__quantity {
+ .wc-block-cart-item__remove-link {
+ @include link-button;
+ @include font-size(smaller);
+
+ text-transform: none;
+ white-space: nowrap;
+ }
+ }
+ .wc-block-components-product-name {
+ display: block;
+ max-width: max-content;
+ }
+ .wc-block-cart-item__total {
+ @include font-size(regular);
+ text-align: right;
+ line-height: inherit;
+ }
+ .wc-block-components-product-metadata {
+ margin-bottom: 0.75em;
+ }
+
+ &.is-disabled {
+ opacity: 0.5;
+ pointer-events: none;
+ transition: opacity 200ms ease;
+ }
+ }
+}
+
+.wc-block-cart {
+ .wc-block-components-totals-taxes,
+ .wc-block-components-totals-footer-item {
+ margin: 0;
+ }
+}
+
+// Loading placeholder state.
+.wc-block-cart--is-loading,
+.wc-block-mini-cart__drawer.is-loading {
+ th span,
+ h2 span {
+ @include placeholder();
+ @include force-content();
+ min-width: 84px;
+ display: inline-block;
+ }
+ h2 span {
+ min-width: 33%;
+ }
+ .wc-block-components-product-price,
+ .wc-block-components-product-metadata,
+ .wc-block-components-quantity-selector {
+ @include placeholder();
+ }
+ .wc-block-components-product-name {
+ @include placeholder();
+ @include force-content();
+ min-width: 84px;
+ display: inline-block;
+ }
+ .wc-block-components-product-metadata {
+ margin-top: 0.25em;
+ min-width: 8em;
+ }
+ .wc-block-cart-item__remove-link {
+ visibility: hidden;
+ }
+ .wc-block-cart-item__image > a {
+ @include placeholder();
+ display: block;
+ }
+ .wc-block-components-product-price {
+ @include force-content();
+ max-width: 3em;
+ display: block;
+ margin-top: 0.25em;
+ }
+ .wc-block-cart__sidebar .components-card {
+ @include placeholder();
+ @include force-content();
+ min-height: 460px;
+ }
+}
+.wc-block-components-sidebar-layout.wc-block-cart--skeleton {
display: none;
}
+.is-loading + .wc-block-components-sidebar-layout.wc-block-cart--skeleton {
+ display: flex;
+}
+
+.wc-block-cart-item__total-price-and-sale-badge-wrapper {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-end;
-.wp-block-woocommerce-cart {
+ .wc-block-components-sale-badge {
+ margin-top: $gap-smallest;
+ }
+}
+
+.is-small,
+.is-mobile {
+ .wc-block-cart-item__total {
+ .wc-block-components-sale-badge {
+ display: none;
+ }
+ }
+}
+
+.is-medium,
+.is-small,
+.is-mobile {
+ &.wc-block-cart {
+ .wc-block-components-sidebar {
+ .wc-block-cart__totals-title {
+ display: none;
+ }
+ }
+ }
+ table.wc-block-cart-items {
+ td {
+ padding: 0;
+ }
+ .wc-block-cart-items__header {
+ display: none;
+ }
+ .wc-block-cart-item__remove-link {
+ display: none;
+ }
+ .wc-block-cart-items__row {
+ @include with-translucent-border(0 0 1px);
+ display: grid;
+ grid-template-columns: 80px 132px;
+ padding: $gap 0;
+
+ .wc-block-cart-item__image {
+ grid-column-start: 1;
+ grid-row-start: 1;
+ padding-right: $gap;
+ }
+ .wc-block-cart-item__product {
+ grid-column-start: 2;
+ grid-column-end: 4;
+ grid-row-start: 1;
+ justify-self: stretch;
+ padding: 0 $gap $gap 0;
+ }
+ .wc-block-cart-item__quantity {
+ grid-column-start: 1;
+ grid-row-start: 2;
+ vertical-align: bottom;
+ padding-right: $gap;
+ align-self: end;
+ padding-top: $gap;
+ }
+ .wc-block-cart-item__total {
+ grid-row-start: 1;
+
+ .wc-block-components-formatted-money-amount {
+ display: inline-block;
+ }
+ }
+ }
+ }
+}
+
+.is-large.wc-block-cart {
margin-bottom: 3em;
+
+ .wc-block-cart-items {
+ @include with-translucent-border(0 0 1px);
+
+ th {
+ padding: 0.25rem $gap 0.25rem 0;
+ white-space: nowrap;
+ }
+ td {
+ @include with-translucent-border(1px 0 0);
+ padding: $gap 0 $gap $gap;
+ vertical-align: top;
+ }
+ th:last-child {
+ padding-right: 0;
+ }
+ td:last-child {
+ padding-right: $gap;
+ }
+ }
+
+ .wc-block-cart__sidebar {
+ & > div:not(.wc-block-components-totals-wrapper) {
+ margin-left: $gap;
+ margin-right: $gap;
+ }
+ }
+
+ .wc-block-components-radio-control__input {
+ left: 0;
+ }
+
+ .wc-block-cart__totals-title {
+ @include text-heading();
+ @include font-size(smaller);
+ display: block;
+ font-weight: 600;
+ padding: 0.25rem 0;
+ text-align: right;
+ text-transform: uppercase;
+ }
+
+ .wc-block-components-sidebar {
+ .wc-block-components-shipping-calculator,
+ .wc-block-components-shipping-rates-control__package:not(.wc-block-components-panel) {
+ padding-left: $gap;
+ padding-right: $gap;
+ }
+ }
+
+ .wc-block-cart__payment-options {
+ padding: $gap 0 0;
+ }
}
diff --git a/assets/js/blocks/cart-checkout/cart/test/__snapshots__/block.js.snap b/assets/js/blocks/cart-checkout/cart/test/__snapshots__/block.js.snap
deleted file mode 100644
index 0512ed58c55..00000000000
--- a/assets/js/blocks/cart-checkout/cart/test/__snapshots__/block.js.snap
+++ /dev/null
@@ -1,2066 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Testing cart Contains a Taxes section if Core options are set to show it 1`] = `
-
-
-
-
-
- Your cart (3 items)
-
-
-
-
-
-`;
-
-exports[`Testing cart Shows individual tax lines if the store is set to do so 1`] = `
-
-
-
-
-
- Your cart (3 items)
-
-
-
-
-
-`;
-
-exports[`Testing cart Shows rate percentages after tax lines if the block is set to do so 1`] = `
-
-
-
-
-
- Your cart (3 items)
-
-
-
-
-
-`;
diff --git a/assets/js/blocks/cart-checkout/cart/test/block.js b/assets/js/blocks/cart-checkout/cart/test/block.js
index b615dd9d755..9b5ca728649 100644
--- a/assets/js/blocks/cart-checkout/cart/test/block.js
+++ b/assets/js/blocks/cart-checkout/cart/test/block.js
@@ -5,21 +5,64 @@ import { render, screen, waitFor } from '@testing-library/react';
import { previewCart } from '@woocommerce/resource-previews';
import { dispatch } from '@wordpress/data';
import { CART_STORE_KEY as storeKey } from '@woocommerce/block-data';
-import { SlotFillProvider } from '@woocommerce/blocks-checkout';
import { default as fetchMock } from 'jest-fetch-mock';
-
/**
* Internal dependencies
*/
-import Block from '../block';
import { defaultCartState } from '../../../../data/default-states';
import { allSettings } from '../../../../settings/shared/settings-init';
-const CartBlock = ( props ) => (
-
-
-
-);
+import Cart from '../block';
+
+import FilledCart from '../inner-blocks/filled-cart-block/frontend';
+import EmptyCart from '../inner-blocks/empty-cart-block/frontend';
+
+import ItemsBlock from '../inner-blocks/cart-items-block/frontend';
+import TotalsBlock from '../inner-blocks/cart-totals-block/frontend';
+
+import LineItemsBlock from '../inner-blocks/cart-line-items-block/block';
+import OrderSummaryBlock from '../inner-blocks/cart-order-summary-block/block';
+import ExpressPaymentBlock from '../inner-blocks/cart-express-payment-block/block';
+import ProceedToCheckoutBlock from '../inner-blocks/proceed-to-checkout-block/block';
+import AcceptedPaymentMethodsIcons from '../inner-blocks/cart-accepted-payment-methods-block/block';
+
+const CartBlock = ( {
+ attributes = {
+ showRateAfterTaxName: false,
+ isShippingCalculatorEnabled: false,
+ checkoutPageId: 0,
+ },
+} ) => {
+ const {
+ showRateAfterTaxName,
+ isShippingCalculatorEnabled,
+ checkoutPageId,
+ } = attributes;
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Empty Cart
+
+
+ );
+};
+
describe( 'Testing cart', () => {
beforeEach( async () => {
fetchMock.mockResponse( ( req ) => {
@@ -38,14 +81,7 @@ describe( 'Testing cart', () => {
} );
it( 'renders cart if there are items in the cart', async () => {
- render(
-
- );
+ render( );
await waitFor( () => expect( fetchMock ).toHaveBeenCalled() );
expect(
screen.getByText( /Proceed to Checkout/i )
@@ -60,16 +96,10 @@ describe( 'Testing cart', () => {
allSettings.displayCartPricesIncludingTax = false;
// The criteria for showing the Taxes section is:
// Display prices during basket and checkout: 'Excluding tax'.
- const { container } = render(
-
- );
+ render( );
+
await waitFor( () => expect( fetchMock ).toHaveBeenCalled() );
- expect( container ).toMatchSnapshot();
+ expect( screen.getByText( /Tax/i ) ).toBeInTheDocument();
} );
it( 'Shows individual tax lines if the store is set to do so', async () => {
@@ -78,16 +108,9 @@ describe( 'Testing cart', () => {
// The criteria for showing the lines in the Taxes section is:
// Display prices during basket and checkout: 'Excluding tax'.
// Display tax totals: 'Itemized';
- const { container } = render(
-
- );
+ render( );
await waitFor( () => expect( fetchMock ).toHaveBeenCalled() );
- expect( container ).toMatchSnapshot();
+ expect( screen.getByText( /Sales tax/i ) ).toBeInTheDocument();
} );
it( 'Shows rate percentages after tax lines if the block is set to do so', async () => {
@@ -96,17 +119,15 @@ describe( 'Testing cart', () => {
// The criteria for showing the lines in the Taxes section is:
// Display prices during basket and checkout: 'Excluding tax'.
// Display tax totals: 'Itemized';
- const { container } = render(
+ render(
);
await waitFor( () => expect( fetchMock ).toHaveBeenCalled() );
- expect( container ).toMatchSnapshot();
+ expect( screen.getByText( /Sales tax 20%/i ) ).toBeInTheDocument();
} );
it( 'renders empty cart if there are no items in the cart', async () => {
@@ -118,14 +139,7 @@ describe( 'Testing cart', () => {
}
return Promise.resolve( '' );
} );
- render(
- Empty Cart ' }
- attributes={ {
- isShippingCalculatorEnabled: false,
- } }
- />
- );
+ render( );
await waitFor( () => expect( fetchMock ).toHaveBeenCalled() );
expect( screen.getByText( /Empty Cart/i ) ).toBeInTheDocument();
@@ -157,7 +171,7 @@ describe( 'Testing cart', () => {
return Promise.resolve( JSON.stringify( cart ) );
}
} );
- render( );
+ render( );
await waitFor( () => expect( fetchMock ).toHaveBeenCalled() );
expect( screen.getAllByRole( 'cell' )[ 1 ] ).toHaveTextContent( '16€' );
diff --git a/assets/js/blocks/cart-checkout/cart-i2/types.ts b/assets/js/blocks/cart-checkout/cart/types.ts
similarity index 100%
rename from assets/js/blocks/cart-checkout/cart-i2/types.ts
rename to assets/js/blocks/cart-checkout/cart/types.ts
diff --git a/assets/js/blocks/cart-checkout/mini-cart/block.tsx b/assets/js/blocks/cart-checkout/mini-cart/block.tsx
index 188bd5092f2..ede73eace65 100644
--- a/assets/js/blocks/cart-checkout/mini-cart/block.tsx
+++ b/assets/js/blocks/cart-checkout/mini-cart/block.tsx
@@ -18,7 +18,7 @@ import { getSetting } from '@woocommerce/settings';
/**
* Internal dependencies
*/
-import CartLineItemsTable from '../cart/full-cart/cart-line-items-table';
+import CartLineItemsTable from '../cart/cart-line-items-table';
import './style.scss';
interface MiniCartBlockProps {
diff --git a/bin/hook-docs/data/actions.json b/bin/hook-docs/data/actions.json
index 14a28155349..e2c756c207a 100644
--- a/bin/hook-docs/data/actions.json
+++ b/bin/hook-docs/data/actions.json
@@ -175,17 +175,6 @@
"long_description_html": ""
}
},
- {
- "name": "woocommerce_blocks_cart_enqueue_data",
- "file": "BlockTypes/MiniCart.php",
- "type": "action",
- "doc": {
- "description": "Fires after cart block data is registered.",
- "long_description": "",
- "tags": [],
- "long_description_html": ""
- }
- },
{
"name": "woocommerce_blocks_cart_enqueue_data",
"file": "BlockTypes/Cart.php",
@@ -199,7 +188,7 @@
},
{
"name": "woocommerce_blocks_cart_enqueue_data",
- "file": "BlockTypes/CartI2.php",
+ "file": "BlockTypes/MiniCart.php",
"type": "action",
"doc": {
"description": "Fires after cart block data is registered.",
@@ -230,17 +219,6 @@
"long_description_html": ""
}
},
- {
- "name": "woocommerce_blocks_enqueue_cart_block_scripts_after",
- "file": "BlockTypes/CartI2.php",
- "type": "action",
- "doc": {
- "description": "Fires after cart block scripts are enqueued.",
- "long_description": "",
- "tags": [],
- "long_description_html": ""
- }
- },
{
"name": "woocommerce_blocks_enqueue_cart_block_scripts_before",
"file": "BlockTypes/Cart.php",
@@ -252,17 +230,6 @@
"long_description_html": ""
}
},
- {
- "name": "woocommerce_blocks_enqueue_cart_block_scripts_before",
- "file": "BlockTypes/CartI2.php",
- "type": "action",
- "doc": {
- "description": "Fires before cart block scripts are enqueued.",
- "long_description": "",
- "tags": [],
- "long_description_html": ""
- }
- },
{
"name": "woocommerce_blocks_enqueue_checkout_block_scripts_after",
"file": "BlockTypes/Checkout.php",
@@ -301,7 +268,7 @@
"file": "Integrations/IntegrationRegistry.php",
"type": "action",
"doc": {
- "description": "Fires when and IntegrationRegistry is initialized.",
+ "description": "Fires when the IntegrationRegistry is initialized.",
"long_description": "Runs before integrations are initialized allowing new integration to be registered for use. This should be used as the primary hook for integrations to include their scripts, styles, and other code extending the blocks.",
"tags": [
{
diff --git a/bin/webpack-entries.js b/bin/webpack-entries.js
index a44879bdfd9..8ed530d7043 100644
--- a/bin/webpack-entries.js
+++ b/bin/webpack-entries.js
@@ -46,10 +46,6 @@ const blocks = {
checkout: {
customDir: 'cart-checkout/checkout',
},
- 'cart-i2': {
- customDir: 'cart-checkout/cart-i2',
- isExperimental: true,
- },
'mini-cart': {
customDir: 'cart-checkout/mini-cart',
isExperimental: true,
diff --git a/docs/extensibility/actions.md b/docs/extensibility/actions.md
index 4410568fd07..b72f14fc525 100644
--- a/docs/extensibility/actions.md
+++ b/docs/extensibility/actions.md
@@ -14,12 +14,9 @@
- [woocommerce_applied_coupon](#woocommerce_applied_coupon)
- [woocommerce_blocks_cart_enqueue_data](#woocommerce_blocks_cart_enqueue_data)
- [woocommerce_blocks_cart_enqueue_data](#woocommerce_blocks_cart_enqueue_data-1)
- - [woocommerce_blocks_cart_enqueue_data](#woocommerce_blocks_cart_enqueue_data-2)
- [woocommerce_blocks_checkout_enqueue_data](#woocommerce_blocks_checkout_enqueue_data)
- [woocommerce_blocks_enqueue_cart_block_scripts_after](#woocommerce_blocks_enqueue_cart_block_scripts_after)
- - [woocommerce_blocks_enqueue_cart_block_scripts_after](#woocommerce_blocks_enqueue_cart_block_scripts_after-1)
- [woocommerce_blocks_enqueue_cart_block_scripts_before](#woocommerce_blocks_enqueue_cart_block_scripts_before)
- - [woocommerce_blocks_enqueue_cart_block_scripts_before](#woocommerce_blocks_enqueue_cart_block_scripts_before-1)
- [woocommerce_blocks_enqueue_checkout_block_scripts_after](#woocommerce_blocks_enqueue_checkout_block_scripts_after)
- [woocommerce_blocks_enqueue_checkout_block_scripts_before](#woocommerce_blocks_enqueue_checkout_block_scripts_before)
- [woocommerce_blocks_loaded](#woocommerce_blocks_loaded)
@@ -209,22 +206,6 @@ do_action( 'woocommerce_blocks_cart_enqueue_data' )
### Source
-File: [BlockTypes/MiniCart.php](../src/BlockTypes/MiniCart.php)
-
----
-
-## woocommerce_blocks_cart_enqueue_data
-
-
-Fires after cart block data is registered.
-
-```php
-do_action( 'woocommerce_blocks_cart_enqueue_data' )
-```
-
-### Source
-
-
File: [BlockTypes/Cart.php](../src/BlockTypes/Cart.php)
---
@@ -241,7 +222,7 @@ do_action( 'woocommerce_blocks_cart_enqueue_data' )
### Source
-File: [BlockTypes/CartI2.php](../src/BlockTypes/CartI2.php)
+File: [BlockTypes/MiniCart.php](../src/BlockTypes/MiniCart.php)
---
@@ -277,22 +258,6 @@ File: [BlockTypes/Cart.php](../src/BlockTypes/Cart.php)
---
-## woocommerce_blocks_enqueue_cart_block_scripts_after
-
-
-Fires after cart block scripts are enqueued.
-
-```php
-do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after' )
-```
-
-### Source
-
-
-File: [BlockTypes/CartI2.php](../src/BlockTypes/CartI2.php)
-
----
-
## woocommerce_blocks_enqueue_cart_block_scripts_before
@@ -309,22 +274,6 @@ File: [BlockTypes/Cart.php](../src/BlockTypes/Cart.php)
---
-## woocommerce_blocks_enqueue_cart_block_scripts_before
-
-
-Fires before cart block scripts are enqueued.
-
-```php
-do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_before' )
-```
-
-### Source
-
-
-File: [BlockTypes/CartI2.php](../src/BlockTypes/CartI2.php)
-
----
-
## woocommerce_blocks_enqueue_checkout_block_scripts_after
@@ -380,7 +329,7 @@ File: [Domain/Bootstrap.php](../src/Domain/Bootstrap.php)
## woocommerce_blocks_{$this->registry_identifier}_registration
-Fires when and IntegrationRegistry is initialized.
+Fires when the IntegrationRegistry is initialized.
```php
do_action( 'woocommerce_blocks_{$this->registry_identifier}_registration', \Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry $this )
diff --git a/package.json b/package.json
index 91cafb47b92..d4849b91aae 100644
--- a/package.json
+++ b/package.json
@@ -18,8 +18,8 @@
"./assets/js/middleware/**",
"./assets/js/blocks/cart-checkout/checkout/inner-blocks/**/index.tsx",
"./assets/js/blocks/cart-checkout/checkout/inner-blocks/register-components.ts",
- "./assets/js/blocks/cart-checkout/cart-i2/inner-blocks/**/index.tsx",
- "./assets/js/blocks/cart-checkout/cart-i2/inner-blocks/register-components.ts"
+ "./assets/js/blocks/cart-checkout/cart/inner-blocks/**/index.tsx",
+ "./assets/js/blocks/cart-checkout/cart/inner-blocks/register-components.ts"
],
"repository": {
"type": "git",
diff --git a/packages/checkout/blocks-registry/types.ts b/packages/checkout/blocks-registry/types.ts
index b8a4375eb26..8803659ef6e 100644
--- a/packages/checkout/blocks-registry/types.ts
+++ b/packages/checkout/blocks-registry/types.ts
@@ -13,7 +13,7 @@ export enum innerBlockAreas {
BILLING_ADDRESS = 'woocommerce/checkout-billing-address-block',
SHIPPING_METHODS = 'woocommerce/checkout-shipping-methods-block',
PAYMENT_METHODS = 'woocommerce/checkout-payment-methods-block',
- CART = 'woocommerce/cart-i2',
+ CART = 'woocommerce/cart',
EMPTY_CART = 'woocommerce/empty-cart-block',
FILLED_CART = 'woocommerce/filled-cart-block',
CART_ITEMS = 'woocommerce/cart-items-block',
diff --git a/src/BlockTypes/Cart.php b/src/BlockTypes/Cart.php
index 9a1d8ce6e07..3c540d48a3a 100644
--- a/src/BlockTypes/Cart.php
+++ b/src/BlockTypes/Cart.php
@@ -80,7 +80,32 @@ protected function render( $attributes, $content ) {
wp_dequeue_script( 'selectWoo' );
wp_dequeue_style( 'select2' );
- return $content . $this->get_skeleton();
+ // If the content contains new inner blocks, it means we're in the newer version of Cart.
+ $regex_for_new_block = '//mi';
+
+ $is_new = preg_match( $regex_for_new_block, $content );
+
+ if ( ! $is_new ) {
+ // This fallback needs to match the default templates defined in our Blocks.
+ $inner_blocks_html = '$0
+
+
+ ';
+
+ $content = preg_replace( '/
/mi', $inner_blocks_html, $content );
+ $content = $content . '
';
+ }
+ return $content;
}
/**
@@ -171,85 +196,4 @@ protected function deep_sort_with_accents( $array ) {
protected function hydrate_from_api() {
$this->asset_data_registry->hydrate_api_request( '/wc/store/cart' );
}
-
- /**
- * Render skeleton markup for the cart block.
- */
- protected function get_skeleton() {
- return '
-
- ' . $this->get_skeleton_inline_script();
- }
}
diff --git a/src/BlockTypes/CartI2.php b/src/BlockTypes/CartI2.php
deleted file mode 100644
index c327b7aa877..00000000000
--- a/src/BlockTypes/CartI2.php
+++ /dev/null
@@ -1,174 +0,0 @@
- 'wc-' . $this->block_name . '-block',
- 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name ),
- 'dependencies' => [ 'wc-blocks' ],
- ];
- return $key ? $script[ $key ] : $script;
- }
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @see $this->register_block_type()
- * @param string $key Data to get, or default to everything.
- * @return array|string
- */
- protected function get_block_type_script( $key = null ) {
- $script = [
- 'handle' => 'wc-' . $this->block_name . '-block-frontend',
- 'path' => $this->asset_api->get_block_asset_build_path( $this->block_name . '-frontend' ),
- 'dependencies' => [],
- ];
- return $key ? $script[ $key ] : $script;
- }
-
- /**
- * Enqueue frontend assets for this block, just in time for rendering.
- *
- * @param array $attributes Any attributes that currently are available from the block.
- */
- protected function enqueue_assets( array $attributes ) {
- /**
- * Fires before cart block scripts are enqueued.
- */
- do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_before' );
- parent::enqueue_assets( $attributes );
- /**
- * Fires after cart block scripts are enqueued.
- */
- do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after' );
- }
-
- /**
- * Append frontend scripts when rendering the Cart block.
- *
- * @param array $attributes Block attributes.
- * @param string $content Block content.
- * @return string Rendered block type output.
- */
- protected function render( $attributes, $content ) {
- // Deregister core cart scripts and styles.
- wp_dequeue_script( 'wc-cart' );
- wp_dequeue_script( 'wc-password-strength-meter' );
- wp_dequeue_script( 'selectWoo' );
- wp_dequeue_style( 'select2' );
-
- return $content;
- }
-
- /**
- * Extra data passed through from server to client for block.
- *
- * @param array $attributes Any attributes that currently are available from the block.
- * Note, this will be empty in the editor context when the block is
- * not in the post content on editor load.
- */
- protected function enqueue_data( array $attributes = [] ) {
- parent::enqueue_data( $attributes );
-
- $this->asset_data_registry->add(
- 'shippingCountries',
- function() {
- return $this->deep_sort_with_accents( WC()->countries->get_shipping_countries() );
- },
- true
- );
- $this->asset_data_registry->add(
- 'shippingStates',
- function() {
- return $this->deep_sort_with_accents( WC()->countries->get_shipping_country_states() );
- },
- true
- );
- $this->asset_data_registry->add(
- 'countryLocale',
- function() {
- // Merge country and state data to work around https://github.com/woocommerce/woocommerce/issues/28944.
- $country_locale = wc()->countries->get_country_locale();
- $states = wc()->countries->get_states();
-
- foreach ( $states as $country => $states ) {
- if ( empty( $states ) ) {
- $country_locale[ $country ]['state']['required'] = false;
- $country_locale[ $country ]['state']['hidden'] = true;
- }
- }
- return $country_locale;
- },
- true
- );
- $this->asset_data_registry->add( 'baseLocation', wc_get_base_location(), true );
- $this->asset_data_registry->add( 'isShippingCalculatorEnabled', filter_var( get_option( 'woocommerce_enable_shipping_calc' ), FILTER_VALIDATE_BOOLEAN ), true );
- $this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ), true );
- $this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ), true );
- $this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled(), true );
- $this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled(), true );
- $this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled(), true );
- $this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ), true );
- $this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 );
-
- // Hydrate the following data depending on admin or frontend context.
- if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
- $this->hydrate_from_api();
- }
-
- /**
- * Fires after cart block data is registered.
- */
- do_action( 'woocommerce_blocks_cart_enqueue_data' );
- }
-
- /**
- * Removes accents from an array of values, sorts by the values, then returns the original array values sorted.
- *
- * @param array $array Array of values to sort.
- * @return array Sorted array.
- */
- protected function deep_sort_with_accents( $array ) {
- if ( ! is_array( $array ) || empty( $array ) ) {
- return $array;
- }
-
- if ( is_array( reset( $array ) ) ) {
- return array_map( [ $this, 'deep_sort_with_accents' ], $array );
- }
-
- $array_without_accents = array_map( 'remove_accents', array_map( 'wc_strtolower', array_map( 'html_entity_decode', $array ) ) );
- asort( $array_without_accents );
- return array_replace( $array_without_accents, $array );
- }
-
- /**
- * Hydrate the cart block with data from the API.
- */
- protected function hydrate_from_api() {
- $this->asset_data_registry->hydrate_api_request( '/wc/store/cart' );
- }
-}
diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php
index 659ce9be402..296f4d003f0 100644
--- a/src/BlockTypes/Checkout.php
+++ b/src/BlockTypes/Checkout.php
@@ -82,7 +82,7 @@ protected function render( $attributes, $content ) {
wp_dequeue_script( 'selectWoo' );
wp_dequeue_style( 'select2' );
- // If the content is empty, we may have transformed from an older checkout block. Insert the default list of blocks.
+ // If the content is empty, we may still be in the older checkout block. Insert the default list of blocks.
$regex_for_empty_block = '/
<\/div>/mi';
$is_empty = preg_match( $regex_for_empty_block, $content );
diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php
index 4ded258e121..1ae5757ddca 100644
--- a/src/BlockTypesController.php
+++ b/src/BlockTypesController.php
@@ -183,7 +183,6 @@ protected function get_block_types() {
if ( Package::feature()->is_experimental_build() ) {
$block_types[] = 'SingleProduct';
- $block_types[] = 'CartI2';
$block_types[] = 'MiniCart';
}
diff --git a/src/Payments/Api.php b/src/Payments/Api.php
index 348d84760b4..72a2bbe0e70 100644
--- a/src/Payments/Api.php
+++ b/src/Payments/Api.php
@@ -63,7 +63,7 @@ protected function init() {
* @return array
*/
public function add_payment_method_script_dependencies( $dependencies, $handle ) {
- if ( ! in_array( $handle, [ 'wc-checkout-block', 'wc-checkout-block-frontend', 'wc-cart-block', 'wc-cart-block-frontend', 'wc-cart-i2-block', 'wc-cart-i2-block-frontend' ], true ) ) {
+ if ( ! in_array( $handle, [ 'wc-checkout-block', 'wc-checkout-block-frontend', 'wc-cart-block', 'wc-cart-block-frontend' ], true ) ) {
return $dependencies;
}
return array_merge( $dependencies, $this->payment_method_registry->get_all_active_payment_method_script_dependencies() );
@@ -214,7 +214,7 @@ public function verify_payment_methods_dependencies() {
sprintf( 'console.error( "%s" );', $error_message )
);
- $cart_checkout_scripts = [ 'wc-cart-block', 'wc-cart-block-frontend', 'wc-checkout-block', 'wc-checkout-block-frontend', 'wc-cart-i2-block', 'wc-cart-i2-block-frontend' ];
+ $cart_checkout_scripts = [ 'wc-cart-block', 'wc-cart-block-frontend', 'wc-checkout-block', 'wc-checkout-block-frontend' ];
foreach ( $cart_checkout_scripts as $script_handle ) {
if (
! array_key_exists( $script_handle, $wp_scripts->registered ) ||
diff --git a/tests/e2e/specs/backend/cart.test.js b/tests/e2e/specs/backend/cart.test.js
index 05ca8b22b62..d4eaa6c61f3 100644
--- a/tests/e2e/specs/backend/cart.test.js
+++ b/tests/e2e/specs/backend/cart.test.js
@@ -3,6 +3,7 @@
*/
import {
clickButton,
+ clickBlockToolbarButton,
openDocumentSettingsSidebar,
switchUserToAdmin,
getAllBlocks,
@@ -10,6 +11,7 @@ import {
import {
findLabelWithText,
visitBlockPage,
+ selectBlockByName,
} from '@woocommerce/blocks-test-utils';
import { merchant } from '@woocommerce/e2e-utils';
@@ -20,6 +22,7 @@ import {
closeModalIfExists,
openWidgetsEditorBlockInserter,
} from '../../utils.js';
+import { scrollTo } from '../../../utils';
const block = {
name: 'Cart',
@@ -88,25 +91,26 @@ describe( `${ block.name } Block`, () => {
`Could not find an element with class ${ block.class } - the block probably did not load correctly.`
);
} );
- await page.click( block.class );
+
await expect( page ).toMatchElement(
'[hidden] .wc-block-cart__empty-cart__title'
);
+
+ await selectBlockByName( block.slug );
+ await clickBlockToolbarButton( 'Switch view', 'ariaLabel' );
+ await page.waitForSelector( '.components-popover__content' );
await clickButton( 'Empty Cart' );
+
await expect( page ).not.toMatchElement(
'[hidden] .wc-block-cart__empty-cart__title'
);
- // Simulate user scrolling up so the block toolbar doesn't cover
- // the `Full Cart` button.
- await page.evaluate( () => {
- document
- .querySelector( '.wc-block-view-switch-control' )
- .scrollIntoView( {
- block: 'center',
- inline: 'center',
- } );
- } );
- await clickButton( 'Full Cart' );
+
+ await selectBlockByName( block.slug );
+ await clickBlockToolbarButton( 'Switch view', 'ariaLabel' );
+ await page.waitForSelector( '.components-popover__content' );
+ await scrollTo( '.components-popover__content' );
+ await clickButton( 'Filled Cart' );
+
await expect( page ).toMatchElement(
'[hidden] .wc-block-cart__empty-cart__title'
);
@@ -115,7 +119,9 @@ describe( `${ block.name } Block`, () => {
describe( 'attributes', () => {
beforeEach( async () => {
await openDocumentSettingsSidebar();
- await page.click( block.class );
+ await selectBlockByName(
+ 'woocommerce/cart-order-summary-block'
+ );
} );
it( 'can toggle Shipping calculator', async () => {
diff --git a/tests/js/jest.config.json b/tests/js/jest.config.json
index bb7b2aa35e4..2187e1a2166 100644
--- a/tests/js/jest.config.json
+++ b/tests/js/jest.config.json
@@ -50,5 +50,6 @@
"transform": {
"^.+\\.(js|ts|tsx)$": "/tests/js/jestPreprocess.js"
},
- "verbose": true
+ "verbose": true,
+ "moduleFileExtensions": ["js", "jsx", "ts", "tsx", "json", "node"]
}