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

Commit cbdba5e

Browse files
authored
Merge branch 'trunk' into release/9.6.0
2 parents 5be8f4b + 2b58c5a commit cbdba5e

File tree

44 files changed

+1046
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1046
-200
lines changed

assets/js/atomic/blocks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ import './product-elements/category-list';
1313
import './product-elements/tag-list';
1414
import './product-elements/stock-indicator';
1515
import './product-elements/add-to-cart';
16+
import './product-elements/product-image-gallery';

assets/js/atomic/blocks/product-elements/price/block.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const Block = ( props: Props ): JSX.Element | null => {
8383
align={ textAlign }
8484
className={ wrapperClassName }
8585
regularPriceStyle={ style }
86+
priceStyle={ style }
8687
priceClassName={ priceClassName }
8788
currency={ currency }
8889
price={ prices.price }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "woocommerce/product-image-gallery",
3+
"version": "1.0.0",
4+
"title": "Product Image Gallery",
5+
"icon": "gallery",
6+
"description": "Display a product's images.",
7+
"category": "woocommerce",
8+
"supports": {
9+
"align": true,
10+
"reusable": false
11+
},
12+
"keywords": [ "WooCommerce" ],
13+
"usesContext": [ "postId", "postType", "queryId" ],
14+
"textdomain": "woo-gutenberg-products-block",
15+
"apiVersion": 2,
16+
"$schema": "https://schemas.wp.org/trunk/block.json"
17+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings';
5+
import { isEmptyObject } from '@woocommerce/types';
6+
import { useBlockProps } from '@wordpress/block-editor';
7+
import { BlockAttributes } from '@wordpress/blocks';
8+
import { Disabled } from '@wordpress/components';
9+
10+
/**
11+
* Internal dependencies
12+
*/
13+
import './editor.scss';
14+
15+
const Placeholder = () => {
16+
return (
17+
<div className="wc-block-editor-product-gallery">
18+
<img
19+
src={ `${ WC_BLOCKS_IMAGE_URL }block-placeholders/product-image-gallery.svg` }
20+
alt="Placeholder"
21+
/>
22+
<div className="wc-block-editor-product-gallery__other-images">
23+
{ [ ...Array( 4 ).keys() ].map( ( index ) => {
24+
return (
25+
<img
26+
key={ index }
27+
src={ `${ WC_BLOCKS_IMAGE_URL }block-placeholders/product-image-gallery.svg` }
28+
alt="Placeholder"
29+
/>
30+
);
31+
} ) }
32+
</div>
33+
</div>
34+
);
35+
};
36+
37+
type Context = {
38+
postId: string;
39+
postType: string;
40+
queryId: string;
41+
};
42+
43+
interface Props {
44+
attributes: BlockAttributes;
45+
context: Context;
46+
}
47+
48+
const Edit = ( { context }: Props ) => {
49+
const blockProps = useBlockProps();
50+
51+
if ( isEmptyObject( context ) ) {
52+
return (
53+
<div { ...blockProps }>
54+
<Disabled>
55+
<Placeholder />
56+
</Disabled>
57+
</div>
58+
);
59+
}
60+
// We have work on this case when we will work on the Single Product block.
61+
return '';
62+
};
63+
64+
export default Edit;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.wc-block-editor-product-gallery {
2+
img {
3+
width: 500px;
4+
height: 500px;
5+
}
6+
.wc-block-editor-product-gallery__other-images {
7+
img {
8+
width: 100px;
9+
height: 100px;
10+
margin: 5px;
11+
}
12+
}
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { gallery as icon } from '@wordpress/icons';
5+
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';
6+
import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils';
7+
8+
/**
9+
* Internal dependencies
10+
*/
11+
import edit from './edit';
12+
import metadata from './block.json';
13+
14+
registerBlockSingleProductTemplate( {
15+
registerBlockFn: () => {
16+
// @ts-expect-error: `registerBlockType` is a function that is typed in WordPress core.
17+
registerBlockType( metadata, {
18+
icon,
19+
edit,
20+
} );
21+
},
22+
unregisterBlockFn: () => {
23+
unregisterBlockType( metadata.name );
24+
},
25+
blockName: metadata.name,
26+
} );

assets/js/atomic/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './get-block-map';
22
export * from './create-blocks-from-template';
33
export * from './render-parent-block';
44
export * from './render-standalone-blocks';
5+
export * from './register-block-single-product-template';
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { getBlockType } from '@wordpress/blocks';
5+
import { subscribe, select } from '@wordpress/data';
6+
7+
export const registerBlockSingleProductTemplate = ( {
8+
registerBlockFn,
9+
unregisterBlockFn,
10+
blockName,
11+
}: {
12+
registerBlockFn: () => void;
13+
unregisterBlockFn: () => void;
14+
blockName: string;
15+
} ) => {
16+
let currentTemplateId: string | undefined;
17+
18+
subscribe( () => {
19+
const previousTemplateId = currentTemplateId;
20+
const store = select( 'core/edit-site' );
21+
currentTemplateId = store?.getEditedPostId() as string | undefined;
22+
23+
if ( previousTemplateId === currentTemplateId ) {
24+
return;
25+
}
26+
27+
const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ];
28+
29+
if ( parsedTemplate === null || parsedTemplate === undefined ) {
30+
return;
31+
}
32+
33+
const block = getBlockType( blockName );
34+
35+
if (
36+
block === undefined &&
37+
parsedTemplate.includes( 'single-product' )
38+
) {
39+
registerBlockFn();
40+
}
41+
42+
if ( block !== undefined ) {
43+
unregisterBlockFn();
44+
}
45+
}, 'core/edit-site' );
46+
};

assets/js/base/context/hooks/payment-methods/use-payment-method-interface.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,46 @@ export const usePaymentMethodInterface = (): PaymentMethodInterface => {
6060
return {
6161
// The paymentStatus is exposed to third parties via the payment method interface so the API must not be changed
6262
paymentStatus: {
63-
isPristine: store.isPaymentPristine(),
64-
isStarted: store.isPaymentStarted(),
63+
get isPristine() {
64+
deprecated( 'isPristine', {
65+
since: '9.6.0',
66+
alternative: 'isIdle',
67+
plugin: 'WooCommerce Blocks',
68+
link: 'https://github.com/woocommerce/woocommerce-blocks/pull/8110',
69+
} );
70+
return store.isPaymentIdle();
71+
}, // isPristine is the same as isIdle
72+
isIdle: store.isPaymentIdle(),
73+
isStarted: store.isExpressPaymentStarted(),
6574
isProcessing: store.isPaymentProcessing(),
66-
isFinished: store.isPaymentFinished(),
75+
get isFinished() {
76+
deprecated( 'isFinished', {
77+
since: '9.6.0',
78+
plugin: 'WooCommerce Blocks',
79+
link: 'https://github.com/woocommerce/woocommerce-blocks/pull/8110',
80+
} );
81+
return (
82+
store.hasPaymentError() || store.isPaymentReady()
83+
);
84+
},
6785
hasError: store.hasPaymentError(),
68-
hasFailed: store.isPaymentFailed(),
69-
isSuccessful: store.isPaymentSuccess(),
86+
get hasFailed() {
87+
deprecated( 'hasFailed', {
88+
since: '9.6.0',
89+
plugin: 'WooCommerce Blocks',
90+
link: 'https://github.com/woocommerce/woocommerce-blocks/pull/8110',
91+
} );
92+
return store.hasPaymentError();
93+
},
94+
get isSuccessful() {
95+
deprecated( 'isSuccessful', {
96+
since: '9.6.0',
97+
plugin: 'WooCommerce Blocks',
98+
link: 'https://github.com/woocommerce/woocommerce-blocks/pull/8110',
99+
} );
100+
return store.isPaymentReady();
101+
},
102+
isReady: store.isPaymentReady(),
70103
isDoingExpressPayment: store.isExpressPaymentMethodActive(),
71104
},
72105
activePaymentMethod: store.getActivePaymentMethod(),

assets/js/base/context/providers/cart-checkout/checkout-processor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const CheckoutProcessor = () => {
9292
paymentMethodData,
9393
isExpressPaymentMethodActive,
9494
hasPaymentError,
95-
isPaymentSuccess,
95+
isPaymentReady,
9696
shouldSavePayment,
9797
} = useSelect( ( select ) => {
9898
const store = select( PAYMENT_STORE_KEY );
@@ -102,7 +102,7 @@ const CheckoutProcessor = () => {
102102
paymentMethodData: store.getPaymentMethodData(),
103103
isExpressPaymentMethodActive: store.isExpressPaymentMethodActive(),
104104
hasPaymentError: store.hasPaymentError(),
105-
isPaymentSuccess: store.isPaymentSuccess(),
105+
isPaymentReady: store.isPaymentReady(),
106106
shouldSavePayment: store.getShouldSavePaymentMethod(),
107107
};
108108
}, [] );
@@ -130,7 +130,7 @@ const CheckoutProcessor = () => {
130130
const paidAndWithoutErrors =
131131
! checkoutHasError &&
132132
! checkoutWillHaveError &&
133-
( isPaymentSuccess || ! cartNeedsPayment ) &&
133+
( isPaymentReady || ! cartNeedsPayment ) &&
134134
checkoutIsProcessing;
135135

136136
// Determine if checkout has an error.

0 commit comments

Comments
 (0)