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

Add Product Meta Block #8484

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
d46e480
Add minimum structure for Single Product Details block
thealexandrelara Jan 17, 2023
38fcacb
Add Product Image Gallery #8233
gigitux Jan 18, 2023
2a1b52c
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Jan 20, 2023
e743ebe
Add tests for Single Product Details block
thealexandrelara Jan 20, 2023
3a050d3
Add the initial basis for the Add to Cart button
nefeline Jan 24, 2023
f096dc9
Trigger the single product add to cart action for each product type.
nefeline Jan 25, 2023
f87de21
wip: create block structure and add initial styles
thealexandrelara Jan 25, 2023
561f6f8
Add block details to the SingleProductDetails.php file
thealexandrelara Jan 26, 2023
9b0fd88
Merge branch 'trunk' into add/add-to-cart-block
nefeline Jan 27, 2023
1331e1c
Rename the block from add-to-cart-button to add-to-cart-form
nefeline Jan 27, 2023
a65d69d
Update to use the cart icon.
nefeline Jan 27, 2023
16ee8bf
Implement the skeleton for the editor preview.
nefeline Jan 27, 2023
d07b9b5
Render tabs title with empty content
thealexandrelara Jan 27, 2023
9c90f71
Use woocommerce_output_product_data_tabs function to retrieve tabs data
thealexandrelara Jan 27, 2023
eb6301b
Merge branch 'trunk' into add/add-to-cart-block
nefeline Jan 29, 2023
961b62f
Update styles and add Notice for the display in the Editor.
nefeline Jan 29, 2023
01a6400
Update CSS.
nefeline Jan 29, 2023
5f889e6
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Jan 30, 2023
caa6e6a
Add base tests for the new Add to Cart Form component.
nefeline Jan 30, 2023
13dc046
Add Product Image Gallery block
gigitux Jan 30, 2023
1dc7baa
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Jan 30, 2023
21a1fea
remove support global styles
gigitux Jan 30, 2023
d9900e0
remove support global styles
gigitux Jan 30, 2023
75d00bb
Merge branch 'add/8233-product-image-gallery-block' of https://github…
gigitux Jan 30, 2023
f8e00c9
Merge branch 'trunk' into add/8233-product-image-gallery-block
gigitux Jan 30, 2023
3c06189
Update the button CSS.
nefeline Jan 30, 2023
eb0ce4a
Remove customizations for the Single Product Details block
thealexandrelara Jan 30, 2023
30f3385
Update styles for the cart form.
nefeline Jan 30, 2023
8a58e3c
update td style.
nefeline Jan 30, 2023
22be4e9
Merge branch 'trunk' into feat/add-single-product-details-block
thealexandrelara Jan 30, 2023
d57a5da
Update divs and CSS.
nefeline Jan 30, 2023
c394df5
Merge branch 'trunk' into add/add-to-cart-block
nefeline Jan 30, 2023
137776a
Use conventional input instead of the experimental InputControl
nefeline Jan 30, 2023
795a698
address CSS feedback
gigitux Jan 31, 2023
90c71d3
Merge branch 'add/8233-product-image-gallery-block' of https://github…
gigitux Jan 31, 2023
dc48ddf
add support for the custom classname
gigitux Jan 31, 2023
e526eff
remove save function
gigitux Jan 31, 2023
2a4baad
Remove unnecessary console.log from the Edit.tsx file
thealexandrelara Jan 31, 2023
8e05b71
Remove block classname from block wrapper
thealexandrelara Jan 31, 2023
f70ab0c
Remove unnecessary WooCommerce tabs filter from the BlockTemplatesCon…
thealexandrelara Jan 31, 2023
4ea37cb
Merge branch 'trunk' into feat/add-single-product-details-block
thealexandrelara Jan 31, 2023
ad70695
Remove attributes property from the block registration
thealexandrelara Jan 31, 2023
fd83c09
Remove isExperimental flag for the Single Product Details block
thealexandrelara Jan 31, 2023
3661133
Remove get_classes_and_styles_by_attributes method from SingleProduct…
thealexandrelara Jan 31, 2023
8a9196e
Prevent Single Product Details block from apppearing in Pages or Posts
thealexandrelara Jan 31, 2023
66595f1
add second parameter to the subscribe function
gigitux Feb 1, 2023
5a0eb23
Implement the new design and copy provided for the editor.
nefeline Feb 1, 2023
dbc8f4b
Make the notice compatible with dark themes.
nefeline Feb 1, 2023
9a5b468
Some additional CSS tweaks
nefeline Feb 1, 2023
e196c6a
adjust the padding for the input
nefeline Feb 1, 2023
deaf86e
wrap the Single Product Template in a div with the product class
gigitux Feb 1, 2023
edcac21
Fix PHP Coding Standards warnings
thealexandrelara Feb 1, 2023
95a05a4
improve logic and increase coverage of unit test
gigitux Feb 2, 2023
83e8088
Merge branch 'trunk' into add/add-to-cart-block
nefeline Feb 2, 2023
1568ec2
improve logic and increase coverage of unit test
gigitux Feb 3, 2023
379548a
Merge branch 'trunk' into fix/8314-blockifying-single-product-templat…
gigitux Feb 3, 2023
e82ab27
fix test
gigitux Feb 3, 2023
36d5ebf
format HTML
gigitux Feb 3, 2023
4e76b07
fix edge case
gigitux Feb 3, 2023
c701d7f
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Feb 3, 2023
5a4ac3b
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Feb 13, 2023
8aee841
update @types/wordpress__data package
gigitux Feb 13, 2023
32f97dd
update placeholder, icon and description
gigitux Feb 13, 2023
e3be328
update tsconfig
gigitux Feb 13, 2023
528b9ce
Merge branch 'trunk' into feat/add-single-product-details-block
gigitux Feb 13, 2023
0ba35e1
update block name
gigitux Feb 13, 2023
af09b77
Merge branch 'feat/add-single-product-details-block' of https://githu…
gigitux Feb 13, 2023
93bcb28
fix SCSS linter error
gigitux Feb 13, 2023
f48dad5
Merge branch 'add/add-to-cart-block' of https://github.com/woocommerc…
gigitux Feb 13, 2023
03a909c
Merge branch 'add/8233-product-image-gallery-block' into add/compatib…
gigitux Feb 13, 2023
4b5e9c2
Merge branch 'feat/add-single-product-details-block' into add/compati…
gigitux Feb 13, 2023
82184a0
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Feb 14, 2023
6413df8
address feedback
gigitux Feb 14, 2023
c8cd88e
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Feb 14, 2023
3478a2e
Merge branch 'fix/8314-blockifying-single-product-template-investigat…
gigitux Feb 14, 2023
5a8c13f
create SingleProductTemplateCompatibility class
gigitux Feb 14, 2023
51f6e06
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Feb 14, 2023
94ac4a0
Add Hooks compatibility
gigitux Feb 14, 2023
78f0b87
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Feb 15, 2023
607dff4
remove not used file
gigitux Feb 15, 2023
2df42bd
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Feb 16, 2023
2a0848f
remove not used files
gigitux Feb 16, 2023
d715fa3
Add compatibility layer for the Single Product template
gigitux Feb 16, 2023
ce9bd9c
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Feb 16, 2023
eeef013
Merge branch 'add/compatibility-single-product-block' into 8465-singl…
gigitux Feb 17, 2023
6996ca8
fix check
gigitux Feb 17, 2023
ecebc81
Merge branch 'add/compatibility-single-product-block' into 8465-singl…
gigitux Feb 17, 2023
7790a5d
implement Product meta template header
gigitux Feb 20, 2023
846b803
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Mar 1, 2023
f16d440
Merge branch 'trunk' into 8465-single-product-template-create-a-templ…
gigitux Mar 2, 2023
5205f52
Product Price Block: Add support Single Product Template
gigitux Mar 2, 2023
32c7203
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Mar 3, 2023
a3d1ba3
fix missing import
gigitux Mar 3, 2023
a3c3673
add comment
gigitux Mar 3, 2023
8ccb2b3
return a value
gigitux Mar 3, 2023
9d8a43a
improve comment
gigitux Mar 3, 2023
5b47d97
fix import
gigitux Mar 3, 2023
851861a
Merge branch '8479-product-price-block-add-support-to-the-single-prod…
gigitux Mar 3, 2023
4c8f30d
Add Product Meta block
gigitux Mar 3, 2023
4789141
Merge branch 'trunk' into 8465-single-product-template-create-a-templ…
gigitux Mar 3, 2023
80ea6a2
Merge branch 'trunk' into 8465-single-product-template-create-a-templ…
gigitux Mar 7, 2023
749c4e5
remove unnecessary change
gigitux Mar 7, 2023
5242bdc
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Mar 7, 2023
d9c9b96
fix compatibility layer when the Single Product template has the clas…
gigitux Mar 8, 2023
18b3ce0
Merge branch 'trunk' of https://github.com/woocommerce/woocommerce-bl…
gigitux Mar 8, 2023
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
1 change: 1 addition & 0 deletions assets/js/atomic/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ import './product-elements/add-to-cart-form';
import './product-elements/product-image-gallery';
import './product-elements/product-details';
import './product-elements/related-products';
import './product-elements/product-meta';
17 changes: 17 additions & 0 deletions assets/js/atomic/blocks/product-elements/product-meta/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "woocommerce/product-meta",
"version": "1.0.0",
"title": "Product Meta",
"icon": "product",
"description": "Display Product Meta",
"category": "woocommerce",
"supports": {
"align": true,
"reusable": false
},
"keywords": [ "WooCommerce" ],
"usesContext": [ "postId", "postType", "queryId" ],
"textdomain": "woo-gutenberg-products-block",
"apiVersion": 2,
"$schema": "https://schemas.wp.org/trunk/block.json"
}
50 changes: 50 additions & 0 deletions assets/js/atomic/blocks/product-elements/product-meta/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* External dependencies
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import { InnerBlockTemplate } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './editor.scss';

