Woocommerce-admin: Analytics: Use /products/stats on categories report

Created on 11 Jan 2019  路  9Comments  路  Source: woocommerce/woocommerce-admin

Currently the Categories report is the last remaining place that uses a SwaggerHub endpoint. This should be updated to reference our own endpoint.

Note that this endpoint should be versioned to v4 as we're updating the namespace across the board.

This endpoint should return intervals and the following totals:
gross_revenue
items_sold
orders_count
products_count

Currently this endpoint needs to have the following query params for filtering:
page
per_page
after
before
order
orderby (enum -category_id, items_sold, net_revenue, orders_count, products_count, category)
categories (array of category IDs)

analytics

All 9 comments

Just thinking out loud, but maybe we could just modify /products/stats:

  • add gross_revenue (not sure if actually needed as https://github.com/woocommerce/wc-admin/issues/1072 changed categories endpoint to return net_revenue, so perhaps this one should return net_revenue, too?)
  • make it possible to order by category and category_id.

Otherwise /products/stats seems to cover all possible needs as far as I can see?

Great point @peterfabian - just verified that the data returned by the existing endpoint is sufficient - excellent! /cc @LevinMedia are we okay with using net_revenue on the categories report instead of gross_revenue? This would allow us to fully use the products stats endpoint as-is.

Yep @peterfabian @timmyc definitely - turns out I was mistaken when I originally designed it using GROSS. @joshuatf caught the error and did some 鉁╫n the products report to switch it to NET.

https://github.com/woocommerce/wc-admin/pull/1105

Categories report should be using NET too.

I updated the title of the issue and the labels to reflect the change here. Should be quite a bit easier to implement this than the new endpoint route. Props @peterfabian for the suggestion

Nice find @peterfabian !

make it possible to order by category and category_id.

I'm working out the best way to do this, although orderby isn't exactly the right term. It would need to filter /reports/products/stats by products which are assigned a category.

I have a few ideas to let the backend know it should filter by category:

  1. Modify the categories parameter to additionally accept a value like all. When looking at a single category or comparing categories, the parameter would behave as normal, eg categories=23,56.
  2. Create a new parameter, filterby which accepts a value category.
  3. Extend the WC_Admin_REST_Reports_Products_Stats_Controller to make new a categories endpoint and make modifications for filtering by category.

I'm thinking option 2 makes the most sense, but I wanted some input before investing too much time.

Thanks

@psealock for option 1 above, wouldn't omitting the categories param be the same as the notion of having the param support all?

for option 1 above, wouldn't omitting the categories param be the same as the notion of having the param support all?

Yes, but it will also return products that have no category. I imagine a store owner would only be interested in products with categories.

Checked the legacy report and it allows you to select "Uncategorized" as an option to view sales for those products. I think a good first step would just be to do option 1 above as-is, and just show uncategorized products too.

I think a good first step would just be to do option 1 above as-is, and just show uncategorized products too.

Sounds good, and simplifies things a lot.

Was this page helpful?
0 / 5 - 0 ratings