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
Display "Origin" column in Orders table in Orders Analytics #46424
Conversation
`_wc_order_attribution_utm_source` can be null when the order is created via web admin.
This default is the same as found in `output_origin_column` function in plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php.
This is needed when there are more than 25 records in the Orders Analytics report.
Hi @ibndawood, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
@layoutd , since you are the main contributor for the order attribution feature, could you help to review and test this feature please? 🙏 Also cc my co-DRI @ibndawood , for your info. |
We loop through $orders_data instead of $order_attributions data. This is because $order_attributions may not have attributions data for some orders. By looping through $orders_data, it would automatically cater for "Unknown" data from get_origin_label function call, and we don't need to specify "Unknown" as default value for origin.
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 @ecgan, I've added my review with some feedback. Please take a look and let me know what do you think.
plugins/woocommerce/src/Admin/API/Reports/Orders/Controller.php
Outdated
Show resolved
Hide resolved
...commerce/tests/legacy/unit-tests/woocommerce-admin/reports/class-wc-tests-reports-orders.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
To make code shorter and easier to read, instead of long horizontal code.
@ibndawood , thanks for the review. I have addressed your comments and make the necessary changes. Could you do another round of review please? |
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.
Thank you, @ecgan, for the changes. I've tested the PR with and without HPOS. I've also followed the test instructions. The changes test well. I've added one input and some cosmetic changes. I've approved the PR. 🚀
Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
* Display channel column in Orders Analytics UI. * Set $data to false to not use cache. For development purpose. * Get channel info from order meta and put into extended_info. * Set channel in order item level. * Replace channel with get_origin_label in extended_info. * Remove unnneeded channel in orders_data. * Display origin instead of channel in table. * Fix lint errors. * Query order meta table based on HPOS. * Remove code for development purpose. * Add changelog. * Fix code comment. * Guard against null values. `_wc_order_attribution_utm_source` can be null when the order is created via web admin. * Set default origin label to "Unknown". This default is the same as found in `output_origin_column` function in plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php. * Support server side report download. This is needed when there are more than 25 records in the Orders Analytics report. * Fix failed test. * Fix lint error. * Simplify code. We loop through $orders_data instead of $order_attributions data. This is because $order_attributions may not have attributions data for some orders. By looping through $orders_data, it would automatically cater for "Unknown" data from get_origin_label function call, and we don't need to specify "Unknown" as default value for origin. * Change "channel" to "attribution" object in controller. This is because we need more than one piece of information, so we need it to be an object with properties like `origin`, `device` etc. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> * Change `origin` string to `attribution` array in Orders DataStore. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> * Change origin string to attribution object. * Fix indexing after changing from origin string to attribution object. * Change from origin string to attribution object in table.js. * Simplify code. To make code shorter and easier to read, instead of long horizontal code. * Fix lint errors. * Fix failed test. * Fix lint error. * Fix retrieving origin in CSV export. * Use $wpdb->postmeta; cosmetic change. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> * Cosmetic change. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> * Sanitize order IDs by using absint. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> --------- Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
Note that the "Origin" column is changed to "Attribution" column in PR #46760. |
* Display channel column in Orders Analytics UI. * Set $data to false to not use cache. For development purpose. * Get channel info from order meta and put into extended_info. * Set channel in order item level. * Replace channel with get_origin_label in extended_info. * Remove unnneeded channel in orders_data. * Display origin instead of channel in table. * Fix lint errors. * Query order meta table based on HPOS. * Remove code for development purpose. * Add changelog. * Fix code comment. * Guard against null values. `_wc_order_attribution_utm_source` can be null when the order is created via web admin. * Set default origin label to "Unknown". This default is the same as found in `output_origin_column` function in plugins/woocommerce/src/Internal/Orders/OrderAttributionController.php. * Support server side report download. This is needed when there are more than 25 records in the Orders Analytics report. * Fix failed test. * Fix lint error. * Simplify code. We loop through $orders_data instead of $order_attributions data. This is because $order_attributions may not have attributions data for some orders. By looping through $orders_data, it would automatically cater for "Unknown" data from get_origin_label function call, and we don't need to specify "Unknown" as default value for origin. * Change "channel" to "attribution" object in controller. This is because we need more than one piece of information, so we need it to be an object with properties like `origin`, `device` etc. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> * Change `origin` string to `attribution` array in Orders DataStore. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> * Change origin string to attribution object. * Fix indexing after changing from origin string to attribution object. * Change from origin string to attribution object in table.js. * Simplify code. To make code shorter and easier to read, instead of long horizontal code. * Fix lint errors. * Fix failed test. * Fix lint error. * Fix retrieving origin in CSV export. * Use $wpdb->postmeta; cosmetic change. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> * Cosmetic change. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> * Sanitize order IDs by using absint. Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com> --------- Co-authored-by: Kader Ibrahim S <kader.ibrahim.s@a8c.com>
Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes #46383.
In this PR:
GET /wp-json/wc-analytics/reports/orders
endpoint is modified to return the origin data inextended_info.attribution.origin
in the order objects in the API response. Example screenshot below:Screenshot below shows the new "Origin" column in the Orders table in Orders Analytics:
Screenshot below shows the new "Origin" column in the exported CSV file:
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
NOTE: Orders Analytics has a cache in place. To test the code, you may refer to commit 1a48761 to disable caching.
/wp-admin/admin.php?page=wc-admin&path=%2Fanalytics%2Forders
/wp-admin/admin.php?page=wc-admin&path=%2Fanalytics%2Forders
Changelog entry
Significance
Type
Message
Comment