lat9 / gpsf

An update to the previous Numinix version, now supporting Zen Carts 1.5.6 and above (including 1.5.8a) as well as PHP versions 5.6 through 8.2.
GNU General Public License v2.0
2 stars 2 forks source link

PHP Fatal error when a product has an availability date in the future #14

Closed torvista closed 5 months ago

torvista commented 6 months ago

https://github.com/lat9/gpsf/blob/5b23df84745fb3db16c7acf4b3cd9f340f7b3b45/includes/classes/gpsfFeedGenerator.php#L803 it seems this should be $this->xmlWriter->writeElement('g:availability_date', date('Y-m-d', strtotime($product['products_date_available'] . 'T00:00:00')));

lat9 commented 6 months ago

I'm confused, that's how that line reads currently. strtotime returns an int and the code section prior to that line has verified that the products_date_available isn't null.

torvista commented 6 months ago

. 'T00:00:00' is appended to the strtotime result instead of being part of its parameter.

torvista commented 6 months ago

Wrong again, the 'T00:00:00' should be appended to the result of date.

drbyte commented 6 months ago

It's the date() function that's complaining that it's getting a string as its 2nd parameter. That's because the int from strtotime() is getting the T00:00:00 string appended to it, making it a string.

Should the T00:00:00 be appended to the 'Y-m-d' string instead? Or just to the end of the result of the call to date()?

torvista commented 6 months ago

just to the end of the result of the call to date()

the T: is part of the GMC spec https://support.google.com/merchants/answer/6324470?hl=en#Format

drbyte commented 6 months ago

From that spec:

If you don’t include a time, the start date will use 00:00:00, and the end date will use 23:59:59.

... which is probably reasonable in most cases.

drbyte commented 6 months ago

Google is big on using standardized RFC formats for things. Is there already a compliant RFC date/time string format in PHP's supported formats? Why not use that instead of hacking things together manually?

torvista commented 6 months ago

Again, when a future date is set:

PHP Fatal error: Uncaught TypeError: date(): Argument #2 ($timestamp) must be of type ?int, bool given in ...\includes\classes\gpsfFeedGenerator.php:791 Stack trace:

0 ...\includes\classes\gpsfFeedGenerator.php(791): date('c', false

from https://github.com/lat9/gpsf/blob/b9292604f51bc7b0d7441eefc6fa5e987c447cee/includes/classes/gpsfFeedGenerator.php#L791

as the value passed to strtotime is eg: 2024-03-20 00:00:00 00:00:00

which returns false.

lat9 commented 6 months ago

@torvista, next time, please open a new issue referencing a closed one; otherwise, I'm sure to miss the update!