News:

Looking for documentation? Take a look on our wiki

Main Menu

Bug (and fix) for metadata snippet

Started by Alexb65, July 26, 2023, 12:10:59 PM

Previous topic - Next topic

Alexb65

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?

Milbo

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 I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Ghost

Just wondering, what is the reason for building a JSON string manually instead of using json_encode()?

Milbo

Someone did it that way and now it is a legacy
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Alexb65

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.

Milbo

Should work since some days again. I just had to commit the stuff of the last 2 months.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Alexb65

#6
Yes svn works

Great job as usual @Milbo