2019-12-03 13:57:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-10-25 14:46:34 +00:00
|
|
|
import classnames from 'classnames';
|
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';
|
2020-06-05 19:13:51 +00:00
|
|
|
import { registerFeaturePluginBlockType } from '@woocommerce/block-settings';
|
2021-10-25 14:46:34 +00:00
|
|
|
import { 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 = {
|
2019-12-03 13:57:56 +00:00
|
|
|
title: __( 'Cart', 'woo-gutenberg-products-block' ),
|
|
|
|
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',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __( 'Shopping cart.', 'woo-gutenberg-products-block' ),
|
|
|
|
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,
|
2021-10-25 14:46:34 +00:00
|
|
|
__experimentalExposeControlsToChildren: true,
|
2019-12-03 13:57:56 +00:00
|
|
|
},
|
2020-04-08 15:03:39 +00:00
|
|
|
example: {
|
|
|
|
attributes: {
|
|
|
|
isPreview: true,
|
|
|
|
},
|
|
|
|
},
|
2020-03-13 13:41:59 +00:00
|
|
|
attributes: blockAttributes,
|
2021-10-25 14:46:34 +00:00
|
|
|
edit: Edit,
|
|
|
|
save: Save,
|
|
|
|
// Migrates v1 to v2 checkout.
|
|
|
|
deprecated: [
|
|
|
|
{
|
|
|
|
attributes: blockAttributes,
|
|
|
|
save: ( { attributes } ) => {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={ classnames(
|
|
|
|
'is-loading',
|
|
|
|
attributes.className
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<InnerBlocks.Content />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
migrate: ( attributes, innerBlocks ) => {
|
|
|
|
const {
|
|
|
|
isShippingCalculatorEnabled,
|
|
|
|
showRateAfterTaxName,
|
|
|
|
checkoutPageId,
|
2021-10-25 16:42:31 +00:00
|
|
|
align,
|
2021-10-25 14:46:34 +00:00
|
|
|
} = attributes;
|
|
|
|
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',
|
|
|
|
{
|
|
|
|
isShippingCalculatorEnabled,
|
|
|
|
showRateAfterTaxName,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-10-25 14:46:34 +00:00
|
|
|
registerFeaturePluginBlockType( blockName, settings );
|