2019-12-03 13:57:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-02-19 16:33:10 +00:00
|
|
|
import classNames from 'classnames';
|
2019-12-10 15:41:57 +00:00
|
|
|
import { InnerBlocks } from '@wordpress/block-editor';
|
2019-12-03 13:57:56 +00:00
|
|
|
import { registerBlockType } from '@wordpress/blocks';
|
2020-01-31 18:20:33 +00:00
|
|
|
import { Icon, cart } from '@woocommerce/icons';
|
2020-02-19 16:33:10 +00:00
|
|
|
import {
|
|
|
|
IS_SHIPPING_CALCULATOR_ENABLED,
|
|
|
|
IS_SHIPPING_COST_HIDDEN,
|
|
|
|
} from '@woocommerce/block-settings';
|
2019-12-03 13:57:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-03-10 09:09:34 +00:00
|
|
|
import edit from './edit';
|
2019-12-03 13:57:56 +00:00
|
|
|
import { example } from './example';
|
2019-12-10 15:41:57 +00:00
|
|
|
import './style.scss';
|
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 } />,
|
2019-12-03 13:57:56 +00:00
|
|
|
foreground: '#96588a',
|
|
|
|
},
|
|
|
|
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,
|
2019-12-03 13:57:56 +00:00
|
|
|
},
|
|
|
|
example,
|
2020-02-19 16:33:10 +00:00
|
|
|
attributes: {
|
|
|
|
isShippingCalculatorEnabled: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: IS_SHIPPING_CALCULATOR_ENABLED,
|
|
|
|
},
|
|
|
|
isShippingCostHidden: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: IS_SHIPPING_COST_HIDDEN,
|
|
|
|
},
|
|
|
|
},
|
2019-12-03 13:57:56 +00:00
|
|
|
|
2020-03-10 09:09:34 +00:00
|
|
|
edit,
|
2019-12-03 13:57:56 +00:00
|
|
|
|
|
|
|
/**
|
2020-02-19 16:33:10 +00:00
|
|
|
* Save the props to post content.
|
2019-12-03 13:57:56 +00:00
|
|
|
*/
|
2020-02-19 16:33:10 +00:00
|
|
|
save( { attributes } ) {
|
|
|
|
const {
|
|
|
|
className,
|
|
|
|
isShippingCalculatorEnabled,
|
|
|
|
isShippingCostHidden,
|
|
|
|
} = attributes;
|
|
|
|
const data = {
|
2020-03-10 09:09:34 +00:00
|
|
|
'data-is-shipping-calculator-enabled': isShippingCalculatorEnabled,
|
|
|
|
'data-is-shipping-cost-hidden': isShippingCostHidden,
|
2020-02-19 16:33:10 +00:00
|
|
|
};
|
2019-12-10 15:41:57 +00:00
|
|
|
return (
|
2020-02-19 16:33:10 +00:00
|
|
|
<div
|
|
|
|
className={ classNames( 'is-loading', className ) }
|
|
|
|
{ ...data }
|
|
|
|
>
|
2019-12-10 15:41:57 +00:00
|
|
|
<InnerBlocks.Content />
|
|
|
|
</div>
|
|
|
|
);
|
2019-12-03 13:57:56 +00:00
|
|
|
},
|
2020-01-31 20:04:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE === 'experimental' ) {
|
|
|
|
registerBlockType( 'woocommerce/cart', settings );
|
|
|
|
}
|