2023-06-29 13:41:22 +00:00
/ * *
* External dependencies
* /
2023-09-20 12:56:00 +00:00
import { createBlock , type BlockInstance } from '@wordpress/blocks' ;
2023-06-29 13:41:22 +00:00
import { __ } from '@wordpress/i18n' ;
2023-09-20 12:56:00 +00:00
/ * *
* Internal dependencies
* /
import type { OnClickCallbackParameter , InheritedAttributes } from './types' ;
2023-06-29 13:41:22 +00:00
const isConversionPossible = ( ) = > {
2023-09-20 12:56:00 +00:00
return true ;
} ;
2023-12-12 23:05:20 +00:00
const getButtonLabel = ( ) = > __ ( 'Transform into blocks' , 'woocommerce' ) ;
2023-09-20 12:56:00 +00:00
const getBlockifiedTemplate = ( inheritedAttributes : InheritedAttributes ) = >
[
createBlock ( 'woocommerce/order-confirmation-status' , {
. . . inheritedAttributes ,
fontSize : 'large' ,
} ) ,
createBlock (
'woocommerce/order-confirmation-summary' ,
inheritedAttributes
) ,
createBlock (
'woocommerce/order-confirmation-totals-wrapper' ,
inheritedAttributes
) ,
createBlock (
'woocommerce/order-confirmation-downloads-wrapper' ,
inheritedAttributes
) ,
createBlock (
'core/columns' ,
{
. . . inheritedAttributes ,
2024-10-07 10:12:37 +00:00
className : 'wc-block-order-confirmation-address-wrapper' ,
2023-09-20 12:56:00 +00:00
} ,
[
createBlock ( 'core/column' , inheritedAttributes , [
createBlock (
'woocommerce/order-confirmation-shipping-wrapper' ,
inheritedAttributes
) ,
] ) ,
createBlock ( 'core/column' , inheritedAttributes , [
createBlock (
'woocommerce/order-confirmation-billing-wrapper' ,
inheritedAttributes
) ,
] ) ,
]
) ,
2024-01-16 13:17:28 +00:00
createBlock (
'woocommerce/order-confirmation-additional-fields-wrapper' ,
inheritedAttributes
) ,
2023-09-20 12:56:00 +00:00
createBlock (
'woocommerce/order-confirmation-additional-information' ,
inheritedAttributes
) ,
] . filter ( Boolean ) as BlockInstance [ ] ;
const onClickCallback = ( {
clientId ,
attributes ,
getBlocks ,
replaceBlock ,
selectBlock ,
} : OnClickCallbackParameter ) = > {
replaceBlock ( clientId , getBlockifiedTemplate ( attributes ) ) ;
const blocks = getBlocks ( ) ;
const groupBlock = blocks . find (
( block ) = >
block . name === 'core/group' &&
block . innerBlocks . some (
( innerBlock ) = >
innerBlock . name === 'woocommerce/store-notices'
)
) ;
if ( groupBlock ) {
selectBlock ( groupBlock . clientId ) ;
}
2023-06-29 13:41:22 +00:00
} ;
const getDescription = ( ) = > {
return __ (
'This block represents the classic template used to display the order confirmation. The actual rendered template may appear different from this placeholder.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2023-06-29 13:41:22 +00:00
) ;
} ;
const getSkeleton = ( ) = > {
return (
< div className = "woocommerce-page" >
< div className = "woocommerce-order" >
2023-12-12 23:05:20 +00:00
< h1 > { __ ( 'Order received' , 'woocommerce' ) } < / h1 >
2023-06-29 13:41:22 +00:00
< p className = "woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-confirmation" >
{ __ (
'Thank you. Your order has been received.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2023-06-29 13:41:22 +00:00
) }
< / p >
< ul className = "woocommerce-order-overview woocommerce-thankyou-order-details order_details" >
< li className = "woocommerce-order-overview__order order" >
2023-12-12 23:05:20 +00:00
{ __ ( 'Order number' , 'woocommerce' ) } : { ' ' }
< strong > 123 < / strong >
2023-06-29 13:41:22 +00:00
< / li >
< li className = "woocommerce-order-overview__date date" >
2023-12-12 22:12:36 +00:00
{ __ ( 'Date' , 'woocommerce' ) } : { ' ' }
2023-06-29 13:41:22 +00:00
< strong > May 25 , 2023 < / strong >
< / li >
< li className = "woocommerce-order-overview__email email" >
2023-12-12 22:12:36 +00:00
{ __ ( 'Email' , 'woocommerce' ) } : { ' ' }
2024-04-19 21:11:01 +00:00
< strong > shopper @woocommerce . com < / strong >
2023-06-29 13:41:22 +00:00
< / li >
< li className = "woocommerce-order-overview__total total" >
2023-12-12 22:12:36 +00:00
{ __ ( 'Total' , 'woocommerce' ) } : { ' ' }
2023-06-29 13:41:22 +00:00
< strong > $20 . 00 < / strong >
< / li >
< / ul >
< section className = "woocommerce-order-details" >
< h2 className = "woocommerce-order-details__title" >
2023-12-12 23:05:20 +00:00
{ __ ( 'Order details' , 'woocommerce' ) }
2023-06-29 13:41:22 +00:00
< / h2 >
< table className = "woocommerce-table woocommerce-table--order-details shop_table order_details" >
< thead >
< tr >
< th className = "woocommerce-table__product-name product-name" >
2023-12-12 23:05:20 +00:00
{ __ ( 'Product' , 'woocommerce' ) }
2023-06-29 13:41:22 +00:00
< / th >
< th className = "woocommerce-table__product-table product-total" >
2023-12-12 23:05:20 +00:00
{ __ ( 'Total' , 'woocommerce' ) }
2023-06-29 13:41:22 +00:00
< / th >
< / tr >
< / thead >
< tbody >
< tr className = "woocommerce-table__line-item order_item" >
< td className = "woocommerce-table__product-name product-name" >
Sample Product { ' ' }
< strong className = "product-quantity" >
× & nbsp ; 2
< / strong > { ' ' }
< / td >
< td className = "woocommerce-table__product-total product-total" >
$20 . 00
< / td >
< / tr >
< / tbody >
< tfoot >
< tr >
< th scope = "row" >
2023-12-12 23:05:20 +00:00
{ __ ( 'Subtotal' , 'woocommerce' ) } :
2023-06-29 13:41:22 +00:00
< / th >
< td > $20 . 00 < / td >
< / tr >
< tr >
< th scope = "row" >
2023-12-12 23:05:20 +00:00
{ __ ( 'Total' , 'woocommerce' ) } :
2023-06-29 13:41:22 +00:00
< / th >
< td > $20 . 00 < / td >
< / tr >
< / tfoot >
< / table >
< / section >
< section className = "woocommerce-customer-details" >
< section className = "woocommerce-columns woocommerce-columns--2 woocommerce-columns--addresses col2-set addresses" >
< div className = "woocommerce-column woocommerce-column--1 woocommerce-column--billing-address col-1" >
< h2 className = "woocommerce-column__title" >
2023-12-12 23:05:20 +00:00
{ __ ( 'Billing address' , 'woocommerce' ) }
2023-06-29 13:41:22 +00:00
< / h2 >
< address >
123 Main St
< br / >
New York , NY 10001
< br / >
United States ( US )
< / address >
< / div >
< div className = "woocommerce-column woocommerce-column--2 woocommerce-column--shipping-address col-2" >
< h2 className = "woocommerce-column__title" >
2023-12-12 23:05:20 +00:00
{ __ ( 'Shipping address' , 'woocommerce' ) }
2023-06-29 13:41:22 +00:00
< / h2 >
< address >
123 Main St
< br / >
New York , NY 10001
< br / >
United States ( US )
< / address >
< / div >
< / section >
< / section >
< / div >
< / div >
) ;
} ;
2023-09-20 12:56:00 +00:00
const blockifyConfig = {
getButtonLabel ,
onClickCallback ,
getBlockifiedTemplate ,
} ;
export { blockifyConfig , isConversionPossible , getDescription , getSkeleton } ;