From e4f4710b5e752e06b1de75297cad5cd8c9d3f391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20P=C3=A9rez=20Pellicer?= <5908855+puntope@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:03:44 +0400 Subject: [PATCH 1/6] Hide or Disable GTIN in product Editor --- src/Admin/Input/Input.php | 1 + src/Admin/ProductBlocksService.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/Admin/Input/Input.php b/src/Admin/Input/Input.php index db54bac570..a9d0187b26 100644 --- a/src/Admin/Input/Input.php +++ b/src/Admin/Input/Input.php @@ -263,6 +263,7 @@ public function get_block_attributes(): array { 'property' => "meta_data.{$meta_key}", 'label' => $this->get_label(), 'tooltip' => $this->get_description(), + 'disabled' => $this->is_readonly() ], $this->block_attributes ); diff --git a/src/Admin/ProductBlocksService.php b/src/Admin/ProductBlocksService.php index a3843a6a81..312b5baf33 100644 --- a/src/Admin/ProductBlocksService.php +++ b/src/Admin/ProductBlocksService.php @@ -275,6 +275,12 @@ private function add_product_attribute_blocks( SectionInterface $section ): void $input_type = call_user_func( [ $attribute_type, 'get_input_type' ] ); $input = AttributesForm::init_input( new $input_type(), new $attribute_type() ); + // Avoid to render Inputs that are defined as hidden in the Input. + // i.e We don't render GTIN for new WC versions anymore. + if ( $input->is_hidden() ) { + continue; + } + if ( $is_variation_template ) { // When editing a variation, its product type on the frontend side won't be changed dynamically. // In addition, the property of `editedProduct.type` doesn't exist in the variation product. From 2561b9532b00bee37ae2db0d3ac1b83ae4fa9252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20P=C3=A9rez=20Pellicer?= <5908855+puntope@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:09:32 +0400 Subject: [PATCH 2/6] Disable GTIN for Product Editor when YOAST is active --- js/src/blocks/product-select-with-text-field/edit.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/src/blocks/product-select-with-text-field/edit.js b/js/src/blocks/product-select-with-text-field/edit.js index 4440fb76b5..fb0da0662c 100644 --- a/js/src/blocks/product-select-with-text-field/edit.js +++ b/js/src/blocks/product-select-with-text-field/edit.js @@ -86,12 +86,14 @@ export default function Edit( { attributes, context } ) { options={ options } value={ optionValue } onChange={ handleSelectionChange } + disabled={ attributes.disabled } /> { isSelectedCustomInput && ( ) } From 007fdbe912610f94bb70bad5e8bec8959991eef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20P=C3=A9rez=20Pellicer?= <5908855+puntope@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:17:23 +0400 Subject: [PATCH 3/6] Prevent "disable" attribute if is not needed --- src/Admin/Input/Input.php | 10 ++++++++-- .../Attributes/Input/AttributeInputCollectionTest.php | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Admin/Input/Input.php b/src/Admin/Input/Input.php index a9d0187b26..f9d46c2e89 100644 --- a/src/Admin/Input/Input.php +++ b/src/Admin/Input/Input.php @@ -258,15 +258,21 @@ public function set_block_attribute( string $key, $value ): InputInterface { public function get_block_attributes(): array { $meta_key = $this->prefix_meta_key( $this->get_id() ); - return array_merge( + $block_attributes = array_merge( [ 'property' => "meta_data.{$meta_key}", 'label' => $this->get_label(), 'tooltip' => $this->get_description(), - 'disabled' => $this->is_readonly() ], $this->block_attributes ); + + // Set boolean disabled property only if it's needed. + if ( $this->is_readonly() ) { + $block_attributes['disabled'] = true; + } + + return $block_attributes; } /** diff --git a/tests/Unit/Admin/Product/Attributes/Input/AttributeInputCollectionTest.php b/tests/Unit/Admin/Product/Attributes/Input/AttributeInputCollectionTest.php index 224f115ee6..606a0544b2 100644 --- a/tests/Unit/Admin/Product/Attributes/Input/AttributeInputCollectionTest.php +++ b/tests/Unit/Admin/Product/Attributes/Input/AttributeInputCollectionTest.php @@ -361,6 +361,7 @@ public function test_gtin_input() { 'property' => 'meta_data._wc_gla_gtin', 'label' => 'Global Trade Item Number (GTIN)', 'tooltip' => $description, + 'disabled' => true, ], ], $input->get_block_config() From c2f4f58691d568c573e12added5eb0df28e4dc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20P=C3=A9rez=20Pellicer?= <5908855+puntope@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:20:48 +0400 Subject: [PATCH 4/6] Fix E2E product editor --- tests/e2e/specs/product-editor/block-integration.test.js | 8 ++++++-- tests/e2e/utils/product-editor.js | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/e2e/specs/product-editor/block-integration.test.js b/tests/e2e/specs/product-editor/block-integration.test.js index f42854899f..6d1b663085 100644 --- a/tests/e2e/specs/product-editor/block-integration.test.js +++ b/tests/e2e/specs/product-editor/block-integration.test.js @@ -607,7 +607,9 @@ test.describe( 'Product Block Editor integration', () => { await editorUtils.save(); for ( const [ attribute, value ] of pairs ) { - await expect( attribute ).toHaveValue( value ); + if ( await attribute.isEditable() ) { + await expect( attribute ).toHaveValue( value ); + } } /* @@ -649,7 +651,9 @@ test.describe( 'Product Block Editor integration', () => { await editorUtils.save(); for ( const [ attribute, value ] of pairs ) { - await expect( attribute ).toHaveValue( value ); + if ( await attribute.isEditable() ) { + await expect( attribute ).toHaveValue( value ); + } } /* diff --git a/tests/e2e/utils/product-editor.js b/tests/e2e/utils/product-editor.js index 25b5e94474..a472f95141 100644 --- a/tests/e2e/utils/product-editor.js +++ b/tests/e2e/utils/product-editor.js @@ -67,6 +67,10 @@ async function getAvailableProductAttributesWithTestValues( async function setAttributeValue( locator, value ) { const tagName = await locator.evaluate( ( element ) => element.tagName ); + if ( ( await locator.isEditable() ) === false ) { + return; + } + if ( tagName === 'SELECT' ) { await locator.selectOption( value ); } else { From c5237022fd13baf32229c1eda5f57357b5b5e1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20P=C3=A9rez=20Pellicer?= <5908855+puntope@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:25:46 +0400 Subject: [PATCH 5/6] Fix E2E classic editor --- .../e2e/specs/product-editor/classic-integration.test.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/e2e/specs/product-editor/classic-integration.test.js b/tests/e2e/specs/product-editor/classic-integration.test.js index 5430346b8b..3eddfe2974 100644 --- a/tests/e2e/specs/product-editor/classic-integration.test.js +++ b/tests/e2e/specs/product-editor/classic-integration.test.js @@ -586,7 +586,9 @@ test.describe( 'Classic Product Editor integration', () => { await editorUtils.clickPluginTab(); for ( const [ attribute, value ] of pairs ) { - await expect( attribute ).toHaveValue( value ); + if ( await attribute.isEditable() ) { + await expect( attribute ).toHaveValue( value ); + } } /* @@ -631,7 +633,9 @@ test.describe( 'Classic Product Editor integration', () => { await editorUtils.gotoEditVariation(); for ( const [ attribute, value ] of pairs ) { - await expect( attribute ).toHaveValue( value ); + if ( await attribute.isEditable() ) { + await expect( attribute ).toHaveValue( value ); + } } /* From 4aece62718624378c7ebf83d00ccced2f2bf4295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20P=C3=A9rez=20Pellicer?= <5908855+puntope@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:52:58 +0400 Subject: [PATCH 6/6] Fix Conditional WP CLI sharing issue --- src/Internal/DependencyManagement/CoreServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Internal/DependencyManagement/CoreServiceProvider.php b/src/Internal/DependencyManagement/CoreServiceProvider.php index d18c76e69c..c3d192ed90 100644 --- a/src/Internal/DependencyManagement/CoreServiceProvider.php +++ b/src/Internal/DependencyManagement/CoreServiceProvider.php @@ -435,6 +435,6 @@ function ( ...$arguments ) { } // ClI Classes - $this->share_with_tags( WPCLIMigrationGTIN::class, ProductRepository::class, AttributeManager::class ); + $this->conditionally_share_with_tags( WPCLIMigrationGTIN::class, ProductRepository::class, AttributeManager::class ); } }