This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add order confirmation wrapper block (#10286)
* Add a heading wrapper block * Register the BillingWrapper Block server side * Fix exception 'render_content' error * Add the Billing Wrapper Block to the template * Fix wrong block name error * Fix php error * Conditionally render Billing Address within the Wrapper * Fix parent rendering * Clean up code (remove billing address from the template) * Update titles, descriptions, and icons of the billing Block and inner block * Fix broken block by removing the "parent" keyword * Use a user-friendly title and description for the Billing Wrapper * Update Billing Wrapper Block's title case Co-authored-by: Mike Jolley <mike.jolley@me.com> * Fix PHP failing unit test --------- Co-authored-by: Mike Jolley <mike.jolley@me.com>
- Loading branch information
1 parent
a3c5715
commit 83ab71e
Showing
9 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
assets/js/blocks/order-confirmation/billing-wrapper/attributes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export default { | ||
heading: { | ||
type: 'string', | ||
default: __( 'Billing address', 'woo-gutenberg-products-block' ), | ||
}, | ||
}; |
19 changes: 19 additions & 0 deletions
19
assets/js/blocks/order-confirmation/billing-wrapper/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "woocommerce/order-confirmation-billing-wrapper", | ||
"version": "1.0.0", | ||
"title": "Order Confirmation Billing Section", | ||
"description": "Display the order confirmation billing section.", | ||
"category": "woocommerce", | ||
"keywords": [ "WooCommerce" ], | ||
"attributes": { | ||
"filterType": { | ||
"type": "string" | ||
}, | ||
"heading": { | ||
"type": "string" | ||
} | ||
}, | ||
"textdomain": "woo-gutenberg-products-block", | ||
"apiVersion": 2, | ||
"$schema": "https://schemas.wp.org/trunk/block.json" | ||
} |
46 changes: 46 additions & 0 deletions
46
assets/js/blocks/order-confirmation/billing-wrapper/edit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
const Edit = ( { | ||
attributes, | ||
setAttributes, | ||
}: { | ||
attributes: { | ||
heading: string; | ||
}; | ||
setAttributes: ( attributes: Record< string, unknown > ) => void; | ||
} ) => { | ||
const blockProps = useBlockProps(); | ||
|
||
return ( | ||
<div { ...blockProps }> | ||
<InnerBlocks | ||
allowedBlocks={ [ 'core/heading' ] } | ||
template={ [ | ||
[ | ||
'core/heading', | ||
{ | ||
level: 3, | ||
content: attributes.heading || '', | ||
onChangeContent: ( value: string ) => | ||
setAttributes( { heading: value } ), | ||
}, | ||
], | ||
[ | ||
'woocommerce/order-confirmation-billing-address', | ||
{ | ||
heading: '', | ||
lock: { | ||
remove: true, | ||
}, | ||
}, | ||
], | ||
] } | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Edit; |
33 changes: 33 additions & 0 deletions
33
assets/js/blocks/order-confirmation/billing-wrapper/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor'; | ||
import { Icon, mapMarker } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
import metadata from './block.json'; | ||
import attributes from './attributes'; | ||
|
||
registerBlockType( metadata, { | ||
icon: { | ||
src: ( | ||
<Icon | ||
icon={ mapMarker } | ||
className="wc-block-editor-components-block-icon" | ||
/> | ||
), | ||
}, | ||
edit, | ||
save() { | ||
return ( | ||
<div { ...useBlockProps.save() }> | ||
<InnerBlocks.Content /> | ||
</div> | ||
); | ||
}, | ||
attributes, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Automattic\WooCommerce\Blocks\BlockTypes\OrderConfirmation; | ||
|
||
use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils; | ||
use Automattic\WooCommerce\Blocks\BlockTypes\OrderConfirmation\BillingAddress; | ||
|
||
/** | ||
* BillingWrapper class. | ||
*/ | ||
class BillingWrapper extends AbstractOrderConfirmationBlock { | ||
|
||
/** | ||
* Block name. | ||
* | ||
* @var string | ||
*/ | ||
protected $block_name = 'order-confirmation-billing-wrapper'; | ||
|
||
/** | ||
* Render the block. | ||
* | ||
* @param array $attributes Block attributes. | ||
* @param string $content Block content. | ||
* @param WP_Block $block Block instance. | ||
* | ||
* @return string | void Rendered block output. | ||
*/ | ||
protected function render( $attributes, $content, $block ) { | ||
$order = $this->get_order(); | ||
|
||
if ( ! $order || ! $this->is_current_customer_order( $order ) || ! $order->has_billing_address() ) { | ||
return ''; | ||
} | ||
|
||
$classname = $attributes['className'] ?? ''; | ||
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes ); | ||
|
||
if ( isset( $attributes['align'] ) ) { | ||
$classname .= " align{$attributes['align']}"; | ||
} | ||
|
||
return sprintf( | ||
'<div class="wc-block-%4$s %1$s %2$s">%3$s</div>', | ||
esc_attr( $classes_and_styles['classes'] ), | ||
esc_attr( $classname ), | ||
$content, | ||
esc_attr( $this->block_name ) | ||
); | ||
} | ||
|
||
/** | ||
* This renders the content of the billing wrapper. | ||
* | ||
* @param \WC_Order $order Order object. | ||
* @param string $permission Permission level for viewing order details. | ||
* @param array $attributes Block attributes. | ||
*/ | ||
protected function render_content( $order, $permission = false, $attributes = [] ) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters