I have Opencart 3.0.4.0 and with php 8.x i get error with the default extension Google Base Feed:
Unknown: html_entity_decode(): Passing null to parameter #1 ($string) of type string is deprecated in \catalog\controller\extension\feed\google_base.php on line 39.
Do we have i little fix for that please?
If you are trying to use php8.4 you need to downgrade.
php 8 has strict usage of empty strings being passed these now need to be explicit.
Code: Select all
html_entity_decode($string ?? '');
html_entity_decode($string ?? '', ENT_QUOTES, 'UTF-8');
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
Code: Select all
$output .= '<g:brand><![CDATA[' . html_entity_decode($product['manufacturer'], ENT_QUOTES, 'UTF-8') . ']]></g:brand>';
Code: Select all
$output .= '<g:brand><![CDATA[' . html_entity_decode((string)$product['manufacturer'], ENT_QUOTES, 'UTF-8') . ']]></g:brand>';
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Can you go into detail why this and not that ?
https://stackoverflow.com/questions/717 ... eter-error
(going down to the bit about strict and Rector) I am still none the wiser - but you probably are ...
Thanks in advance
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
Yes worked. One other question:JNeuhoff wrote: ↑Sun Jun 15, 2025 8:08 pmCode: Select all
$output .= '<g:brand><![CDATA[' . html_entity_decode((string)$product['manufacturer'], ENT_QUOTES, 'UTF-8') . ']]></g:brand>';
The Google Base feed does not include a currency.
Google Merchant thinks we're using dollars (by default?), I guess...
But we live in Europe, so the currency should be EUR. Is this easy to adjust?
Now the feed gives:
<g:price>24.5</g:price>
But should be:
<g:price>24.5 EUR</g:price>
We could have used the Null Coalescing Operator, too, but I think in this case it's easier just to typecast the null into an empty string. I just tested the change, and it work fine.by mona wrote: ↑Sun Jun 15, 2025 8:34 pm@JNeuhoff
Can you go into detail why this and not that ?
https://stackoverflow.com/questions/717 ... eter-error
(going down to the bit about strict and Rector) I am still none the wiser - but you probably are ...
Thanks in advance
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Good point. What's your OpenCart default currency? I think it uses the configured default currency in the feed.maffe wrote: ↑Sun Jun 15, 2025 9:29 pmYes worked. One other question:JNeuhoff wrote: ↑Sun Jun 15, 2025 8:08 pmCode: Select all
$output .= '<g:brand><![CDATA[' . html_entity_decode((string)$product['manufacturer'], ENT_QUOTES, 'UTF-8') . ']]></g:brand>';
The Google Base feed does not include a currency.
Google Merchant thinks we're using dollars (by default?), I guess...
But we live in Europe, so the currency should be EUR. Is this easy to adjust?
Now the feed gives:
<g:price>24.5</g:price>
But should be:
<g:price>24.5 EUR</g:price>
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
I understand both, yet I am still none the wiser. My preference would always be to use Null Coalescing Operator, yours I understand would be to typecast the null into an empty string - I have no reason for my preference.JNeuhoff wrote: ↑Sun Jun 15, 2025 9:34 pmWe could have used the Null Coalescing Operator, too, but I think in this case it's easier just to typecast the null into an empty string. I just tested the change, and it work fine.by mona wrote: ↑Sun Jun 15, 2025 8:34 pm@JNeuhoff
Can you go into detail why this and not that ?
https://stackoverflow.com/questions/717 ... eter-error
(going down to the bit about strict and Rector) I am still none the wiser - but you probably are ...
Thanks in advance
This is some interesting points from a conversation from the stackoverflow linked above
The quick fix in most cases is to use the null coalescing operator to provide a default value as appropriate, so you don't need a long null check around every use. For instance, htmlspecialchars($something) can be replaced with htmlspecialchars($something ?? '')
Rector has the rule NullToStrictStringFuncCallArgRector to fix this:
- mb_strtolower($value);
+ mb_strtolower((string) $value);
I like that better than $value ?? '' –
Depends. One should be aware with the string cast that it turns arrays into the string "Array" while giving a warning (notice before PHPref. So you have to consider the appropriate handling beforehand (or at least should when applying automated changes to the overall code-base), to not run into the next maintenance problem. Rector likely does it this way because this is what would happened before, so it preserves the original behaviour. –
hakre
A big difference is that if you are running with strict_mode=1, then htmlspecialchars(42) is already an error; htmlspecialchars(42 ?? '') retains that error, htmlspecialchars((string)42) suppresses it. Similarly, (string)$object will call $object->__toString(), $object ?? '' will not. On the other hand, htmlspecialchars($mistypedVar ?? '') suppresses a Warning which htmlspecialchars((string)$mistypedVar) does not, so neither is a perfect replacement. –
IMSoP
My strong educated guess in context of the question is that htmlspecialchars() and trim() is a signal that not strict types but "string" types is what OP is aiming for, most likely code related to output (template etc.). This is not what strict_mode is of a particular benefit of, so would only add another error as false positive (even a real one, not a deprecation warning). The reason why the internal functions were typed was a different one than the strict_mode IIRC, and I have some sympathy for the cause here, but fear it's not only null but also the 42. –
this is a great way to hide genuine TypeErrors in the code... use ??'' instead. –
I'd like (as an addition, existing answers have my upvotes) to paint a different picture on how to see and tackle with such "problems". It does not make the outlined approaches less right or wrong and is merely an additional view which hopefully is of mutual benefit. And every project is different.
Cheat-Sheet
(string)$mixed - previous behaviour
$mixed ?? '' - error suppression for TypeError on null only
@ - full error suppression. you should document in/for your code-base where it is applicable to use.
@@ - if this comes up, it is likely an interesting spot to look into.
empty($mixed) ? '' : xxx($mixed) - carry the trash out, typical empty paralysis / mixed confusion, look for clusters, there is a chance the code-base can be greatly simplified. migrate to scalar types (PHP 7), pull in strict type handling from most-inner in outwards direction, use both PHP "classic" and "strict" type handling where applicable. PHP 7.0 assertions and PHP 8.1 deprecation messages can support here well.
I would be interested to know if anyone has an opinion, method or logic to share ?
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
My default currency in the shop is Euro.
I even completely removed the Dollar. But Google Merchant still shows prices in USD.
However, if we include 'EUR' in the feed (like in the example), it works correctly.
I think this needs to be adjusted in the default OpenCart Google Base extension?
Does anyone have a quick fix for this?
I think you are right! Looking at the docs in https://support.google.com/merchants/answer/6324371 the currency should indeed be included, such asmaffe wrote: ↑Tue Jun 17, 2025 4:18 amMy default currency in the shop is Euro.
I even completely removed the Dollar. But Google Merchant still shows prices in USD.
However, if we include 'EUR' in the feed (like in the example), it works correctly.
I think this needs to be adjusted in the default OpenCart Google Base extension?
Does anyone have a quick fix for this?
Code: Select all
<g:price>15.00 USD</g:price>
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Users browsing this forum: Amazon [Bot] and 60 guests