-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add helper method to get WooCommerce object meta value #723
Open
nmolham-godaddy
wants to merge
5
commits into
master
Choose a base branch
from
mwc-17547/get-wc-object-meta-value-helper
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
18f7def
Add helper method to get WooCommerce object meta value based on its d…
nmolham-godaddy 3a6fc7a
Unit test SV_WC_Helper::getWooCommerceObjectMetaValue method
nmolham-godaddy 5249fea
Add preserveGlobalState annotation
nmolham-godaddy 9f45812
Drop the dependency on OrderUtil, add a compat method with tests inst…
ajaynes-godaddy 287c7be
Rename test methods to remove OrderUtil references.
ajaynes-godaddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Automattic\WooCommerce\Utilities; | ||
|
||
class OrderUtil | ||
{ | ||
public static function get_post_or_object_meta(?\WP_Post $post, ?\WC_Data $data, string $key, bool $single) | ||
{ | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Reading through the Woo source code, I understand what you have here will absolutely work for any WC class that extends
WC_Data
(such as products).Just wondering if it's at all weird/risky to use the
OrderUtil
class anyway? That class is described as a utility class for orders, and it does work with products anyway, but do you think there's a risk of that ever changing so that it is orders only?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.
Good question, as far as I can tell, the same
OrderUtil
class is used in many places in WC codebase to get all sort of meta data for objects despite being orders or not! I know it is weird and sounds risky, but if you look intoOrderUtil::get_post_or_object_meta
source code, it doesn't case if the passed object is an order or not, it just loos for theWC_Data
orWP_Post
I can't find an equivalent to is within WC codebase for products or any other WC_Data/WP_Post based objects
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.
Knowing it's considered to be an internal utility class, it might not be the worst idea to abstract the source of
get_post_or_object_meta()
to our own trait or helper.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.
At first I thought about doing so, but I remembered how many time WC change stuff internally that causes compatibility issues. So, the idea here is to use their implementation with fallback with our own implementation.
Make sense?
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 think I'm going to try just adding it as a second method to the helper, see how annoying the tests are to write.
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.
Added the compat method in 9f45812 and 287c7be
Feel free to revert or adjust as needed.
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.
That looks good to me, how about you @agibson-godaddy, what do you think?