Always use productTemplateId when available and use editedRecord in useEntityRecord hooks (#46395)
* Use editedRecord instead of record * Always use productTemplateId when available * Change private methods to protected in ProductVariationTemplate * Use editedRecord in hook useEntityRecord * Update changelogs * Restore attribute renamed by mistake * Change useProductTemplate unit test
This commit is contained in:
parent
d8ffca8d40
commit
450b06a1e1
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Always use productTemplateId when available and use editedRecord in useEntityRecord hooks
|
|
@ -155,7 +155,7 @@ export function BlockEditor( {
|
|||
{ postType }
|
||||
);
|
||||
|
||||
const { record: product } = useEntityRecord< Product >(
|
||||
const { editedRecord: product } = useEntityRecord< Product >(
|
||||
'postType',
|
||||
postType,
|
||||
productId
|
||||
|
|
|
@ -117,9 +117,9 @@ describe( 'useProductTemplate', () => {
|
|||
expect( result.current.productTemplate ).toBeUndefined();
|
||||
} );
|
||||
|
||||
it( 'should use the standard product template if the product type is variable', () => {
|
||||
it( 'should use the standard product template if no templateId is provided', () => {
|
||||
const { result } = renderHook( () =>
|
||||
useProductTemplate( 'template-1', { type: 'variable' } )
|
||||
useProductTemplate( undefined, { type: 'simple' } )
|
||||
);
|
||||
|
||||
expect( result.current.productTemplate?.id ).toEqual(
|
||||
|
|
|
@ -67,9 +67,7 @@ export const useProductTemplate = (
|
|||
const productType = product?.type;
|
||||
|
||||
const productTemplateIdToFind =
|
||||
productType === 'variable'
|
||||
? 'standard-product-template'
|
||||
: productTemplateId;
|
||||
productTemplateId || 'standard-product-template';
|
||||
|
||||
const productTypeToFind =
|
||||
productType === 'variable' ? 'simple' : productType;
|
||||
|
|
|
@ -60,7 +60,7 @@ export function useProductVariationsHelper() {
|
|||
'id'
|
||||
);
|
||||
|
||||
const { record: product } = useEntityRecord< Product >(
|
||||
const { editedRecord: product } = useEntityRecord< Product >(
|
||||
'postType',
|
||||
'product',
|
||||
productId
|
||||
|
|
|
@ -23,5 +23,5 @@ declare module '@wordpress/core-data' {
|
|||
kind: string,
|
||||
name: string,
|
||||
id: number | string
|
||||
): { record: T };
|
||||
): { record: T, editedRecord: T };
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: tweak
|
||||
|
||||
Change private methods to protected in ProductVariationTemplate
|
|
@ -64,7 +64,7 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
|
|||
/**
|
||||
* Adds the group blocks to the template.
|
||||
*/
|
||||
private function add_group_blocks() {
|
||||
protected function add_group_blocks() {
|
||||
$this->add_group(
|
||||
array(
|
||||
'id' => $this::GROUP_IDS['GENERAL'],
|
||||
|
@ -106,7 +106,7 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
|
|||
/**
|
||||
* Adds the general group blocks to the template.
|
||||
*/
|
||||
private function add_general_group_blocks() {
|
||||
protected function add_general_group_blocks() {
|
||||
$general_group = $this->get_group_by_id( $this::GROUP_IDS['GENERAL'] );
|
||||
$general_group->add_block(
|
||||
array(
|
||||
|
@ -193,7 +193,7 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
|
|||
/**
|
||||
* Adds the pricing group blocks to the template.
|
||||
*/
|
||||
private function add_pricing_group_blocks() {
|
||||
protected function add_pricing_group_blocks() {
|
||||
$is_calc_taxes_enabled = wc_tax_enabled();
|
||||
|
||||
$pricing_group = $this->get_group_by_id( $this::GROUP_IDS['PRICING'] );
|
||||
|
@ -315,7 +315,7 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
|
|||
/**
|
||||
* Adds the inventory group blocks to the template.
|
||||
*/
|
||||
private function add_inventory_group_blocks() {
|
||||
protected function add_inventory_group_blocks() {
|
||||
$inventory_group = $this->get_group_by_id( $this::GROUP_IDS['INVENTORY'] );
|
||||
$inventory_group->add_block(
|
||||
array(
|
||||
|
@ -425,7 +425,7 @@ class ProductVariationTemplate extends AbstractProductFormTemplate implements Pr
|
|||
/**
|
||||
* Adds the shipping group blocks to the template.
|
||||
*/
|
||||
private function add_shipping_group_blocks() {
|
||||
protected function add_shipping_group_blocks() {
|
||||
$shipping_group = $this->get_group_by_id( $this::GROUP_IDS['SHIPPING'] );
|
||||
$shipping_group->add_block(
|
||||
array(
|
||||
|
|
Loading…
Reference in New Issue