Hi all
The snippet for product microdata builds a broken JSON if "pricevalidunitl" is not filled.
The bug apperas in valid data becouse the url field in metadata becomes last BUT it is followed by a comma that breaks JSON
The fix is to move the required comma before the addictional "pircevaliunitl" field and $extra variable
in sublayouts/snippets.php the code should look like the following that builds balid JSON
Starting at line 159:
<?php } ?>
"offers": {
"@type": "Offer",
"priceCurrency": "<?php echo $currency->_vendorCurrency_code_3; ?>",
"availability": "<?php echo $stockog; ?>",
"price": "<?php echo $product->prices['salesPrice']; ?>",
"url": "<?php echo $canonicalUrl; ?>"
<?php if ($priceUntil) { ?>
,"priceValidUntil": "<?php echo $priceUntil; ?>"
<?php }
if(strlen($extra)){
echo ",".$extra;
}
?>
--- end at line 172
@Milbo would you please take it in consideration?
Thank you for this fix. is added.
Btw, did you note the extra?
$extra = '';
if(!empty($product->customfieldsSorted['snippet'])){
foreach ($product->customfieldsSorted['snippet'] as $customfield) {
$extra .= '"'.$customfield->custom_title.'": "'.$customfield->customfield_value.'",';
}
$extra = substr($extra,0,-1);
}
So you can add your own snippets just bei a customfield.
Just wondering, what is the reason for building a JSON string manually instead of using json_encode()?
Someone did it that way and now it is a legacy
Great job as usual Milbo
Thank you
BTW the dev svn is out of sync now with version 4.2
I have a couple of tests on possible bugs :-)
Quote from: Milbo on August 14, 2023, 09:47:25 AM
Thank you for this fix. is added.
Btw, did you note the extra?
$extra = '';
if(!empty($product->customfieldsSorted['snippet'])){
foreach ($product->customfieldsSorted['snippet'] as $customfield) {
$extra .= '"'.$customfield->custom_title.'": "'.$customfield->customfield_value.'",';
}
$extra = substr($extra,0,-1);
}
So you can add your own snippets just bei a customfield.
Should work since some days again. I just had to commit the stuff of the last 2 months.
Yes svn works
Great job as usual @Milbo