-
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
WooCommerce Subscriptions compatibility: Fix the visible issue of the product data tab and meta box for some unsupported product types #2087
Conversation
…o the product editing page by JS.
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 integration class doesn't actually participate in any runtime processing anymore now, but I'm not sure if it would be better to remove it entirely.
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.
What would be the downside of removing the file entirely?
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.
Originally I guess it might be ok to keep it as a reminder that this extension doesn't support the product types of WooCommerce Subscriptions. After second thoughts, I think it should be fine to remove it because the current way only uses an inclusive list of the supported product types. Other product types will naturally not be supported.
Removed in d013eaa
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #2087 +/- ##
===========================================
+ Coverage 58.3% 58.4% +0.1%
+ Complexity 4118 4113 -5
===========================================
Files 454 453 -1
Lines 17683 17651 -32
===========================================
Hits 10304 10304
+ Misses 7379 7347 -32
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.
Hey @eason9487, thanks for your work on this issue 🙌
Tested the branch locally with Subscriptions and Product Bundles. The GLA tab and channel visibility meta box now only appear if the product type is simple, variable, or bundle. So LGTM ✅
js/src/product-attributes/index.js
Outdated
const applicableProductTypes = new Set( [ | ||
// Simple product | ||
'simple', | ||
// Variable product | ||
'variable', | ||
// Product bundle from WooCommerce Product Bundles | ||
'bundle', | ||
] ); |
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.
Just have one additional comment about this list. Previously we had the PHP filter woocommerce_gla_supported_product_types
which allows an integration such as Bundles to add themselves to the list. We added this filter not only for the internal integrations we support, but also if there is a plugin which wants to add support for syncing their "specific" product type. With this list it's not possible to extend the supported product types. Can we pass this list dynamically to the JS so it's run through the woocommerce_gla_supported_product_types
filter?
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 the suggestion!
Since the original execution order of the related processing is:
- AssetsHandler->add_many
- AssetsHandler->register
- IntegrationInitializer->register and WooCommerceProductBundles->init_product_types
- AssetsHandler->enqueue_many
On the first call, the inline script glaData
is created along with the script file registration. However, the third call has not yet been made, which results in the supported product types not containing the 'bundle'
.
Therefore, I adjusted the execution order as follows in d13cdf6, so that the script registration will be called after the IntegrationInitializer->register
.
- IntegrationInitializer->register and WooCommerceProductBundles->init_product_types
- AssetsHandler->register_many: Combines the former
AssetsHandler->add_many
andAssetsHandler->register
- AssetsHandler->enqueue_many
And removed the former calls of AssetsHandler->add_many
and AssetsHandler->register
.
…e on the front-end side. Address #2087 (comment)
Hi @mikkamp, thanks for the suggestion. As there are quite a number of changes made for #2087 (comment), could you take another look at this PR? |
…e on the front-end side. Address #2087 (comment)
b8ed263
to
99d1cd1
Compare
…e on the front-end side. Address #2087 (comment)
99d1cd1
to
d13cdf6
Compare
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. I've taken some time to look over it and so far it looks good.
But I just wanted to note that previously we would call:
Asset::register
right after init
hook. Now it's called directly whenever we call AssetHandler::register
for the individual Asset
. In the case of the collection of admin assets that should be fine because we call register
on the hook admin_enqueue_scripts
.
But I'd like to test that a little further also on the frontend assets and ensure there aren't any other adverse affects from changing those timings. I'll continue testing on Monday.
|
||
/** | ||
* Class AssetsHandler | ||
* | ||
* @package Automattic\WooCommerce\GoogleListingsAndAds\Assets | ||
*/ | ||
final class AssetsHandler implements Registerable, AssetsHandlerInterface { | ||
final class AssetsHandler implements AssetsHandlerInterface { |
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.
I was a bit confused about the renaming of the add > register functions. If I recall correctly that name was previously avoided because it implemnted the Registerable interface. But I guess since you removed that here there is no issue with using the function name register
.
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.
If I understood it right, only when a class implements the Service
and Registerable
interfaces and is tagged with its interfaces via a AbstractServiceProvider
method like share_with_tags will be treated as a service and registered in GoogleListingsAndAdsPlugin
.
The previous AssetsHandler
didn't implement Service
and its interfaces were not tagged, so I think it should be fine to remove Registerable
and use the register method in this way. So that it also pairs and aligns with the enqueue
method in the perspective of wp_register_script
and wp_enqueue_script
.
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 the clarification. Yes that's correct that it needs to be both a Service
and Registerable
. The tagging isn't important as it will still fetch the classes even if it's not tagged.
I looked at all the assets further and they all seem to be registered/enqueued at the right time even after these changes. So that all looks good.
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. I've tested the assets and I can confirm that they are all loaded correctly with their associated data.
I just left one comment though about the data possibly conflicting. It's not a major blocker as it's not an issue right now. So I'll go ahead and approve this PR.
src/Admin/Admin.php
Outdated
$product_condition | ||
) ); | ||
) )->add_inline_script( ...$gla_data_inline_script_args ); |
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.
Based on the conditions we won't ever be on a WC Admin registered page and a (traditional) product edit page, so it's ok to pass the data to two separate scripts. I wonder though if this will always remain the case, like with the new product editing experience. Because in that case we would be setting glaData
twice on the page.
If applicableProductTypes
is all that's needed then why wouldn't we just pass that separately so we'd never be able to conflict:
) )->add_inline_script( ...$gla_data_inline_script_args ); | |
) )->add_inline_script( | |
[ | |
'glaProductData', | |
[ | |
'applicableProductTypes' => ProductSyncer::get_supported_product_types(), | |
], | |
] | |
); |
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 the suggestion.
It's uncertain if the new Product Edit page will have the case of setting glaData
twice. Indeed, it will be better to avoid possible conflicts in advance. Separated the inline script withe different variable names in 0468a73.
…ntial conflicts in the future. Address #2087 (comment)
Changes proposed in this Pull Request:
Closes #2086
Screenshots:
Kapture.2023-09-07.at.14.37.39.mp4
Detailed test instructions:
npm start
) if it's running.google-listings-and-ads/js/src/product-attributes/index.js
Lines 11 to 18 in f325aa1
Changelog entry