Ok, found it.
Create a new file in "includes/templates/YOUR_TEMPLATE/jscript" , and name it "structured_data_product.php"
In the new file paste the code from below
PHP Code:
<?php
// defines
define('STRUCTURED_DATA_CONDITION', 'NewCondition'); // DamagedCondition, NewCondition, RefurbishedCondition, UsedCondition
define('STRUCTURED_DATA_STOCK', 'InStock'); // Discontinued, InStock, InStoreOnly, LimitedAvailability, OnlineOnly, OutOfStock, PreOrder, PreSale, SoldOut
$ratingQuery = "SELECT reviews_id, reviews_rating
FROM " . TABLE_REVIEWS . "
WHERE products_id = " . $product_info->fields['products_id'];
$rating = $db->Execute($ratingQuery);
while (!$rating->EOF) {
$ratingArray[] = array('reviews_id' => $rating->fields['reviews_id'],
'reviews_rating' => $rating->fields['reviews_rating']);
$rating->MoveNext();
}
$ratingSum = array();
if ($ratingArray != '') {
foreach ($ratingArray as $value) {
$ratingSum[] = $value['reviews_rating'];
}
} else {
$ratingSum = 0;
}
$reviewCount = sizeof($ratingArray);
if ($reviewCount != 0) {
$ratingValue = array_sum($ratingSum) / $reviewCount;
} else {
$ratingValue = 0;
}
?>
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "<?php echo $products_name; ?>",
"image": "<?php echo (($request_type == 'SSL') ? HTTPS_SERVER . DIR_WS_HTTPS_CATALOG : HTTP_SERVER . DIR_WS_CATALOG ) . '/' . DIR_WS_IMAGES . $product_info->fields['products_image']; ?>",
"description": "<?php echo htmlspecialchars(zen_clean_html(stripslashes(zen_get_products_description($product_info->fields['products_id'], $_SESSION['languages_id']))), ENT_QUOTES); ?>",
"mpn": "<?php echo $products_model; ?>",
"brand": {
"@type": "Thing",
"name": "<?php echo $manufacturers_name; ?>"
},
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "<?php echo $ratingValue; ?>",
"reviewCount": "<?php echo $reviewCount; ?>"
},
"offers": {
"@type": "Offer",
"priceCurrency": "<?php echo $_SESSION['currency']; ?>",
"price": "<?php echo $products_price = (round(zen_get_products_base_price($product_info->fields['products_id']),2)); ?>",
"priceValidUntil": "2020-11-05",
"itemCondition": "http://schema.org/<?php echo STRUCTURED_DATA_CONDITION; ?>",
"availability": "http://schema.org/<?php echo STRUCTURED_DATA_STOCK; ?>",
"seller": {
"@type": "Organization",
"name": "<?php echo STORE_NAME ?>"
}
}
}
</script>
in the file "includes\templates\YOUR_TEMPLATE\templates\tpl_product_info_display.php", add at the bottom of the file:
PHP Code:
<?php /* BOF Zen4All structured_data_product */ ?>
<?php include ($template->get_template_dir('structured_data_product.php', DIR_WS_TEMPLATE, $current_page_base, 'jscript') . '/' . 'structured_data_product.php'); ?>
<?php /* EOF Zen4All structured_data_product */ ?>
Note: This was some experimental code, and it works on my site and my client's. The code may also need some optimization, like the defines at the top of the file.
Bookmarks