const Edit = () => {
const TEMPLATE: InnerBlockTemplate[] = [
[
'core/group',
{ layout: { type: 'flex', flexWrap: 'nowrap' } },
[
[
'woocommerce/product-sku',
{
isDescendentOfSingleProductTemplate: true,
},
],
[
'core/post-terms',
{
prefix: 'Category: ',
term: 'product_cat',
},
],
[
'core/post-terms',
{
prefix: 'Tags: ',
term: 'product_tag',
},
],
],
],
];
const blockProps = useBlockProps();

return (
<div { ...blockProps }>
<InnerBlocks template={ TEMPLATE } />
</div>
);
};

export default Edit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.wc-block-editor-related-products__notice {
margin: 10px auto;
max-width: max-content;
}
28 changes: 28 additions & 0 deletions assets/js/atomic/blocks/product-elements/product-meta/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* External dependencies
*/
import { box as icon } from '@wordpress/icons';
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';
import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils';

/**
* Internal dependencies
*/
import edit from './edit';
import save from './save';
import metadata from './block.json';

registerBlockSingleProductTemplate( {
registerBlockFn: () => {
// @ts-expect-error: `registerBlockType` is a function that is typed in WordPress core.
registerBlockType( metadata, {
icon,
edit,
save,
} );
},
unregisterBlockFn: () => {
unregisterBlockType( metadata.name );
},
blockName: metadata.name,
} );
17 changes: 17 additions & 0 deletions assets/js/atomic/blocks/product-elements/product-meta/save.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* External dependencies
*/
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

