Cron Job - error log

Hi all.
I run a site for a charity, and it uses Commerce.
Within it there is the Abandoned Cart Module, which emails potential customers using a cron job. I have set it up as per the docs, but they aren’t being delivered.

The error log shows this, which refers to a timestamp issue I think? But it’s a bit over my head - can anyone decipher what is the problem here?

[29-Jan-2025 22:25:03 Europe/London] PHP Fatal error:  Uncaught TypeError: strtotime(): Argument #2 ($baseTimestamp) must be of type ?int, string given in /home/sitename/public_html/core/components/commerce_abandonedcart/model/commerce_abandonedcart/abandonedcartschedule.class.php:37
Stack trace:
#0 /home/sitename/public_html/core/components/commerce_abandonedcart/model/commerce_abandonedcart/abandonedcartschedule.class.php(37): strtotime('+1 day', '2024-06-14 20:4...')
#1 /home/sitename/public_html/core/components/commerce_abandonedcart/src/Cron/ScheduledRunner.php(95): AbandonedCartSchedule->conditionsMet(Object(AbandonedCartOrder_mysql))
#2 /home/sitename/public_html/assets/components/commerce_abandonedcart/run.php(44): PoconoSewVac\AbandonedCart\Cron\ScheduledRunner->run()
#3 {main}
  thrown in /home/sitename/public_html/core/components/commerce_abandonedcart/model/commerce_abandonedcart/abandonedcartschedule.class.php on line 37

The cron job looks like this:

/usr/local/bin/php /home/sitename/public_html/assets/components/commerce_abandonedcart/run.php > /dev/null 2>&1

Within the Commerce Abandoned Cart Module, the setting for send time are documented like this:

Enter in PHP strtotime format (ex. +1 day). Relative to when the abandoned cart was created.


So I have used:

 +1 day

But is the syntax wrong, and therefore causing the issue?

Any advice would be much appreciated!

Thanks
Andy

I think your +1 day is OK. the problem is that the second argument needs to be an integer timestamp and it’s a string. If that argument is coming from the MODX DB, it may be stored as a timestamp, but MODX automatically converts it to a human-readable string when you retrieve it. You can convert it to an integer by wrapping it in another strtotime() or you can leave it out, in which case PHP will use the current time as the base time.

Ah Ok thanks Bob - getting somewhere.

So the error is on this line in the file: abandonedcartschedule.class.php

  // Check if time is valid
        $sendTime = strtotime($this->get('send_time'), $cart->get('added_on'));
        if ($sendTime === false) {
            $this->adapter->log(1, '[AbandonedCart] Invalid time passed to strtotime "' . $sendTime . '" for schedule ' . $this->get('id'));
            return false;
        }

It must be this part wich requires the ‘strtotime’:

$cart->get('added_on')

But not sure how it should look?
Or are you saying I can remove that part entirely and just leave this:

// Check if time is valid
        $sendTime = strtotime($this->get('send_time'));
        if ($sendTime === false) {
            $this->adapter->log(1, '[AbandonedCart] Invalid time passed to strtotime "' . $sendTime . '" for schedule ' . $this->get('id'));
            return false;
        }

Thanks
Andy

Try replacing the line

with this instead

$sendTime = strtotime($this->get('send_time'), strtotime($cart->get('added_on')));

or maybe

$sendTime = strtotime($cart->get('added_on') . ' ' . $this->get('send_time'));

I don’t think this would work correctly.

OK thank you - I will try that now and report back!

The second option:

$sendTime = strtotime($cart->get('added_on') . ' ' . $this->get('send_time'));

has done something, although emails are still not sent. The error has now changed to:

[30-Jan-2025 14:40:03 Europe/London] PHP Fatal error:  Uncaught TypeError: comOrderEmailMessage::parseEmailField(): Argument #1 ($value) must be of type string, null given, called in /home/sitename/public_html/core/components/commerce/model/commerce/comorderemailmessage.class.php on line 70 and defined in /home/sitename/public_html/core/components/commerce/model/commerce/comorderemailmessage.class.php:136
Stack trace:
#0 /home/sitename/public_html/core/components/commerce/model/commerce/comorderemailmessage.class.php(70): comOrderEmailMessage->parseEmailField(NULL, Object(comCartOrder_mysql))
#1 /home/sitename/public_html/core/components/commerce_abandonedcart/model/commerce_abandonedcart/abandonedcartschedule.class.php(116): comOrderEmailMessage->send()
#2 /home/sitename/public_html/core/components/commerce_abandonedcart/src/Cron/ScheduledRunner.php(96): AbandonedCartSchedule->send(Object(AbandonedCartOrder_mysql))
#3 /home/sitename/public_html/assets/components/commerce_abandonedcart/run.php(44): PoconoSewVac\AbandonedCart\Cron\ScheduledRunner->run()
#4 {main}
  thrown in /home/sitename/public_html/core/components/commerce/model/commerce/comorderemailmessage.class.php on line 136

Not sure if this related, or additional though?

This is a different error.

And it seems to be now causes by the Commerce extra itself (and not the Abandoned Cart module). I don’t know if it can be fixed in the Abandoned Cart code. (It’s hard to say as Commerce is not open source).


Maybe a check could be added here that aborts the message being sent if the email field is empty. (But I’m not sure if that is even the cause of the issue.)

You should probably ask your question here.

My bad. I should have suggested that earlier.

OK thank you Bob will do.

OK - I will speak with Mark at Modmore and see what he says.

Thanks Harry!