This is one of those addons where the idea is great, the code is so old and just about impossible to properly update. It might be worth exploring to see if there are any other shopowners who might chip in to the cost and get the idea of the addon remade to modern coding standard.
Dates
The general idea with dates was to simplify simplify simplify using the HTML5 date system for display along with minor logic to write to and get from the database. The gremlin here is the TIME part of the date. The HTML datepicker requires DATE only, but Phoenix requires DATE & TIME, so inserting into the DB we add the time, then displaying we remove the time.
Example Display
Code: Select all
<div class="form-group row" id="zDate">
<label for="specialDate" class="col-form-label col-sm-3 text-left text-sm-right"><?= TEXT_SPECIALS_EXPIRES_DATE ?></label>
<div class="col-sm-9">
<?= new Input('expdate', ['min' => date('Y-m-d'), 'class' => 'form-control w-25', 'value' => substr($sInfo->expires_date ?? '', 0, 10), 'onfocus' => 'this.showPicker?.()'], 'date') ?>
</div>
</div>
This shows an date input box called "expdate";
'expdate'
which is set to today as the earliest date that can be chosen;
'min' => date('Y-m-d')
set to the relevant "form" bootstrap class for display;
'class' => 'form-control w-25'
and showing the
first 10 characters [in other words removing the time of the expiry date taken from the database [or Nothing if no date];
'value' => substr($sInfo->expires_date ?? '', 0, 10)
and set to open the datepicker when the input box is clicked [this is not needed, but gives a slightly nicer experience];
'onfocus' => 'this.showPicker?.()'
Inserting into Database
From the display of the datepicker,
data would be _POST'd as date only (eg); 2023-12-25
You need to do two things here. Add in TIME, then SAVE to database.
Adding Time
Code: Select all
$expdate = Text::input($_POST['expdate']);
if (Text::is_empty($expdate)) {
$expires_date = 'NULL';
} else {
$expires_date = date($expdate . ' H:i:s', strtotime('tomorrow -1 second'));
}
First see if any DATE was _POST'd;
if (Text::is_empty($expdate)) {
If NO, set expiry date to NULL;
$expires_date = 'NULL';
If YES, add TIME; $expires_date = date($expdate . ' H:i:s', strtotime('tomorrow -1 second'));
That YES, is slightly esoteric, but it basically says;
a/ what is the _POST'd expiry date
b/ set that date to the day after
c/ remove 1 second
So, example;
a/ 2023-12-25
b/ 2023-12-26 00:00:00
c/ 2023-12-25 23:59:59
At this point, $expiry_date = 2023-12-25 23:59:59;
Which is the date the user chose, and logic sets the end of the day.
Now you can insert to DB;
Code: Select all
$db->perform('specials', [
'products_id' => (int)$products_id,
'specials_new_products_price' => $specials_price,
'specials_date_added' => 'NOW()',
'expires_date' => $expires_date,
'status' => 1,
]);
This piece; 'expires_date' => $expires_date,
will either be 'NULL'
Or be '2023-12-25 23:59:59'
I hope this helps.