woocommerce/woocommerce-admin

Replace the `date_created` column name with a class property in the analytics DataStore

xristos3490 opened this issue · 1 comments

Hey team!

While working on extending several extensions into the WCA Analytics, we encountered an extensibility issue regarding the date's table column name.

More precisely, under the Automattic\WooCommerce\Admin\API\Reports\DataStore class, the date_created DB column appears hardcoded in a few places. See: https://github.com/woocommerce/woocommerce-admin/blob/main/src/API/Reports/DataStore.php#L502

This leads to difficulties when we need to extend analytics using custom DB tables rather than the lookup tables.

Describe the solution you'd like

Introduce a class property $date_column_name with default value (= date_created) and replace every occurrence with this protected prop.

Additional context

Currently, the Gift Cards extension extends the base DataStore class to replace all the methods that include the hardcoded values.

Another occurrence of this column name is inside a helper function in the TimeInterval class. See https://github.com/woocommerce/woocommerce-admin/blob/main/src/API/Reports/TimeInterval.php#L84

Having to handle this hand-coded value in more than one place, raises a question about the architecture of these helpers.
Perhaps we need to move the db_datetime_format() helper into the base DataStore class? Or add another param for the date column name?

Thoughts?

Closing this in favor of: woocommerce/woocommerce#32643