Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide GTIN field for new installs make readonly for existing installs #2622

Conversation

martynmjones
Copy link
Contributor

@martynmjones martynmjones commented Sep 20, 2024

Changes proposed in this Pull Request:

Adds restrictions to the GTIN field in Google for WooCommerce depending on the version of WooCommerce installed and what version of Google for WooCommerce was first installed.

The following conditions apply:

  1. If WooCommerce 9.2.0 or higher is installed and Google for WooCommerce is installed for the first time the GTIN field in G4W is hidden
  2. If WooCommerce 9.2.0 or higher is installed and Google for WooCommerce had already been installed on a website then the GTIN field in G4W is read-only
  3. If any version of WooCommerce lower than 9.2.0 is installed then the GTIN field in G4W continues to function as it previously did

Additionally, a new option is added called INSTALL_VERSION for tracking what version of Google for WooCommerce was first installed on a website 43a76c3.

Closes #2615

Screenshots:

Screenshot 2024-09-20 at 17 46 09

Detailed test instructions:

  1. Checkout update/2615-hide-gtin-for-new-users-make-readonly-for-exisitng on a site with WC 9.1.0 installed that has already onboarded with Google for WooCommerce
  2. Add or edit a product and confirm that the GTIN field is available on the Google for WooCommerce tab
  3. Update WooCommerce to version 9.2.0 or higher
  4. Add or edit a product and confirm that the GTIN field is read-only and the tooltip directs merchants to the Inventory tab
  5. Install the extension from this branch on a new test site and go through onboarding
    • Alternatively, run the following WP Cli command to simulate the first install
      wp option update gla_install_version 2.8.4
  6. Confirm that the GTIN field is not displayed on the Google for WooCommerce tab when editing a product

Changelog entry

Update - Restrict the GTIN field based on the version of WooCommerce installed and the initial version of G4W installed

@martynmjones martynmjones self-assigned this Sep 20, 2024
@github-actions github-actions bot added the changelog: update Big changes to something that wasn't broken. label Sep 20, 2024
@martynmjones martynmjones changed the base branch from develop to add/support-core-gtin-field September 23, 2024 18:02
@martynmjones martynmjones requested a review from a team September 24, 2024 21:40
@martynmjones martynmjones marked this pull request as ready for review September 24, 2024 21:40
src/Admin/Input/Input.php Outdated Show resolved Hide resolved
src/Admin/Input/Input.php Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 6, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.

Project coverage is 65.5%. Comparing base (b29ce70) to head (a2c3654).
Report is 15 commits behind head on add/support-core-gtin-field.

Files with missing lines Patch % Lines
src/Admin/Product/Attributes/Input/GTINInput.php 88.9% 1 Missing ⚠️
src/Internal/InstallTimestamp.php 0.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                       Coverage Diff                        @@
##             add/support-core-gtin-field   #2622      +/-   ##
================================================================
+ Coverage                           62.7%   65.5%    +2.8%     
- Complexity                             0    4608    +4608     
================================================================
  Files                                319     474     +155     
  Lines                               5074   19299   +14225     
  Branches                            1231       0    -1231     
================================================================
+ Hits                                3180   12638    +9458     
- Misses                              1721    6661    +4940     
+ Partials                             173       0     -173     
Flag Coverage Δ
js-unit-tests ?
php-unit-tests 65.5% <92.3%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/Admin/Input/Input.php 100.0% <100.0%> (ø)
src/Admin/Product/Attributes/AttributesForm.php 97.3% <100.0%> (ø)
src/Admin/Product/Attributes/Input/GTINInput.php 92.9% <88.9%> (ø)
src/Internal/InstallTimestamp.php 0.0% <0.0%> (ø)

... and 789 files with indirect coverage changes

@puntope puntope requested a review from a team October 16, 2024 13:50
@puntope puntope self-assigned this Oct 17, 2024
Copy link
Contributor

@mikkamp mikkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the changes here. I have done the testing and I can confirm that the field is shown as normal for WC < 9.2. For newer versions of WC it's shown as a read only field:
image

And with the install later than 2.8.5 it's completely removed:
image

Should we keep a note that we need to tweak that version, I notice it's already been bumped from 2.8.4 > 2.8.5 but by the time we release this we might be at a newer version.

I went through the code and added a few opinionated comments, but these aren't strictly necessary to merge this PR, so I've gone ahead and approved anyway.

/**
* @var bool
*/
protected $is_readonly = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really necessary since we don't do it in most other classes. But in theory we support PHP 7.4+ which means we can declare type for class properties. Just looks odd to set the type only in the doc-block and not actually restrict it in the class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I didn't do it is because the rest of the files (and other files like this one) have not the type set neither. So I bet for consistency in regards this topic.

*
* @return InputInterface
*/
public function set_readonly( $value ): InputInterface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment here, if we are stating in the doc-block that $value should be a bool why don't we restrict it by setting the type? That's supported well before PHP 7.4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted here fa973aa

@@ -24,5 +35,28 @@ public function __construct() {

$this->set_label( __( 'Global Trade Item Number (GTIN)', 'google-listings-and-ads' ) );
$this->set_description( __( 'Global Trade Item Number (GTIN) for your item. These identifiers include UPC (in North America), EAN (in Europe), JAN (in Japan), and ISBN (for books)', 'google-listings-and-ads' ) );
$this->set_options_object( woogle_get_container()->get( OptionsInterface::class ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a little confusing to me. In other classes we use the OptionsAwareTrait which will automatically set the Options object within the class so we don't need to set it for each class individually. However for an input field it's not shared within the container class so it doesn't automatically set this object.

Since this class differs and it only needs to access options once, my suggestion would be to not use the OptionsAwareTrait and get the options object only once when needed. For example:

		$options         = woogle_get_container()->get( OptionsInterface::class );
		$initial_version = $options->get( OptionsInterface::INSTALL_VERSION, false );

It would make it harder to mock, but I don't see us testing with a mocked options object for this class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted here a2c3654

@puntope
Copy link
Contributor

puntope commented Oct 18, 2024

Should we keep a note that we need to tweak that version, I notice it's already been bumped from 2.8.4 > 2.8.5 but by the time we release this we might be at a newer version.

Correct @mikkamp Thanks for catching that. Added here #2648

@puntope puntope merged commit 4f6c307 into add/support-core-gtin-field Oct 19, 2024
12 checks passed
@puntope puntope deleted the update/2615-hide-gtin-for-new-users-make-readonly-for-exisitng branch October 19, 2024 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: update Big changes to something that wasn't broken.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GTIN] Hide the Global Trade Item Number field for new users and make read-only for existing users
3 participants