Skip to content

Commit

Permalink
Merge pull request #2690 from woocommerce/fix/hide-gtin-in-product-ed…
Browse files Browse the repository at this point in the history
…itor

[GTIN] Hide GTIN in product editor
  • Loading branch information
puntope authored Nov 22, 2024
2 parents 5d03086 + 4aece62 commit f17e3c0
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions js/src/blocks/product-select-with-text-field/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ export default function Edit( { attributes, context } ) {
options={ options }
value={ optionValue }
onChange={ handleSelectionChange }
disabled={ attributes.disabled }
/>
{ isSelectedCustomInput && (
<TextControl
type="text"
value={ text }
onChange={ handleTextChange }
disabled={ attributes.disabled }
/>
) }
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/Admin/Input/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +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(),
],
$this->block_attributes
);

// Set boolean disabled property only if it's needed.
if ( $this->is_readonly() ) {
$block_attributes['disabled'] = true;
}

return $block_attributes;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Admin/ProductBlocksService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/DependencyManagement/CoreServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/specs/product-editor/block-integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

/*
Expand Down Expand Up @@ -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 );
}
}

/*
Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/specs/product-editor/classic-integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

/*
Expand Down Expand Up @@ -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 );
}
}

/*
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/utils/product-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f17e3c0

Please sign in to comment.