Update Easy Admin Specials

Open to all! Ask other shopowners for help.
Post Reply
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Update Easy Admin Specials

Post by Pierre_P »

I'm trying to update this admin specials to most recent changes but not getting past the dates that needs to be saved correctly into the database.
For some reason and ability i cant figure out where the issue are.
The start or end dates, if they are left empty it will save date as 0000-00-00 00:00:00 which is invalid and needs to be null if empty.

Anyone for a quick look perhaps?

Phoenix 1.0.8.20 with 8.21 updates, php8.2
You do not have the required permissions to view the files attached to this post.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4561
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 422 times

Re: Update Easy Admin Specials

Post by burt »

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.
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Re: Update Easy Admin Specials

Post by Pierre_P »

Thanks for this explanation @burt

For now when saving a special, database updates the NULL dates as empty values and not the NULL value giving me all zeros on date.

Let me take a short break and work through this step by step as you explained and see what i can come up with.
raiwa
Certified Developer
Posts: 1641
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Update Easy Admin Specials

Post by raiwa »

I do not know this one, but maybe advanced specials can replace it:
https://phoenixcart.org/forum/app.php/ ... _specials/
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Re: Update Easy Admin Specials

Post by Pierre_P »

Hey @raiwa
The only reason i have to fix this is because the column expires_date must not be saved as 0000-00-00 00:00:00
For the discount coupon addon, when the date is like this and you have your coupon code set to exclude specials then coupon can still be used on special items - too much too late ;)

Buying your Easy Discount addon(for me it is already outdated with the upcoming date picker) will save me many hours of figuring out how to get a date correctly displayed and saved and in the process i hopefully learn something new and apart from this i will modify it straight away to add filter for an addon Vendors whereby each item is assigned to a vendor.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply