From bd45c2cd29f6bcff9df7c144e1f56c090299ad4c Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Mon, 3 Apr 2023 18:44:03 +0100
Subject: [PATCH 01/16] Order Received template bootstrap
---
.../js/blocks/classic-template/constants.ts | 10 +++++
src/BlockTemplatesController.php | 9 +++-
src/Domain/Bootstrap.php | 14 +++++--
src/Templates/OrderReceivedTemplate.php | 41 +++++++++++++++++++
.../templates/blockified/order-received.html | 8 ++++
templates/templates/order-received.html | 8 ++++
6 files changed, 86 insertions(+), 4 deletions(-)
create mode 100644 src/Templates/OrderReceivedTemplate.php
create mode 100644 templates/templates/blockified/order-received.html
create mode 100644 templates/templates/order-received.html
diff --git a/assets/js/blocks/classic-template/constants.ts b/assets/js/blocks/classic-template/constants.ts
index ecba18dff6d..21056e1f6dd 100644
--- a/assets/js/blocks/classic-template/constants.ts
+++ b/assets/js/blocks/classic-template/constants.ts
@@ -14,10 +14,12 @@ export const TYPES = {
productCatalog: 'product-catalog',
productTaxonomy: 'product-taxonomy',
productSearchResults: 'product-search-results',
+ orderReceived: 'order-received',
};
export const PLACEHOLDERS = {
singleProduct: 'single-product',
archiveProduct: 'archive-product',
+ orderReceived: 'order-received',
};
export const TEMPLATES: TemplateDetails = {
@@ -69,4 +71,12 @@ export const TEMPLATES: TemplateDetails = {
),
placeholder: PLACEHOLDERS.archiveProduct,
},
+ 'order-received': {
+ types: TYPES.orderReceived,
+ title: __(
+ 'WooCommerce Order Received Block',
+ 'woo-gutenberg-products-block'
+ ),
+ placeholder: PLACEHOLDERS.orderReceived,
+ },
};
diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php
index fbc7f99c768..c8c919314c9 100644
--- a/src/BlockTemplatesController.php
+++ b/src/BlockTemplatesController.php
@@ -1,11 +1,12 @@
block_template_is_available( OrderReceivedTemplate::SLUG )
+ ) {
+ add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
} else {
$queried_object = get_queried_object();
if ( is_null( $queried_object ) ) {
diff --git a/src/Domain/Bootstrap.php b/src/Domain/Bootstrap.php
index 8ef3f15dc46..35d7c6218d3 100644
--- a/src/Domain/Bootstrap.php
+++ b/src/Domain/Bootstrap.php
@@ -21,15 +21,16 @@
use Automattic\WooCommerce\Blocks\Payments\Integrations\PayPal;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use Automattic\WooCommerce\Blocks\Registry\Container;
+use Automattic\WooCommerce\Blocks\Shipping\ShippingController;
+use Automattic\WooCommerce\Blocks\Templates\ArchiveProductTemplatesCompatibility;
use Automattic\WooCommerce\Blocks\Templates\ClassicTemplatesCompatibility;
+use Automattic\WooCommerce\Blocks\Templates\OrderReceivedTemplate;
use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate;
use Automattic\WooCommerce\Blocks\Templates\ProductSearchResultsTemplate;
+use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplateCompatibility;
use Automattic\WooCommerce\StoreApi\RoutesController;
use Automattic\WooCommerce\StoreApi\SchemaController;
use Automattic\WooCommerce\StoreApi\StoreApi;
-use Automattic\WooCommerce\Blocks\Shipping\ShippingController;
-use Automattic\WooCommerce\Blocks\Templates\SingleProductTemplateCompatibility;
-use Automattic\WooCommerce\Blocks\Templates\ArchiveProductTemplatesCompatibility;
/**
* Takes care of bootstrapping the plugin.
@@ -130,6 +131,7 @@ function() {
$this->container->get( BlockTemplatesController::class );
$this->container->get( ProductSearchResultsTemplate::class );
$this->container->get( ProductAttributeTemplate::class );
+ $this->container->get( OrderReceivedTemplate::class );
$this->container->get( ClassicTemplatesCompatibility::class );
$this->container->get( ArchiveProductTemplatesCompatibility::class )->init();
$this->container->get( SingleProductTemplateCompatibility::class )->init();
@@ -271,6 +273,12 @@ function () {
return new ProductAttributeTemplate();
}
);
+ $this->container->register(
+ OrderReceivedTemplate::class,
+ function () {
+ return new OrderReceivedTemplate();
+ }
+ );
$this->container->register(
ClassicTemplatesCompatibility::class,
function ( Container $container ) {
diff --git a/src/Templates/OrderReceivedTemplate.php b/src/Templates/OrderReceivedTemplate.php
new file mode 100644
index 00000000000..4c5b4f2a196
--- /dev/null
+++ b/src/Templates/OrderReceivedTemplate.php
@@ -0,0 +1,41 @@
+init();
+ }
+
+ /**
+ * Initialization method.
+ */
+ protected function init() {
+ add_filter( 'page_template_hierarchy', array( $this, 'update_page_template_hierarchy' ), 10, 3 );
+ }
+
+ /**
+ * When it's the Order Received poge and a block theme is active, render the Order Received Template.
+ *
+ * @param array $templates Templates that match the pages_template_hierarchy.
+ */
+ public function update_page_template_hierarchy( $templates ) {
+
+ if ( is_wc_endpoint_url( 'order-received' ) && wc_current_theme_is_fse_theme() ) {
+ array_unshift( $templates, self::SLUG );
+ }
+
+ return $templates;
+ }
+
+}
diff --git a/templates/templates/blockified/order-received.html b/templates/templates/blockified/order-received.html
new file mode 100644
index 00000000000..f071ced1f33
--- /dev/null
+++ b/templates/templates/blockified/order-received.html
@@ -0,0 +1,8 @@
+
+
+
+
+
Order Received blockified
+
+
+
diff --git a/templates/templates/order-received.html b/templates/templates/order-received.html
new file mode 100644
index 00000000000..5698615525d
--- /dev/null
+++ b/templates/templates/order-received.html
@@ -0,0 +1,8 @@
+
+
+
+
+
From 782fc37b00c9e9db94ccc8bfdd399924f2bd6a20 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Mon, 3 Apr 2023 18:44:38 +0100
Subject: [PATCH 02/16] typo
---
src/Templates/OrderReceivedTemplate.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Templates/OrderReceivedTemplate.php b/src/Templates/OrderReceivedTemplate.php
index 4c5b4f2a196..33f9a611448 100644
--- a/src/Templates/OrderReceivedTemplate.php
+++ b/src/Templates/OrderReceivedTemplate.php
@@ -25,7 +25,7 @@ protected function init() {
}
/**
- * When it's the Order Received poge and a block theme is active, render the Order Received Template.
+ * When it's the Order Received page and a block theme is active, render the Order Received Template.
*
* @param array $templates Templates that match the pages_template_hierarchy.
*/
From cd0dc0ad3b1b0f8c127254ee9f9595704c8dcf85 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Tue, 4 Apr 2023 18:36:42 +0100
Subject: [PATCH 03/16] WIP: new block
---
assets/js/blocks/order-received/block.json | 11 ++++
assets/js/blocks/order-received/edit.tsx | 25 ++++++++
assets/js/blocks/order-received/editor.scss | 30 ++++++++++
assets/js/blocks/order-received/index.tsx | 26 +++++++++
assets/js/blocks/order-received/style.scss | 7 +++
src/BlockTypes/OrderReceived.php | 65 +++++++++++++++++++++
src/BlockTypesController.php | 1 +
templates/templates/order-received.html | 8 +--
8 files changed, 169 insertions(+), 4 deletions(-)
create mode 100644 assets/js/blocks/order-received/block.json
create mode 100644 assets/js/blocks/order-received/edit.tsx
create mode 100644 assets/js/blocks/order-received/editor.scss
create mode 100644 assets/js/blocks/order-received/index.tsx
create mode 100644 assets/js/blocks/order-received/style.scss
create mode 100644 src/BlockTypes/OrderReceived.php
diff --git a/assets/js/blocks/order-received/block.json b/assets/js/blocks/order-received/block.json
new file mode 100644
index 00000000000..0481d78b5d4
--- /dev/null
+++ b/assets/js/blocks/order-received/block.json
@@ -0,0 +1,11 @@
+{
+ "name": "woocommerce/order-received",
+ "version": "1.0.0",
+ "title": "HJJJHGWHUGW Order Received Block",
+ "description": "TODO",
+ "category": "woocommerce",
+ "keywords": [ "WooCommerce" ],
+ "textdomain": "woo-gutenberg-products-block",
+ "apiVersion": 2,
+ "$schema": "https://schemas.wp.org/trunk/block.json"
+}
diff --git a/assets/js/blocks/order-received/edit.tsx b/assets/js/blocks/order-received/edit.tsx
new file mode 100644
index 00000000000..9df206b9816
--- /dev/null
+++ b/assets/js/blocks/order-received/edit.tsx
@@ -0,0 +1,25 @@
+/**
+ * External dependencies
+ */
+import { useBlockProps } from '@wordpress/block-editor';
+/**
+ * Internal dependencies
+ */
+import './editor.scss';
+export interface Attributes {
+ className?: string;
+}
+
+const Edit = () => {
+ const blockProps = useBlockProps( {
+ className: 'wc-block-order-received',
+ } );
+
+ return (
+
+ HELLO!
+
+ );
+};
+
+export default Edit;
diff --git a/assets/js/blocks/order-received/editor.scss b/assets/js/blocks/order-received/editor.scss
new file mode 100644
index 00000000000..c45cef71e54
--- /dev/null
+++ b/assets/js/blocks/order-received/editor.scss
@@ -0,0 +1,30 @@
+.wc-block-add-to-cart-form {
+ display: flex;
+ flex-direction: row;
+}
+
+.wc-block-add-to-cart-form__notice.components-notice {
+ margin: 10px 0;
+ color: $black;
+ max-width: 60%;
+}
+
+input.wc-block-add-to-cart-form__quantity[type="number"] {
+ max-width: 50px;
+ min-height: 23px;
+ float: left;
+ padding: 6px 6px 6px 12px;
+ margin-right: 10px;
+ font-size: 13px;
+ height: inherit;
+}
+
+input[type="number"]::-webkit-inner-spin-button {
+ opacity: 1;
+}
+
+button.components-button.wc-block-add-to-cart-form__button {
+ float: left;
+ padding: 20px 30px;
+ border-radius: 0;
+}
diff --git a/assets/js/blocks/order-received/index.tsx b/assets/js/blocks/order-received/index.tsx
new file mode 100644
index 00000000000..13f0ea67a83
--- /dev/null
+++ b/assets/js/blocks/order-received/index.tsx
@@ -0,0 +1,26 @@
+/**
+ * External dependencies
+ */
+import { registerBlockType } from '@wordpress/blocks';
+import { Icon, button } from '@wordpress/icons';
+
+/**
+ * Internal dependencies
+ */
+import metadata from './block.json';
+import edit from './edit';
+
+registerBlockType( metadata, {
+ icon: {
+ src: (
+
+ ),
+ },
+ edit,
+ save() {
+ return null;
+ },
+} );
diff --git a/assets/js/blocks/order-received/style.scss b/assets/js/blocks/order-received/style.scss
new file mode 100644
index 00000000000..ebaed422715
--- /dev/null
+++ b/assets/js/blocks/order-received/style.scss
@@ -0,0 +1,7 @@
+.wp-block-add-to-cart-form {
+ .woocommerce-Price-amount.amount,
+ .woocommerce-grouped-product-list-item__price del {
+ font-size: var(--wp--preset--font-size--large);
+ }
+ width: unset;
+}
diff --git a/src/BlockTypes/OrderReceived.php b/src/BlockTypes/OrderReceived.php
new file mode 100644
index 00000000000..18b89aa54a7
--- /dev/null
+++ b/src/BlockTypes/OrderReceived.php
@@ -0,0 +1,65 @@
+%4$s',
+ esc_attr( $classes_and_styles['classes'] ),
+ esc_attr( $classname ),
+ esc_attr( $classes_and_styles['styles'] ),
+ $order_block
+ );
+ }
+
+ /**
+ * Get the frontend script handle for this block type.
+ *
+ * @param string $key Data to get, or default to everything.
+ */
+ protected function get_block_type_script( $key = null ) {
+ return null;
+ }
+
+ /**
+ * It isn't necessary register block assets because it is a server side block.
+ */
+ protected function register_block_type_assets() {
+ return null;
+ }
+}
diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php
index 04846b9869b..35ce2db6b64 100644
--- a/src/BlockTypesController.php
+++ b/src/BlockTypesController.php
@@ -214,6 +214,7 @@ protected function get_block_types() {
'RelatedProducts',
'ProductDetails',
'StockFilter',
+ 'OrderReceived',
];
$block_types = array_merge(
diff --git a/templates/templates/order-received.html b/templates/templates/order-received.html
index 5698615525d..879336c4c97 100644
--- a/templates/templates/order-received.html
+++ b/templates/templates/order-received.html
@@ -1,8 +1,8 @@
-
-
From ce8ef161fcf9bdbf22126268489251cca20ae740 Mon Sep 17 00:00:00 2001
From: Luigi
Date: Tue, 4 Apr 2023 20:35:53 +0200
Subject: [PATCH 04/16] add logic here
---
src/BlockTypes/ClassicTemplate.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/BlockTypes/ClassicTemplate.php b/src/BlockTypes/ClassicTemplate.php
index 46b9b6b1b6c..d0496f14bbf 100644
--- a/src/BlockTypes/ClassicTemplate.php
+++ b/src/BlockTypes/ClassicTemplate.php
@@ -62,6 +62,10 @@ protected function render( $attributes, $content, $block ) {
$frontend_scripts::load_scripts();
}
+ if ( 'order-received' === $attributes['template'] ) {
+ echo 'Add template here';
+ }
+
$archive_templates = array( 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag', ProductAttributeTemplate::SLUG, ProductSearchResultsTemplate::SLUG );
if ( 'single-product' === $attributes['template'] ) {
From 9ebd0cb06195b9e09147c080c8f7b001677167a5 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 12:20:21 +0100
Subject: [PATCH 05/16] Order received classic template
---
assets/js/blocks/order-received/block.json | 11 ----
assets/js/blocks/order-received/edit.tsx | 25 --------
assets/js/blocks/order-received/editor.scss | 30 ----------
assets/js/blocks/order-received/index.tsx | 26 ---------
assets/js/blocks/order-received/style.scss | 7 ---
src/BlockTypes/ClassicTemplate.php | 44 ++++++++++----
src/BlockTypes/OrderReceived.php | 65 ---------------------
src/BlockTypesController.php | 1 -
templates/templates/order-received.html | 7 +--
9 files changed, 36 insertions(+), 180 deletions(-)
delete mode 100644 assets/js/blocks/order-received/block.json
delete mode 100644 assets/js/blocks/order-received/edit.tsx
delete mode 100644 assets/js/blocks/order-received/editor.scss
delete mode 100644 assets/js/blocks/order-received/index.tsx
delete mode 100644 assets/js/blocks/order-received/style.scss
delete mode 100644 src/BlockTypes/OrderReceived.php
diff --git a/assets/js/blocks/order-received/block.json b/assets/js/blocks/order-received/block.json
deleted file mode 100644
index 0481d78b5d4..00000000000
--- a/assets/js/blocks/order-received/block.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "name": "woocommerce/order-received",
- "version": "1.0.0",
- "title": "HJJJHGWHUGW Order Received Block",
- "description": "TODO",
- "category": "woocommerce",
- "keywords": [ "WooCommerce" ],
- "textdomain": "woo-gutenberg-products-block",
- "apiVersion": 2,
- "$schema": "https://schemas.wp.org/trunk/block.json"
-}
diff --git a/assets/js/blocks/order-received/edit.tsx b/assets/js/blocks/order-received/edit.tsx
deleted file mode 100644
index 9df206b9816..00000000000
--- a/assets/js/blocks/order-received/edit.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * External dependencies
- */
-import { useBlockProps } from '@wordpress/block-editor';
-/**
- * Internal dependencies
- */
-import './editor.scss';
-export interface Attributes {
- className?: string;
-}
-
-const Edit = () => {
- const blockProps = useBlockProps( {
- className: 'wc-block-order-received',
- } );
-
- return (
-
- HELLO!
-
- );
-};
-
-export default Edit;
diff --git a/assets/js/blocks/order-received/editor.scss b/assets/js/blocks/order-received/editor.scss
deleted file mode 100644
index c45cef71e54..00000000000
--- a/assets/js/blocks/order-received/editor.scss
+++ /dev/null
@@ -1,30 +0,0 @@
-.wc-block-add-to-cart-form {
- display: flex;
- flex-direction: row;
-}
-
-.wc-block-add-to-cart-form__notice.components-notice {
- margin: 10px 0;
- color: $black;
- max-width: 60%;
-}
-
-input.wc-block-add-to-cart-form__quantity[type="number"] {
- max-width: 50px;
- min-height: 23px;
- float: left;
- padding: 6px 6px 6px 12px;
- margin-right: 10px;
- font-size: 13px;
- height: inherit;
-}
-
-input[type="number"]::-webkit-inner-spin-button {
- opacity: 1;
-}
-
-button.components-button.wc-block-add-to-cart-form__button {
- float: left;
- padding: 20px 30px;
- border-radius: 0;
-}
diff --git a/assets/js/blocks/order-received/index.tsx b/assets/js/blocks/order-received/index.tsx
deleted file mode 100644
index 13f0ea67a83..00000000000
--- a/assets/js/blocks/order-received/index.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * External dependencies
- */
-import { registerBlockType } from '@wordpress/blocks';
-import { Icon, button } from '@wordpress/icons';
-
-/**
- * Internal dependencies
- */
-import metadata from './block.json';
-import edit from './edit';
-
-registerBlockType( metadata, {
- icon: {
- src: (
-
- ),
- },
- edit,
- save() {
- return null;
- },
-} );
diff --git a/assets/js/blocks/order-received/style.scss b/assets/js/blocks/order-received/style.scss
deleted file mode 100644
index ebaed422715..00000000000
--- a/assets/js/blocks/order-received/style.scss
+++ /dev/null
@@ -1,7 +0,0 @@
-.wp-block-add-to-cart-form {
- .woocommerce-Price-amount.amount,
- .woocommerce-grouped-product-list-item__price del {
- font-size: var(--wp--preset--font-size--large);
- }
- width: unset;
-}
diff --git a/src/BlockTypes/ClassicTemplate.php b/src/BlockTypes/ClassicTemplate.php
index d0496f14bbf..393c71959e5 100644
--- a/src/BlockTypes/ClassicTemplate.php
+++ b/src/BlockTypes/ClassicTemplate.php
@@ -4,7 +4,7 @@
use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate;
use Automattic\WooCommerce\Blocks\Templates\ProductSearchResultsTemplate;
use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
-use WC_Query;
+use WC_Shortcode_Checkout;
/**
* Classic Single Product class
@@ -63,14 +63,22 @@ protected function render( $attributes, $content, $block ) {
}
if ( 'order-received' === $attributes['template'] ) {
- echo 'Add template here';
+ return $this->render_order_received();
}
- $archive_templates = array( 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag', ProductAttributeTemplate::SLUG, ProductSearchResultsTemplate::SLUG );
-
if ( 'single-product' === $attributes['template'] ) {
return $this->render_single_product();
- } elseif ( in_array( $attributes['template'], $archive_templates, true ) ) {
+ }
+
+ $archive_templates = array(
+ 'archive-product',
+ 'taxonomy-product_cat',
+ 'taxonomy-product_tag',
+ ProductAttributeTemplate::SLUG,
+ ProductSearchResultsTemplate::SLUG,
+ );
+
+ if ( in_array( $attributes['template'], $archive_templates, true ) ) {
// Set this so that our product filters can detect if it's a PHP template.
$this->asset_data_registry->add( 'is_rendering_php_template', true, true );
@@ -84,14 +92,28 @@ protected function render( $attributes, $content, $block ) {
);
return $this->render_archive_product();
- } else {
- ob_start();
+ }
- echo "You're using the ClassicTemplate block";
+ ob_start();
- wp_reset_postdata();
- return ob_get_clean();
- }
+ echo "You're using the ClassicTemplate block";
+
+ wp_reset_postdata();
+
+ return ob_get_clean();
+ }
+
+ /**
+ * Render method for rendering the order received template.
+ *
+ * @return string Rendered block type output.
+ */
+ protected function render_order_received() {
+ ob_start();
+
+ WC_Shortcode_Checkout::output( array() );
+
+ return ob_get_clean();
}
/**
diff --git a/src/BlockTypes/OrderReceived.php b/src/BlockTypes/OrderReceived.php
deleted file mode 100644
index 18b89aa54a7..00000000000
--- a/src/BlockTypes/OrderReceived.php
+++ /dev/null
@@ -1,65 +0,0 @@
-%4$s',
- esc_attr( $classes_and_styles['classes'] ),
- esc_attr( $classname ),
- esc_attr( $classes_and_styles['styles'] ),
- $order_block
- );
- }
-
- /**
- * Get the frontend script handle for this block type.
- *
- * @param string $key Data to get, or default to everything.
- */
- protected function get_block_type_script( $key = null ) {
- return null;
- }
-
- /**
- * It isn't necessary register block assets because it is a server side block.
- */
- protected function register_block_type_assets() {
- return null;
- }
-}
diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php
index 35ce2db6b64..04846b9869b 100644
--- a/src/BlockTypesController.php
+++ b/src/BlockTypesController.php
@@ -214,7 +214,6 @@ protected function get_block_types() {
'RelatedProducts',
'ProductDetails',
'StockFilter',
- 'OrderReceived',
];
$block_types = array_merge(
diff --git a/templates/templates/order-received.html b/templates/templates/order-received.html
index 879336c4c97..ee5278f818a 100644
--- a/templates/templates/order-received.html
+++ b/templates/templates/order-received.html
@@ -1,8 +1,7 @@
-
+
+
+
From 5079c0e6bde5045102d5ccba9f8ce6f2de7aa215 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 12:27:16 +0100
Subject: [PATCH 06/16] reverted constants.ts
---
assets/js/blocks/classic-template/constants.ts | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/assets/js/blocks/classic-template/constants.ts b/assets/js/blocks/classic-template/constants.ts
index 21056e1f6dd..ecba18dff6d 100644
--- a/assets/js/blocks/classic-template/constants.ts
+++ b/assets/js/blocks/classic-template/constants.ts
@@ -14,12 +14,10 @@ export const TYPES = {
productCatalog: 'product-catalog',
productTaxonomy: 'product-taxonomy',
productSearchResults: 'product-search-results',
- orderReceived: 'order-received',
};
export const PLACEHOLDERS = {
singleProduct: 'single-product',
archiveProduct: 'archive-product',
- orderReceived: 'order-received',
};
export const TEMPLATES: TemplateDetails = {
@@ -71,12 +69,4 @@ export const TEMPLATES: TemplateDetails = {
),
placeholder: PLACEHOLDERS.archiveProduct,
},
- 'order-received': {
- types: TYPES.orderReceived,
- title: __(
- 'WooCommerce Order Received Block',
- 'woo-gutenberg-products-block'
- ),
- placeholder: PLACEHOLDERS.orderReceived,
- },
};
From 1fea8e0b566fbf4894f8b3b1d95da70c7a68cd0f Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 13:00:35 +0100
Subject: [PATCH 07/16] Added the post title (buggy)
---
templates/templates/blockified/order-received.html | 8 --------
templates/templates/order-received.html | 1 +
2 files changed, 1 insertion(+), 8 deletions(-)
delete mode 100644 templates/templates/blockified/order-received.html
diff --git a/templates/templates/blockified/order-received.html b/templates/templates/blockified/order-received.html
deleted file mode 100644
index f071ced1f33..00000000000
--- a/templates/templates/blockified/order-received.html
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
Order Received blockified
-
-
-
diff --git a/templates/templates/order-received.html b/templates/templates/order-received.html
index ee5278f818a..1f87fb0dcf7 100644
--- a/templates/templates/order-received.html
+++ b/templates/templates/order-received.html
@@ -1,6 +1,7 @@
+
From 9dba2cf661d24127a0097b7bdd52ec35563c137f Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 13:46:39 +0100
Subject: [PATCH 08/16] Corrected page title
---
src/BlockTypes/ClassicTemplate.php | 7 +++++++
templates/templates/order-received.html | 3 +--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/BlockTypes/ClassicTemplate.php b/src/BlockTypes/ClassicTemplate.php
index 393c71959e5..2775d7693ee 100644
--- a/src/BlockTypes/ClassicTemplate.php
+++ b/src/BlockTypes/ClassicTemplate.php
@@ -111,6 +111,13 @@ protected function render( $attributes, $content, $block ) {
protected function render_order_received() {
ob_start();
+ echo sprintf(
+ '<%1$s %2$s>%3$s%1$s>',
+ 'h1',
+ esc_attr( get_block_wrapper_attributes() ),
+ esc_html__( 'Order received', 'woo-gutenberg-products-block' )
+ );
+
WC_Shortcode_Checkout::output( array() );
return ob_get_clean();
diff --git a/templates/templates/order-received.html b/templates/templates/order-received.html
index 1f87fb0dcf7..87620948711 100644
--- a/templates/templates/order-received.html
+++ b/templates/templates/order-received.html
@@ -1,7 +1,6 @@
-
+
-
From 6b47c63e63ce70a968d92fe3c1e28c632e618c72 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 14:06:25 +0100
Subject: [PATCH 09/16] Updated constants.ts
---
assets/js/blocks/classic-template/constants.ts | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/assets/js/blocks/classic-template/constants.ts b/assets/js/blocks/classic-template/constants.ts
index ecba18dff6d..21056e1f6dd 100644
--- a/assets/js/blocks/classic-template/constants.ts
+++ b/assets/js/blocks/classic-template/constants.ts
@@ -14,10 +14,12 @@ export const TYPES = {
productCatalog: 'product-catalog',
productTaxonomy: 'product-taxonomy',
productSearchResults: 'product-search-results',
+ orderReceived: 'order-received',
};
export const PLACEHOLDERS = {
singleProduct: 'single-product',
archiveProduct: 'archive-product',
+ orderReceived: 'order-received',
};
export const TEMPLATES: TemplateDetails = {
@@ -69,4 +71,12 @@ export const TEMPLATES: TemplateDetails = {
),
placeholder: PLACEHOLDERS.archiveProduct,
},
+ 'order-received': {
+ types: TYPES.orderReceived,
+ title: __(
+ 'WooCommerce Order Received Block',
+ 'woo-gutenberg-products-block'
+ ),
+ placeholder: PLACEHOLDERS.orderReceived,
+ },
};
From 230fd080fcdfe87bb8ed8d36dcd04da2385529f8 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 14:06:44 +0100
Subject: [PATCH 10/16] Fixed template typo
---
templates/templates/order-received.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/templates/order-received.html b/templates/templates/order-received.html
index 87620948711..d73c09b30e8 100644
--- a/templates/templates/order-received.html
+++ b/templates/templates/order-received.html
@@ -1,5 +1,5 @@
-
+
From c594feed9a88b911a2ffbe7a724d5832b8d3018e Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 14:09:10 +0100
Subject: [PATCH 11/16] removed placeholder for order received block
---
assets/js/blocks/classic-template/constants.ts | 2 --
1 file changed, 2 deletions(-)
diff --git a/assets/js/blocks/classic-template/constants.ts b/assets/js/blocks/classic-template/constants.ts
index 21056e1f6dd..1379a5a9961 100644
--- a/assets/js/blocks/classic-template/constants.ts
+++ b/assets/js/blocks/classic-template/constants.ts
@@ -19,7 +19,6 @@ export const TYPES = {
export const PLACEHOLDERS = {
singleProduct: 'single-product',
archiveProduct: 'archive-product',
- orderReceived: 'order-received',
};
export const TEMPLATES: TemplateDetails = {
@@ -77,6 +76,5 @@ export const TEMPLATES: TemplateDetails = {
'WooCommerce Order Received Block',
'woo-gutenberg-products-block'
),
- placeholder: PLACEHOLDERS.orderReceived,
},
};
From 389cfa2163d1a38f14c02ab5a48e941b128cb411 Mon Sep 17 00:00:00 2001
From: Luigi
Date: Thu, 6 Apr 2023 15:24:06 +0200
Subject: [PATCH 12/16] add order-received template description
---
.../js/blocks/classic-template/constants.ts | 4 +-
assets/js/blocks/classic-template/index.tsx | 3 +
.../blocks/classic-template/order-received.ts | 55 +++++++++++++++++++
assets/js/blocks/classic-template/types.ts | 8 ++-
4 files changed, 68 insertions(+), 2 deletions(-)
create mode 100644 assets/js/blocks/classic-template/order-received.ts
diff --git a/assets/js/blocks/classic-template/constants.ts b/assets/js/blocks/classic-template/constants.ts
index 1379a5a9961..d7db3321ae2 100644
--- a/assets/js/blocks/classic-template/constants.ts
+++ b/assets/js/blocks/classic-template/constants.ts
@@ -19,6 +19,7 @@ export const TYPES = {
export const PLACEHOLDERS = {
singleProduct: 'single-product',
archiveProduct: 'archive-product',
+ orderReceived: 'fallback',
};
export const TEMPLATES: TemplateDetails = {
@@ -71,10 +72,11 @@ export const TEMPLATES: TemplateDetails = {
placeholder: PLACEHOLDERS.archiveProduct,
},
'order-received': {
- types: TYPES.orderReceived,
+ type: TYPES.orderReceived,
title: __(
'WooCommerce Order Received Block',
'woo-gutenberg-products-block'
),
+ placeholder: PLACEHOLDERS.orderReceived,
},
};
diff --git a/assets/js/blocks/classic-template/index.tsx b/assets/js/blocks/classic-template/index.tsx
index 2df71d93f5e..ee788f4a3a8 100644
--- a/assets/js/blocks/classic-template/index.tsx
+++ b/assets/js/blocks/classic-template/index.tsx
@@ -35,6 +35,8 @@ import {
} from './archive-product';
import * as blockifiedSingleProduct from './single-product';
import * as blockifiedProductSearchResults from './product-search-results';
+import * as blockifiedOrderReceived from './order-received';
+
import type { BlockifiedTemplateConfig } from './types';
type Attributes = {
@@ -54,6 +56,7 @@ const conversionConfig: { [ key: string ]: BlockifiedTemplateConfig } = {
[ TYPES.productTaxonomy ]: blockifiedProductTaxonomyConfig,
[ TYPES.singleProduct ]: blockifiedSingleProduct,
[ TYPES.productSearchResults ]: blockifiedProductSearchResults,
+ [ TYPES.orderReceived ]: blockifiedOrderReceived,
fallback: blockifiedFallbackConfig,
};
diff --git a/assets/js/blocks/classic-template/order-received.ts b/assets/js/blocks/classic-template/order-received.ts
new file mode 100644
index 00000000000..9d306191ef4
--- /dev/null
+++ b/assets/js/blocks/classic-template/order-received.ts
@@ -0,0 +1,55 @@
+/**
+ * External dependencies
+ */
+
+import { __, sprintf } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+
+const getBlockifiedTemplate = () => [];
+
+const isConversionPossible = () => {
+ // Blockification is possible for the WP version 6.1 and above,
+ // which are the versions the Products block supports.
+ return false;
+};
+
+const getDescriptionAllowingConversion = ( templateTitle: string ) =>
+ sprintf(
+ /* translators: %s is the template title */
+ __(
+ "This block serves as a placeholder for your %s. We recommend upgrading to the Products block for more features to edit your products visually. Don't worry, you can always revert back.",
+ 'woo-gutenberg-products-block'
+ ),
+ templateTitle
+ );
+
+const getDescriptionDisallowingConversion = ( templateTitle: string ) =>
+ sprintf(
+ /* translators: %s is the template title */
+ __(
+ 'This block serves as a placeholder for your %s. It will display the actual product image, title, price in your store. You can move this placeholder around and add more blocks around to customize the template.',
+ 'woo-gutenberg-products-block'
+ ),
+ templateTitle
+ );
+
+const getDescription = ( templateTitle: string, canConvert: boolean ) => {
+ if ( canConvert ) {
+ return getDescriptionAllowingConversion( templateTitle );
+ }
+
+ return getDescriptionDisallowingConversion( templateTitle );
+};
+
+const getButtonLabel = () =>
+ __( 'Upgrade to Products block', 'woo-gutenberg-products-block' );
+
+export {
+ getBlockifiedTemplate,
+ isConversionPossible,
+ getDescription,
+ getButtonLabel,
+};
diff --git a/assets/js/blocks/classic-template/types.ts b/assets/js/blocks/classic-template/types.ts
index 41cb7d61006..0f95ef897b0 100644
--- a/assets/js/blocks/classic-template/types.ts
+++ b/assets/js/blocks/classic-template/types.ts
@@ -3,7 +3,13 @@
*/
import { type BlockInstance } from '@wordpress/blocks';
-export type TemplateDetails = Record< string, Record< string, string > >;
+type TemplateDetail = {
+ type: string;
+ title: string;
+ placeholder: string;
+};
+
+export type TemplateDetails = Record< string, TemplateDetail >;
export type InheritedAttributes = {
align?: string;
From b1f070ff2375cee465a9e7324df9c9e856a29673 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 15:49:56 +0100
Subject: [PATCH 13/16] updated placeholder description
---
assets/js/blocks/classic-template/order-received.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/assets/js/blocks/classic-template/order-received.ts b/assets/js/blocks/classic-template/order-received.ts
index 9d306191ef4..9df2ebf7a49 100644
--- a/assets/js/blocks/classic-template/order-received.ts
+++ b/assets/js/blocks/classic-template/order-received.ts
@@ -20,7 +20,7 @@ const getDescriptionAllowingConversion = ( templateTitle: string ) =>
sprintf(
/* translators: %s is the template title */
__(
- "This block serves as a placeholder for your %s. We recommend upgrading to the Products block for more features to edit your products visually. Don't worry, you can always revert back.",
+ "This block serves as a placeholder for your %s. We recommend upgrading to the Order Received block for more features and to edit it visually. Don't worry, you can always revert back.",
'woo-gutenberg-products-block'
),
templateTitle
@@ -30,7 +30,7 @@ const getDescriptionDisallowingConversion = ( templateTitle: string ) =>
sprintf(
/* translators: %s is the template title */
__(
- 'This block serves as a placeholder for your %s. It will display the actual product image, title, price in your store. You can move this placeholder around and add more blocks around to customize the template.',
+ 'This block serves as a placeholder for your %s. It will display the thankyou.php template. You can move this placeholder around and add more blocks around to customize the template.',
'woo-gutenberg-products-block'
),
templateTitle
From 6f2d599327ae255d94e6679ee1e7b4d1f36f1d8e Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 18:41:38 +0100
Subject: [PATCH 14/16] Formatting fixes
---
src/BlockTypes/ClassicTemplate.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/BlockTypes/ClassicTemplate.php b/src/BlockTypes/ClassicTemplate.php
index 2775d7693ee..96d8b0731cc 100644
--- a/src/BlockTypes/ClassicTemplate.php
+++ b/src/BlockTypes/ClassicTemplate.php
@@ -111,15 +111,19 @@ protected function render( $attributes, $content, $block ) {
protected function render_order_received() {
ob_start();
+ echo '';
+
echo sprintf(
'<%1$s %2$s>%3$s%1$s>',
'h1',
- esc_attr( get_block_wrapper_attributes() ),
+ get_block_wrapper_attributes(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
esc_html__( 'Order received', 'woo-gutenberg-products-block' )
);
WC_Shortcode_Checkout::output( array() );
+ echo '
';
+
return ob_get_clean();
}
From 0295e49108236b06801d90b01001b03ac9905164 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Thu, 6 Apr 2023 18:55:32 +0100
Subject: [PATCH 15/16] Template description.
---
src/Utils/BlockTemplateUtils.php | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php
index a0f1c636c19..fd6b13d7e33 100644
--- a/src/Utils/BlockTemplateUtils.php
+++ b/src/Utils/BlockTemplateUtils.php
@@ -1,11 +1,12 @@
_x( 'Mini Cart', 'Template name', 'woo-gutenberg-products-block' ),
'description' => __( 'Template used to display the Mini Cart drawer.', 'woo-gutenberg-products-block' ),
),
+ OrderReceivedTemplate::SLUG => array(
+ 'title' => _x( 'Order Received', 'Template name', 'woo-gutenberg-products-block' ),
+ 'description' => __( 'Displays the order confirmation page.', 'woo-gutenberg-products-block' ),
+ ),
);
return $plugin_template_types;
From 33e39ada596ba9a700ed3240e78acb17b5f5bbe3 Mon Sep 17 00:00:00 2001
From: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
Date: Mon, 10 Apr 2023 14:58:46 +0100
Subject: [PATCH 16/16] replaced hardcoded string with
OrderReceivedTemplate::SLUG
---
src/BlockTypes/ClassicTemplate.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/BlockTypes/ClassicTemplate.php b/src/BlockTypes/ClassicTemplate.php
index 96d8b0731cc..5720eb51cf7 100644
--- a/src/BlockTypes/ClassicTemplate.php
+++ b/src/BlockTypes/ClassicTemplate.php
@@ -3,6 +3,7 @@
use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate;
use Automattic\WooCommerce\Blocks\Templates\ProductSearchResultsTemplate;
+use Automattic\WooCommerce\Blocks\Templates\OrderReceivedTemplate;
use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
use WC_Shortcode_Checkout;
@@ -62,7 +63,7 @@ protected function render( $attributes, $content, $block ) {
$frontend_scripts::load_scripts();
}
- if ( 'order-received' === $attributes['template'] ) {
+ if ( OrderReceivedTemplate::SLUG === $attributes['template'] ) {
return $this->render_order_received();
}