Remove local start_date and end_date base fields and fix existing dates

Created on 15 August 2023, over 1 year ago
Updated 10 November 2023, about 1 year ago

Problem/Motivation

start_date and end_date fields are now defined as BaseFields in the parent entity using a slightly different date format to what is expected. Previously the start and end date was stored as a "datetime" of with "'datetime_type' = 'date'". New basefield setting defined in \Drupal\commerce_promotion\Entity\Coupon uses "datetime" with "'datetime_type' = 'datetime'". At least in MySQL, these formats are stored in the same data-type of VARCHAR(20) so changing it should be a matter of reformatting.

All of the previous code for adding those fields to this version need to be removed, any previously written data updated to the new format.

At present, the start_date and end_date values when loaded do not work predictably when used in a site with the two date fields unexpectedly comparing different data formats eg "2023-08-03 >= 2023-08-03T06:00:00"

Steps to reproduce

Install commerce_coupon_conditions 8.x-1.1 with Commerce 8.x-2.18 or earlier, and then upgrade Commerce to a later version.

Patch with:
🐛 Add restriction a coupon usage for limited per-customer Fixed
Drupal 10 Compatibility Fixed

Proposed resolution

Remove all additional code related to the old fields, and add an update to fix all data.

The update should read each value and convert it from "2023-08-03" to "2023-08-03T00:00:00" or whichever appended time is appropriate. eg "23:59:59" for end_date.
NB: Update to include hook_XXXX_alter to allow custom setting of the date to deal with timezones.

Make a 1.2 release with the changes from the last 2 years.

Remaining tasks

  • Remove remaining deprecated code
  • Update which will run after base field state has been cleared from cache, to update all of the field data values
  • Make new release with these large changes documented

User interface changes

Incidental; Coupon Start/End Date now inherited from parent so UI includes time.

API changes

all *StartDate() and *EndDate() function are now moved to \Drupal\commerce_promotion\Entity\Coupon

Data model changes

Base Fields previously defined in this module are now handled by Commerce Promotion module. Data type in database remains the same.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇦🇺Australia elc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024