const Save = () => {
const blockProps = useBlockProps.save();

return (
<div { ...blockProps }>
{ /* @ts-expect-error: `InnerBlocks.Content` is a component that is typed in WordPress core*/ }
<InnerBlocks.Content />
</div>
);
};

export default Save;
8 changes: 8 additions & 0 deletions assets/js/atomic/blocks/product-elements/sku/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export const blockAttributes: BlockAttributes = {
type: 'boolean',
default: false,
},
isDescendentOfSingleProductTemplate: {
type: 'boolean',
default: false,
},
showProductSelector: {
type: 'boolean',
default: false,
},
};

export default blockAttributes;
46 changes: 34 additions & 12 deletions assets/js/atomic/blocks/product-elements/sku/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,51 @@ import type { Attributes } from './types';

type Props = Attributes & HTMLAttributes< HTMLDivElement >;

const Preview = ( {
parentClassName,
sku,
className,
}: {
parentClassName: string;
sku: string;
className?: string | undefined;
} ) => (
<div
className={ classnames( className, 'wc-block-components-product-sku', {
[ `${ parentClassName }__product-sku` ]: parentClassName,
} ) }
>
{ __( 'SKU:', 'woo-gutenberg-products-block' ) }{ ' ' }
<strong>{ sku }</strong>
</div>
);

