Skip to content

Commit c75ffbd

Browse files
committed
Updates
1 parent f457639 commit c75ffbd

File tree

8 files changed

+42
-22
lines changed

8 files changed

+42
-22
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ziorwebdev/wordpress-blocks",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "A collection of custom Gutenberg blocks designed to extend the WordPress block editor with icons, dynamic data, and flexible content composition.",
55
"type": "library",
66
"autoload": {

resources/blocks/add-to-cart/edit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useEffect, useMemo, useCallback, useRef } from '@wordpress/element';
44
import { useSelect, useDispatch } from '@wordpress/data';
55
import type { BlockInstance, BlockEditProps } from '@wordpress/blocks';
66
import { ProductSelector } from '@ziorweb-dev/product-selector';
7-
// import ProductSelector from '../../components/product-selector';
87
import type { Attributes } from './index';
98

109
function mergeClasses(existing = '', add = ''): string {
@@ -74,6 +73,7 @@ export default function Edit({ attributes, setAttributes, clientId }: BlockEditP
7473
<>
7574
<InspectorControls>
7675
<PanelBody title="Product" initialOpen>
76+
{ attributes.showProductSelector && (
7777
<ProductSelector
7878
value={selectedProduct.id ?? ''}
7979
onChange={(nextProduct: { id: string; label: string }) => {
@@ -85,7 +85,7 @@ export default function Edit({ attributes, setAttributes, clientId }: BlockEditP
8585
});
8686
}}
8787
/>
88-
88+
) }
8989
<ToggleControl
9090
label="Show quantity"
9191
checked={!!showQuantity}

resources/blocks/add-to-cart/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type Attributes = {
99
productId?: string;
1010
showQuantity?: boolean;
1111
quantity?: number;
12+
showProductSelector?: boolean;
1213
};
1314

1415
export const name = metadata.name;

resources/blocks/product-price/edit.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import { PanelBody, SelectControl, __experimentalText as Text } from '@wordpress
2323
/**
2424
* Internal dependencies
2525
*/
26-
// import ProductSelector from '../../components/product-selector';
2726
import metadata from '../../../src/blocks/ProductPrice/block.json';
28-
import { fetchProductInformation } from '../../components/product-selector/product-information';
2927
import { ProductSelector } from '@ziorweb-dev/product-selector';
3028

3129
type ProductValue = {
@@ -137,23 +135,28 @@ function Edit( { attributes, setAttributes, mergeBlocks, onReplace, style }: Pro
137135
{ helpText }
138136
</Text>
139137
) }
140-
138+
{ attributes.showProductSelector && (
141139
<ProductSelector
142140
value={ product ?? EMPTY_PRODUCT }
143-
onChange={ ( nextProduct: ProductValue ) => {
144-
// Reset guards if product cleared
145-
const nextId = nextProduct?.id ? String( nextProduct.id ) : '';
146-
if ( ! nextId ) {
147-
lastFetchedIdRef.current = '';
148-
reqSeqRef.current++;
149-
setAttributes( { product: nextProduct, content: '' } );
150-
return;
151-
}
152-
153-
setAttributes( { product: nextProduct } );
141+
onChange={(nextProduct: ProductValue) => {
142+
// Reset guards if product cleared
143+
const nextId = nextProduct?.id ? String(nextProduct.id) : '';
144+
if (!nextId) {
145+
lastFetchedIdRef.current = '';
146+
reqSeqRef.current++;
147+
setAttributes({ product: nextProduct, content: '' });
148+
return;
149+
}
150+
151+
setAttributes({ product: nextProduct });
152+
}}
153+
onProductInformationChange={ ( productInfo ) => {
154+
setAttributes( {
155+
content: productInfo?.price_html ?? '',
156+
} );
154157
} }
155158
/>
156-
159+
) }
157160
<SelectControl
158161
label={ __( 'HTML tag' ) }
159162
value={ tagName }

resources/blocks/product-rating/edit.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import { PanelBody, __experimentalText as Text } from '@wordpress/components';
2323
/**
2424
* Internal dependencies
2525
*/
26-
// import ProductSelector from '../../components/product-selector';
27-
import { fetchProductInformation } from '../../components/product-selector/product-information';
2826
import { ProductSelector } from '@ziorweb-dev/product-selector';
2927

3028
type ProductValue = {
@@ -125,7 +123,7 @@ function Edit( { attributes, setAttributes, mergeBlocks, onReplace, style }: Pro
125123
{ helpText }
126124
</Text>
127125
) }
128-
126+
{ attributes.showProductSelector && (
129127
<ProductSelector
130128
value={ product ?? EMPTY_PRODUCT }
131129
onChange={ ( nextProduct: ProductValue ) => {
@@ -139,8 +137,14 @@ function Edit( { attributes, setAttributes, mergeBlocks, onReplace, style }: Pro
139137
}
140138

141139
setAttributes( { product: nextProduct } );
140+
}}
141+
onProductInformationChange={ ( productInfo ) => {
142+
setAttributes( {
143+
content: productInfo?.rating_html ?? '',
144+
} );
142145
} }
143-
/>
146+
/>
147+
) }
144148
</PanelBody>
145149
</InspectorControls>
146150
<div className="woocommerce">

src/Blocks/AddToCart/block.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
"showQuantity": {
2626
"type": "boolean",
2727
"default": false
28+
},
29+
"showProductSelector": {
30+
"type": "boolean",
31+
"default": true
2832
}
2933
},
3034
"usesContext": [

src/Blocks/ProductPrice/block.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
"type": "string",
4343
"enum": ["h1", "h2", "h3", "h4", "h5", "h6", "p", "div", "span"],
4444
"default": "h2"
45+
},
46+
"showProductSelector": {
47+
"type": "boolean",
48+
"default": true
4549
}
4650
},
4751
"usesContext": [

src/Blocks/ProductRating/block.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
},
2929
"textAlign": {
3030
"type": "string"
31+
},
32+
"showProductSelector": {
33+
"type": "boolean",
34+
"default": true
3135
}
3236
},
3337
"usesContext": [

0 commit comments

Comments
 (0)