From 062c4ed76aeb7d3789e81318ad3d8bec11ac5f3e Mon Sep 17 00:00:00 2001
From: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
Date: Fri, 30 Aug 2024 07:47:03 +0200
Subject: [PATCH] Migrate Product Price to `block.json` (#50905)
* Migrate Product Price to block.json
* Add changelog
* Update block references
* Update block references and doc manifest
* Add shared config properties to Product Price block.json
* Update block references and docs manifest
---
docs/building-a-woo-store/block-references.md | 11 ++++++
docs/docs-manifest.json | 4 +--
.../product-elements/price/attributes.ts | 29 ----------------
.../blocks/product-elements/price/block.json | 34 +++++++++++++++++++
.../product-elements/price/constants.tsx | 17 ----------
.../blocks/product-elements/price/index.tsx | 34 ++++++++-----------
.../dev-46917-migrate-to-block-json-price | 4 +++
7 files changed, 66 insertions(+), 67 deletions(-)
delete mode 100644 plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/attributes.ts
create mode 100644 plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/block.json
delete mode 100644 plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/constants.tsx
create mode 100644 plugins/woocommerce/changelog/dev-46917-migrate-to-block-json-price
diff --git a/docs/building-a-woo-store/block-references.md b/docs/building-a-woo-store/block-references.md
index 0cf96318ebc..5ae993bb975 100644
--- a/docs/building-a-woo-store/block-references.md
+++ b/docs/building-a-woo-store/block-references.md
@@ -53,6 +53,17 @@ Display the main product image.
- **Supports:**
- **Attributes:** aspectRatio, height, imageSizing, isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, productId, saleBadgeAlign, scale, showProductLink, showSaleBadge, width
+## Product Price - woocommerce/product-price
+
+Display the price of a product.
+
+- **Name:** woocommerce/product-price
+- **Category:** woocommerce-product-elements
+- **Ancestor:** woocommerce/all-products,woocommerce/single-product,woocommerce/product-template,core/post-template
+- **Parent:**
+- **Supports:** ~~html~~
+- **Attributes:** isDescendentOfQueryLoop, isDescendentOfSingleProductBlock, isDescendentOfSingleProductTemplate, productId, textAlign
+
## Product Details - woocommerce/product-details
Display a product's description, attributes, and reviews.
diff --git a/docs/docs-manifest.json b/docs/docs-manifest.json
index 6e8e25bf2e6..6ef73f9e485 100644
--- a/docs/docs-manifest.json
+++ b/docs/docs-manifest.json
@@ -74,7 +74,7 @@
"post_title": "Blocks reference",
"menu_title": "Blocks Reference",
"edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/building-a-woo-store/block-references.md",
- "hash": "a33fe5766283aaa70154077692a180319110e133ad430bf8dda3032455bad45c",
+ "hash": "329f17097ce67074a915d7814b2363e8b9e908910c1f7b196c8f4fd8594cc55c",
"url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/building-a-woo-store/block-references.md",
"id": "1fbe91d7fa4fafaf35f0297e4cee1e7958756aed"
},
@@ -1804,5 +1804,5 @@
"categories": []
}
],
- "hash": "0b0ae9b9ed454ab234a5f053f6efb37bafb3e90f1c98f6488263c019f552697b"
+ "hash": "2ecf48b6181dae0526b3858df889bce4e6ee425e10f2c43d151771d845c5a948"
}
\ No newline at end of file
diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/attributes.ts b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/attributes.ts
deleted file mode 100644
index 0acba812f16..00000000000
--- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/attributes.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * External dependencies
- */
-import { BlockAttributes } from '@wordpress/blocks';
-
-export const blockAttributes: BlockAttributes = {
- productId: {
- type: 'number',
- default: 0,
- },
- isDescendentOfQueryLoop: {
- type: 'boolean',
- default: false,
- },
- textAlign: {
- type: 'string',
- default: '',
- },
- isDescendentOfSingleProductTemplate: {
- type: 'boolean',
- default: false,
- },
- isDescendentOfSingleProductBlock: {
- type: 'boolean',
- default: false,
- },
-};
-
-export default blockAttributes;
diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/block.json b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/block.json
new file mode 100644
index 00000000000..02036c30be1
--- /dev/null
+++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/block.json
@@ -0,0 +1,34 @@
+{
+ "name": "woocommerce/product-price",
+ "version": "1.0.0",
+ "title": "Product Price",
+ "description": "Display the price of a product.",
+ "category": "woocommerce-product-elements",
+ "attributes": {
+ "productId": { "type": "number", "default": 0 },
+ "isDescendentOfQueryLoop": { "type": "boolean", "default": false },
+ "textAlign": { "type": "string", "default": "" },
+ "isDescendentOfSingleProductTemplate": {
+ "type": "boolean",
+ "default": false
+ },
+ "isDescendentOfSingleProductBlock": {
+ "type": "boolean",
+ "default": false
+ }
+ },
+ "usesContext": [ "query", "queryId", "postId" ],
+ "keywords": [ "WooCommerce" ],
+ "textdomain": "woocommerce",
+ "apiVersion": 3,
+ "supports": {
+ "html": false
+ },
+ "ancestor": [
+ "woocommerce/all-products",
+ "woocommerce/single-product",
+ "woocommerce/product-template",
+ "core/post-template"
+ ],
+ "$schema": "https://schemas.wp.org/trunk/block.json"
+}
diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/constants.tsx b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/constants.tsx
deleted file mode 100644
index 1aa64d8e2d5..00000000000
--- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/constants.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-import { currencyDollar, Icon } from '@wordpress/icons';
-
-export const BLOCK_TITLE: string = __( 'Product Price', 'woocommerce' );
-export const BLOCK_ICON: JSX.Element = (
-
-);
-export const BLOCK_DESCRIPTION: string = __(
- 'Display the price of a product.',
- 'woocommerce'
-);
diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/index.tsx b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/index.tsx
index a2e8a06f520..700ed125a99 100644
--- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/index.tsx
+++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/index.tsx
@@ -2,33 +2,29 @@
* External dependencies
*/
import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils';
+import { currencyDollar, Icon } from '@wordpress/icons';
/**
* Internal dependencies
*/
import sharedConfig from '../shared/config';
import edit from './edit';
-import attributes from './attributes';
import { supports } from './supports';
-import {
- BLOCK_TITLE as title,
- BLOCK_ICON as icon,
- BLOCK_DESCRIPTION as description,
-} from './constants';
-
-const blockConfig = {
- ...sharedConfig,
- title,
- description,
- usesContext: [ 'query', 'queryId', 'postId' ],
- icon: { src: icon },
- attributes,
- supports,
- edit,
-};
+import metadata from './block.json';
registerBlockSingleProductTemplate( {
- blockName: 'woocommerce/product-price',
- blockSettings: blockConfig,
+ blockName: metadata.name,
+ blockMetadata: metadata,
+ blockSettings: {
+ ...sharedConfig,
+ supports,
+ icon: (
+
+ ),
+ edit,
+ },
isAvailableOnPostEditor: true,
} );
diff --git a/plugins/woocommerce/changelog/dev-46917-migrate-to-block-json-price b/plugins/woocommerce/changelog/dev-46917-migrate-to-block-json-price
new file mode 100644
index 00000000000..037f08ea6ae
--- /dev/null
+++ b/plugins/woocommerce/changelog/dev-46917-migrate-to-block-json-price
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Product Price: migrate to block.json