const Block = ( props: Props ): JSX.Element | null => {
const { className } = props;
const { parentClassName } = useInnerBlockLayoutContext();
const { product } = useProductDataContext();
const sku = product.sku;

if ( props.isDescendentOfSingleProductTemplate ) {
return (
<Preview
parentClassName={ parentClassName }
className={ className }
sku={ 'Product SKU' }
/>
);
}

if ( ! sku ) {
return null;
}

return (
<div
className={ classnames(
className,
'wc-block-components-product-sku',
{
[ `${ parentClassName }__product-sku` ]: parentClassName,
}
) }
>
{ __( 'SKU:', 'woo-gutenberg-products-block' ) }{ ' ' }
<strong>{ sku }</strong>
</div>
<Preview
className={ className }
parentClassName={ parentClassName }
sku={ sku }
/>
);
};

Expand Down
12 changes: 1 addition & 11 deletions assets/js/atomic/blocks/product-elements/sku/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import type { BlockEditProps } from '@wordpress/blocks';
import EditProductLink from '@woocommerce/editor-components/edit-product-link';
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
Expand All @@ -11,8 +10,6 @@ import { useEffect } from '@wordpress/element';
* Internal dependencies
*/
import Block from './block';
import withProductSelector from '../shared/with-product-selector';
import { BLOCK_TITLE, BLOCK_ICON } from './constants';
import type { Attributes } from './types';

const Edit = ( {
Expand All @@ -39,11 +36,4 @@ const Edit = ( {
);
};

export default withProductSelector( {
icon: BLOCK_ICON,
label: BLOCK_TITLE,
description: __(
'Choose a product to display its SKU.',
'woo-gutenberg-products-block'
),
} )( Edit );
export default Edit;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { registerBlockType } from '@wordpress/blocks';
import type { BlockConfiguration } from '@wordpress/blocks';
import classnames from 'classnames';

/**
* Internal dependencies
Expand All @@ -16,20 +17,37 @@ import {
BLOCK_DESCRIPTION as description,
} from './constants';

const { ancestor, ...configuration } = sharedConfig;

const blockConfig: BlockConfiguration = {
...sharedConfig,
...configuration,
apiVersion: 2,
title,
description,
icon: { src: icon },
usesContext: [ 'query', 'queryId', 'postId' ],
attributes,
ancestor: [
'woocommerce/all-products',
'woocommerce/single-product',
'core/post-template',
'woocommerce/product-meta',
],
attributes,
edit,
save: () => {
if (
attributes.isDescendentOfQueryLoop ||
attributes.isDescendentOfSingleProductTemplate
) {
return null;
}

return (
<div
className={ classnames( 'is-loading', attributes.className ) }
/>
);
},
};

registerBlockType( 'woocommerce/product-sku', { ...blockConfig } );
2 changes: 0 additions & 2 deletions assets/js/atomic/blocks/product-elements/sku/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.wc-block-components-product-sku {
margin-top: 0;
margin-bottom: $gap-small;
display: block;
text-transform: uppercase;
@include font-size(small);
Expand Down
2 changes: 2 additions & 0 deletions assets/js/atomic/blocks/product-elements/sku/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface Attributes {
productId: number;
isDescendentOfQueryLoop: boolean;
isDescendentOfSingleProductTemplate: boolean;
showProductSelector: boolean;
}
3 changes: 2 additions & 1 deletion src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ function( $template ) {
}

if ( 'single-product' === $template->slug ) {
if ( ! is_admin() ) {
if ( ! is_admin() && ! BlockTemplateUtils::template_has_legacy_template_block( $template ) ) {

$new_content = SingleProductTemplateCompatibility::add_compatibility_layer( $template->content );
$template->content = $new_content;
}
Expand Down
7 changes: 0 additions & 7 deletions src/BlockTypes/RelatedProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class RelatedProducts extends AbstractBlock {
*/
protected $parsed_block;


/**
* Initialize this block type.
*
Expand All @@ -35,7 +34,6 @@ protected function initialize() {
10,
2
);

}

/**
Expand All @@ -45,7 +43,6 @@ protected function register_block_type_assets() {
return null;
}


/**
* Update the query for the product query block.
*
Expand All @@ -70,8 +67,6 @@ public function update_query( $pre_render, $parsed_block ) {
}
}



/**
* Return a custom query based on attributes, filters and global WP_Query.
*
Expand All @@ -92,6 +87,4 @@ public function build_query( $query ) {
'post_status' => 'publish',
);
}


}
Loading