2019-12-03 13:57:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2019-12-10 15:41:57 +00:00
|
|
|
import { InnerBlocks } from '@wordpress/block-editor';
|
2022-02-01 16:54:38 +00:00
|
|
|
import { cart } from '@woocommerce/icons';
|
|
|
|
import { Icon } from '@wordpress/icons';
|
2022-08-15 05:45:15 +00:00
|
|
|
import { registerBlockType, createBlock } from '@wordpress/blocks';
|
2019-12-03 13:57:56 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-10-25 14:46:34 +00:00
|
|
|
import { Edit, Save } from './edit';
|
2019-12-10 15:41:57 +00:00
|
|
|
import './style.scss';
|
2021-10-25 14:46:34 +00:00
|
|
|
import { blockName, blockAttributes } from './attributes';
|
|
|
|
import './inner-blocks';
|
2019-12-05 21:08:48 +00:00
|
|
|
|
2019-12-03 13:57:56 +00:00
|
|
|
/**
|
|
|
|
* Register and run the Cart block.
|
|
|
|
*/
|
2020-01-31 20:04:37 +00:00
|
|
|
const settings = {
|
2023-12-09 13:44:54 +00:00
|
|
|
title: __( 'Cart', 'woocommerce' ),
|
2019-12-03 13:57:56 +00:00
|
|
|
icon: {
|
2021-12-10 14:32:44 +00:00
|
|
|
src: (
|
|
|
|
<Icon
|
2022-02-01 16:54:38 +00:00
|
|
|
icon={ cart }
|
2021-12-10 14:32:44 +00:00
|
|
|
className="wc-block-editor-components-block-icon"
|
|
|
|
/>
|
|
|
|
),
|
2019-12-03 13:57:56 +00:00
|
|
|
},
|
|
|
|
category: 'woocommerce',
|
2023-12-09 13:44:54 +00:00
|
|
|
keywords: [ __( 'WooCommerce', 'woocommerce' ) ],
|
|
|
|
description: __( 'Shopping cart.', 'woocommerce' ),
|
2019-12-03 13:57:56 +00:00
|
|
|
supports: {
|
2021-12-20 11:27:51 +00:00
|
|
|
align: [ 'wide' ],
|
2019-12-03 13:57:56 +00:00
|
|
|
html: false,
|
2019-12-16 13:27:17 +00:00
|
|
|
multiple: false,
|
2019-12-03 13:57:56 +00:00
|
|
|
},
|
2023-03-30 14:15:00 +00:00
|
|
|
example: {
|
|
|
|
attributes: {
|
|
|
|
isPreview: true,
|
|
|
|
},
|
|
|
|
viewportWidth: 800,
|
|
|
|
},
|
2020-03-13 13:41:59 +00:00
|
|
|
attributes: blockAttributes,
|
2021-10-25 14:46:34 +00:00
|
|
|
edit: Edit,
|
|
|
|
save: Save,
|
2023-10-19 15:43:43 +00:00
|
|
|
transforms: {
|
|
|
|
to: [
|
|
|
|
{
|
|
|
|
type: 'block',
|
|
|
|
blocks: [ 'woocommerce/classic-shortcode' ],
|
|
|
|
transform: ( attributes ) => {
|
|
|
|
return createBlock(
|
|
|
|
'woocommerce/classic-shortcode',
|
|
|
|
{
|
|
|
|
shortcode: 'cart',
|
|
|
|
align: attributes.align,
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-10-25 14:46:34 +00:00
|
|
|
// Migrates v1 to v2 checkout.
|
|
|
|
deprecated: [
|
|
|
|
{
|
|
|
|
attributes: blockAttributes,
|
|
|
|
save: ( { attributes } ) => {
|
|
|
|
return (
|
|
|
|
<div
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx( 'is-loading', attributes.className ) }
|
2021-10-25 14:46:34 +00:00
|
|
|
>
|
|
|
|
<InnerBlocks.Content />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
migrate: ( attributes, innerBlocks ) => {
|
2022-04-01 13:45:18 +00:00
|
|
|
const { checkoutPageId, align } = attributes;
|
2021-10-25 14:46:34 +00:00
|
|
|
return [
|
|
|
|
attributes,
|
|
|
|
[
|
2021-10-25 16:42:31 +00:00
|
|
|
createBlock(
|
|
|
|
'woocommerce/filled-cart-block',
|
|
|
|
{ align },
|
|
|
|
[
|
|
|
|
createBlock( 'woocommerce/cart-items-block' ),
|
2021-10-25 14:46:34 +00:00
|
|
|
createBlock(
|
2021-10-25 16:42:31 +00:00
|
|
|
'woocommerce/cart-totals-block',
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
createBlock(
|
|
|
|
'woocommerce/cart-order-summary-block',
|
2022-04-01 13:45:18 +00:00
|
|
|
{}
|
2021-10-25 16:42:31 +00:00
|
|
|
),
|
|
|
|
createBlock(
|
|
|
|
'woocommerce/cart-express-payment-block'
|
|
|
|
),
|
|
|
|
createBlock(
|
|
|
|
'woocommerce/proceed-to-checkout-block',
|
|
|
|
{ checkoutPageId }
|
|
|
|
),
|
|
|
|
createBlock(
|
|
|
|
'woocommerce/cart-accepted-payment-methods-block'
|
|
|
|
),
|
|
|
|
]
|
2021-10-25 14:46:34 +00:00
|
|
|
),
|
2021-10-25 16:42:31 +00:00
|
|
|
]
|
|
|
|
),
|
2021-10-25 14:46:34 +00:00
|
|
|
createBlock(
|
|
|
|
'woocommerce/empty-cart-block',
|
2021-10-25 16:42:31 +00:00
|
|
|
{ align },
|
2021-10-25 14:46:34 +00:00
|
|
|
innerBlocks
|
|
|
|
),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
},
|
|
|
|
isEligible: ( _, innerBlocks ) => {
|
|
|
|
return ! innerBlocks.find(
|
|
|
|
( block ) => block.name === 'woocommerce/filled-cart-block'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-01-31 20:04:37 +00:00
|
|
|
};
|
|
|
|
|
2022-08-15 05:45:15 +00:00
|
|
|
registerBlockType( blockName, settings );
|