-
Notifications
You must be signed in to change notification settings - Fork 21
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
Hide GTIN
field for new installs make readonly for existing installs
#2622
Conversation
…ed and what version of WC is installed
…readonly-for-exisitng
…-for-new-users-make-readonly-for-exisitng
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this 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:
And with the install later than 2.8.5 it's completely removed:
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/Admin/Input/Input.php
Outdated
* | ||
* @return InputInterface | ||
*/ | ||
public function set_readonly( $value ): InputInterface { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ) ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusted here a2c3654
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:
9.2.0
or higher is installed and Google for WooCommerce is installed for the first time theGTIN
field in G4W is hidden9.2.0
or higher is installed and Google for WooCommerce had already been installed on a website then theGTIN
field in G4W is read-only9.2.0
is installed then theGTIN
field in G4W continues to function as it previously didAdditionally, 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:
Detailed test instructions:
update/2615-hide-gtin-for-new-users-make-readonly-for-exisitng
on a site with WC9.1.0
installed that has already onboarded with Google for WooCommerceGTIN
field is available on theGoogle for WooCommerce
tab9.2.0
or higherGTIN
field is read-only and the tooltip directs merchants to theInventory
tabwp option update gla_install_version 2.8.4
GTIN
field is not displayed on theGoogle for WooCommerce
tab when editing a productChangelog entry