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';
|
2020-01-31 18:20:33 +00:00
|
|
|
import { Icon, cart } from '@woocommerce/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: {
|
2020-01-31 18:20:33 +00:00
|
|
|
src: <Icon srcElement={ cart } />,
|
2021-10-15 14:27:59 +00:00
|
|
|
foreground: '#7f54b3',
|
2019-12-03 13:57:56 +00:00
|
|
|
},
|
|
|
|
category: 'woocommerce',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __( 'Shopping cart.', 'woo-gutenberg-products-block' ),
|
|
|
|
supports: {
|
|
|
|
align: [ 'wide', 'full' ],
|
|
|
|
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 );
|