-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Check order type is set before returning to prevent notice. #35349
Conversation
Test Results SummaryCommit SHA: bb845bd
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
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.
Looks good! Approving, but not merging right away so you can review a note I left (I don't think we require a change, but wanted to check-in quickly to err on the safe side).
@@ -948,7 +948,7 @@ public function get_orders_type( $order_ids ) { | |||
*/ | |||
public function get_order_type( $order_id ) { | |||
$type = $this->get_orders_type( array( $order_id ) ); | |||
return $type[ $order_id ]; | |||
return $type[ $order_id ] ?? ''; |
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 a request for a change, as such, just an observation: I see a few differences between this and the established CPT implementation.
$cpt->get_order_type( $valid_product_id ); # => string(7) "product"
$cot->get_order_type( $valid_product_id ); # => strint(0) ""
$cpt->get_order_type( $invalid_id ); # => bool(false)
$cot->get_order_type( $invalid_id ); # => strint(0) ""
I think the approach here is 'more correct' (it correctly satisfies the documented interface, for one thing), and can't immediately think of a case where this difference will lead to issues, but figured I would note it.
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.
Yeah, I think CPT data store mimics the WP_Post behavior. On further thinking after your comment, I removed the return type (string?
) from the util method declaration, as it wouldn't have worked correctly with CPT store (and would have raised an error) in acebc8d. So probably another review is 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.
Good idea.
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.
LGTM, thanks!
Blocked from merging because of this issue, but I pushed a small commit to address that. As soon as checks pass we can merge.
...Re-running failed checks (seem like random and unrelated fails)... |
Hi @vedanshujain, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
* Check order type is set before returning to prevent notice. * Applied code standards. * Remove type declaration since its not consistent with CPT datastore. * Switch to a yoda condition (satisfy required linting check). Co-authored-by: barryhughes <3594411+barryhughes@users.noreply.github.com>
* Check order type is set before returning to prevent notice. (#35349) * Check order type is set before returning to prevent notice. * Applied code standards. * Remove type declaration since its not consistent with CPT datastore. * Switch to a yoda condition (satisfy required linting check). Co-authored-by: barryhughes <3594411+barryhughes@users.noreply.github.com> * Add readme entry for 35349 * Remove change file for 35349 * Update woocommerce.php to prep for 7.1.0-rc.2 Co-authored-by: Vedanshu Jain <vedanshu.jain.2012@gmail.com> Co-authored-by: barryhughes <3594411+barryhughes@users.noreply.github.com>
All Submissions:
Changes proposed in this Pull Request:
When getting order type of a non-order ID, we were emitting a warning. This PR fixes the warning by adding a check to make sure that order type exists before returning.
How to test the changes in this Pull Request:
Automattic\WooCommerce\Utilities\OrderUtil::is_order( $product_id );
Other information:
pnpm --filter=<project> changelog add
?FOR PR REVIEWER ONLY: