Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Remove Shipping calculator settings and link to the WooCommerce admin settings #11184

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import { TotalsShipping } from '@woocommerce/base-components/cart-checkout';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import { useStoreCart } from '@woocommerce/base-context/hooks';
import { TotalsWrapper } from '@woocommerce/blocks-checkout';
import { getSetting } from '@woocommerce/settings';

const Block = ( {
className,
isShippingCalculatorEnabled,
}: {
className: string;
isShippingCalculatorEnabled: boolean;
} ): JSX.Element | null => {
const Block = ( { className }: { className: string } ): JSX.Element | null => {
const { cartTotals, cartNeedsShipping } = useStoreCart();

if ( ! cartNeedsShipping ) {
Expand All @@ -24,7 +19,10 @@ const Block = ( {
return (
<TotalsWrapper className={ className }>
<TotalsShipping
showCalculator={ isShippingCalculatorEnabled }
showCalculator={ getSetting< boolean >(
'isShippingCalculatorEnabled',
true
) }
showRateSelector={ true }
values={ cartTotals }
currency={ totalsCurrency }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import { __ } from '@wordpress/i18n';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { PanelBody, ToggleControl } from '@wordpress/components';
import { getSetting } from '@woocommerce/settings';
import { PanelBody, ExternalLink } from '@wordpress/components';
import { ADMIN_URL, getSetting } from '@woocommerce/settings';
import Noninteractive from '@woocommerce/base-components/noninteractive';

/**
Expand All @@ -14,19 +14,16 @@ import Block from './block';

export const Edit = ( {
attributes,
setAttributes,
}: {
attributes: {
isShippingCalculatorEnabled: boolean;
className: string;
lock: {
move: boolean;
remove: boolean;
};
};
setAttributes: ( attributes: Record< string, unknown > ) => void;
} ): JSX.Element => {
const { isShippingCalculatorEnabled, className } = attributes;
const { className } = attributes;
const shippingEnabled = getSetting( 'shippingEnabled', true );
const blockProps = useBlockProps();

Expand All @@ -36,35 +33,29 @@ export const Edit = ( {
{ !! shippingEnabled && (
<PanelBody
title={ __(
'Shipping rates',
'Shipping Calculations',
'woo-gutenberg-products-block'
) }
>
<ToggleControl
label={ __(
'Shipping calculator',
<p className="wc-block-checkout__controls-text">
{ __(
'Options that control shipping can be managed in your store settings.',
'woo-gutenberg-products-block'
) }
help={ __(
'Allow customers to estimate shipping by entering their address.',
</p>
<ExternalLink
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping&section=options` }
>
{ __(
'Manage shipping options',
'woo-gutenberg-products-block'
) }
checked={ isShippingCalculatorEnabled }
onChange={ () =>
setAttributes( {
isShippingCalculatorEnabled:
! isShippingCalculatorEnabled,
} )
}
/>
</ExternalLink>{ ' ' }
</PanelBody>
) }
</InspectorControls>
<Noninteractive>
<Block
className={ className }
isShippingCalculatorEnabled={ isShippingCalculatorEnabled }
/>
<Block className={ className } />
</Noninteractive>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/**
* External dependencies
*/
import { withFilteredAttributes } from '@woocommerce/shared-hocs';

/**
* Internal dependencies
*/
import Block from './block';
import attributes from './attributes';

export default withFilteredAttributes( attributes )( Block );
export default Block;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { registerBlockType } from '@wordpress/blocks';
* Internal dependencies
*/
import { Edit, Save } from './edit';
import attributes from './attributes';

registerBlockType( 'woocommerce/cart-order-summary-shipping-block', {
icon: {
Expand All @@ -20,7 +19,6 @@ registerBlockType( 'woocommerce/cart-order-summary-shipping-block', {
/>
),
},
attributes,
edit: Edit,
save: Save,
} );
13 changes: 2 additions & 11 deletions assets/js/blocks/cart/test/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ jest.mock( '@wordpress/compose', () => ( {
const CartBlock = ( {
attributes = {
showRateAfterTaxName: false,
isShippingCalculatorEnabled: false,
checkoutPageId: 0,
},
} ) => {
const {
showRateAfterTaxName,
isShippingCalculatorEnabled,
checkoutPageId,
} = attributes;
const { showRateAfterTaxName, checkoutPageId } = attributes;
return (
<Cart attributes={ attributes }>
<FilledCart>
Expand All @@ -59,11 +54,7 @@ const CartBlock = ( {
<OrderSummaryBlock>
<OrderSummaryHeadingBlock />
<OrderSummarySubtotalBlock />
<OrderSummaryShippingBlock
isShippingCalculatorEnabled={
isShippingCalculatorEnabled
}
/>
<OrderSummaryShippingBlock />
<OrderSummaryTaxesBlock
showRateAfterTaxName={ showRateAfterTaxName }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const Edit = ( {
>
<p className="wc-block-checkout__controls-text">
{ __(
'Account creation and guest checkout settings can be managed in the WooCommerce settings.',
'Account creation and guest checkout settings can be managed in your store settings.',
'woo-gutenberg-products-block'
) }
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,4 @@ export default {
remove: true,
},
},
shippingCostRequiresAddress: {
type: 'boolean',
default: false,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"remove": true,
"move": true
}
},
"shippingCostRequiresAddress": {
"type": "boolean",
"default": false
}
},
"parent": [ "woocommerce/checkout-fields-block" ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useEffect } from '@wordpress/element';
import { CART_STORE_KEY, VALIDATION_STORE_KEY } from '@woocommerce/block-data';
import { useDispatch, useSelect } from '@wordpress/data';
import { isPackageRateCollectable } from '@woocommerce/base-utils';
import { getSetting } from '@woocommerce/settings';

/**
* Internal dependencies
Expand Down Expand Up @@ -164,17 +165,19 @@ const Block = ( {
showIcon,
localPickupText,
shippingText,
shippingCostRequiresAddress = false,
}: {
checked: string;
onChange: ( value: string ) => void;
showPrice: boolean;
showIcon: boolean;
shippingCostRequiresAddress: boolean;
localPickupText: string;
shippingText: string;
} ): JSX.Element | null => {
const { shippingRates } = useShippingData();
const shippingCostRequiresAddress = getSetting< boolean >(
'shippingCostRequiresAddress',
false
);

return (
<RadioGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import { innerBlockAreas } from '@woocommerce/blocks-checkout';
import { useDispatch, useSelect } from '@wordpress/data';
import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data';
import ExternalLinkCard from '@woocommerce/editor-components/external-link-card';
import { Attributes } from '@woocommerce/blocks/checkout/types';
import { updateAttributeInSiblingBlock } from '@woocommerce/utils';

/**
* Internal dependencies
Expand Down Expand Up @@ -154,9 +152,7 @@ const ShippingSelector = ( {
export const Edit = ( {
attributes,
setAttributes,
clientId,
}: {
clientId: string;
attributes: {
title: string;
description: string;
Expand All @@ -167,16 +163,9 @@ export const Edit = ( {
showPrice: boolean;
showIcon: boolean;
className: string;
shippingCostRequiresAddress: boolean;
};
setAttributes: ( attributes: Record< string, unknown > ) => void;
} ): JSX.Element | null => {
const toggleAttribute = ( key: keyof Attributes ): void => {
const newAttributes = {} as Partial< Attributes >;
newAttributes[ key ] = ! ( attributes[ key ] as boolean );
setAttributes( newAttributes );
};

const { setPrefersCollection } = useDispatch( CHECKOUT_STORE_KEY );
const { prefersCollection } = useSelect( ( select ) => {
const checkoutStore = select( CHECKOUT_STORE_KEY );
Expand Down Expand Up @@ -221,30 +210,6 @@ export const Edit = ( {
) }
>
<InspectorControls>
<PanelBody
title={ __(
'Calculations',
'woo-gutenberg-products-block'
) }
>
<ToggleControl
label={ __(
'Hide shipping costs until an address is entered',
'woo-gutenberg-products-block'
) }
checked={ attributes.shippingCostRequiresAddress }
onChange={ ( selected ) => {
updateAttributeInSiblingBlock(
clientId,
'shippingCostRequiresAddress',
selected,
'woocommerce/checkout-shipping-methods-block'
);

toggleAttribute( 'shippingCostRequiresAddress' );
} }
/>
</PanelBody>
<PanelBody
title={ __( 'Appearance', 'woo-gutenberg-products-block' ) }
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ const FrontendBlock = ( {
showIcon,
shippingText,
localPickupText,
shippingCostRequiresAddress,
}: {
title: string;
description: string;
showStepNumber: boolean;
shippingCostRequiresAddress: boolean;
children: JSX.Element;
className?: string;
showPrice: boolean;
Expand Down Expand Up @@ -92,7 +90,6 @@ const FrontendBlock = ( {
showIcon={ showIcon }
localPickupText={ localPickupText }
shippingText={ shippingText }
shippingCostRequiresAddress={ shippingCostRequiresAddress }
/>
{ children }
</FormStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,4 @@ export default {
remove: true,
},
},
shippingCostRequiresAddress: {
type: 'boolean',
default: false,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"remove": true,
"move": true
}
},
"shippingCostRequiresAddress": {
"type": "boolean",
"default": false
}
},
"parent": [ "woocommerce/checkout-fields-block" ],
Expand Down
Loading
Loading