Schema JSON-LD For Product Review Mod - Needs Comma
Posted: Tue Jan 08, 2019 4:08 am
Hi Guys!
I'm not a coder and I'm trying to make my modification schema module work. Site is in a localhost.
Module was found and downloaded from Github:
https://github.com/CyberFoxDigital/cf-o ... uct-schema
The module was tested to work on v2.3.0.2, but there is a glitch, when there are more than 1 review.
I've added a block of code to show a review - copied from another free module and pasted it.
Below is the parsed output, tested with Google Structured Data Testing Tool and it throws error because it has no comma (,) after each review. It should have a comma to separate them.
The Valid One
Tested here:
https://search.google.com/structured-data/testing-tool
The Product Schema Code
I'm not a coder and I'm trying to make my modification schema module work. Site is in a localhost.
Module was found and downloaded from Github:
https://github.com/CyberFoxDigital/cf-o ... uct-schema
The module was tested to work on v2.3.0.2, but there is a glitch, when there are more than 1 review.
I've added a block of code to show a review - copied from another free module and pasted it.
Below is the parsed output, tested with Google Structured Data Testing Tool and it throws error because it has no comma (,) after each review. It should have a comma to separate them.
Code: Select all
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "00-Test Product",
"image": "http://example.com/image//products/product-image-placeholder.jpg",
"description": "Product Description here.",
"mpn": "mpn-xxx",
"sku": "sku-xxx",
"brand": {
"@type": "Thing",
"name": "Furniture Suppliers"
},
"review": [
{
"@type": "Review",
"author": "Claudinee Pacheco",
"datePublished": "01/07/2019",
"description": "Review text here.",
"name": "Claudinee Pacheco",
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "5",
"worstRating": "1"
}
}
{
"@type": "Review",
"author": "Doland Trum",
"datePublished": "01/07/2019",
"description": "Review text here..",
"name": "Doland Trum",
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "5",
"worstRating": "1"
}
}
],
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "5",
"reviewCount": "2"
},
"offers": {
"@type": "Offer",
"url": "http://example.com/test-product",
"priceCurrency": "GBP",
"price": "224.00",
"priceValidUntil": "2020-12-30",
"availability": "http://schema.org/InStock",
"seller": {
"@type": "Organization",
"name": "Zenos 5"
}
}
}
</script>
Tested here:
https://search.google.com/structured-data/testing-tool
Code: Select all
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "00-Test Product",
"image": "http://example.com/image//products/product-image-placeholder.jpg",
"description": "Product Description here.",
"mpn": "mpn-xxx",
"sku": "sku-xxx",
"brand": {
"@type": "Thing",
"name": "Furniture Suppliers"
},
"review": [
{
"@type": "Review",
"author": "Claudinee Pacheco",
"datePublished": "01/07/2019",
"description": "Review text here.",
"name": "Claudinee Pacheco",
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "5",
"worstRating": "1"
}
},
{
"@type": "Review",
"author": "Doland Trum",
"datePublished": "01/07/2019",
"description": "Review text here..",
"name": "Doland Trum",
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "5",
"worstRating": "1"
}
}
],
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "5",
"reviewCount": "2"
},
"offers": {
"@type": "Offer",
"url": "http://example.com/test-product",
"priceCurrency": "GBP",
"price": "224.00",
"priceValidUntil": "2020-12-30",
"availability": "http://schema.org/InStock",
"seller": {
"@type": "Organization",
"name": "Zenos 5"
}
}
}
</script>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Product Schema LD+JSON</name>
<code>0306150316181504210320190308051301</code>
<version>1.0</version>
<author>Cyber Fox</author>
<link>https://github.com/CyberFoxDigital</link>
<file path="catalog/controller/product/product.php">
<operation info="Adding the reviews variable">
<search><![CDATA[$data['tags'] = array();]]></search>
<add position="before"><![CDATA[
$resultss = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id']);
foreach ($resultss as $result) {
$data['reviewss'][] = array(
'author' => $result['author'],
'text' => nl2br($result['text']),
'rating' => (int)$result['rating'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
);
}
]]></add>
</operation>
</file>
<file path="catalog/controller/product/product.php">
<operation>
<search><![CDATA[$data['model'] = $product_info['model'];]]></search>
<add position="after"><![CDATA[ $data['mpn'] = $product_info['mpn'];
$data['sku'] = $product_info['sku'];
$data['seller'] = $this->config->get('config_name');
$data['availability'] = $product_info['quantity'] > 0 ? 'InStock' : 'OutOfStock';
]]></add>
</operation>
</file>
<operation>
<search><![CDATA[<?php echo $footer; ?>]]></search>
<add position="before"><![CDATA[<?php if(!empty($thumb) && (!empty($sku) || !empty($mpn))){ ?>
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "<?php echo $heading_title; ?>",
"image": "<?php echo preg_replace('/\-\d+x\d+\./','.',str_replace('cache/', '', $thumb)); ?>",
"description": "<?php echo strlen(trim(strip_tags($description))) > 200 ? substr(trim(strip_tags($description)), 0, 197) . "..." : trim(strip_tags($description)); ?>",
<?php if(!empty($mpn)){?>
"mpn": "<?php echo $mpn; ?>",
<?php } ?><?php if(!empty($sku)){?>
"sku": "<?php echo $sku; ?>",
<?php } ?><?php if(!empty($manufacturer)){?>
"brand": {
"@type": "Thing",
"name": "<?php echo $manufacturer; ?>"
},
"review": [
<?php foreach($reviewss as $review) { ?>
{
"@type": "Review",
"author": "<?php echo $review['author'];?>",
"datePublished": "<?php echo $review['date_added'];?>",
"description": "<?php echo $review['text'];?>",
"name": "<?php echo $review['author'];?>",
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "<?php echo $review['rating'];?>",
"worstRating": "1"
}
}
<?php } ?>
],
<?php } ?><?php if($rating && $reviews) { ?>
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "<?php echo $rating ?>",
"reviewCount": "<?php echo preg_replace('/.*(\d+).*/s', '$1', $reviews); ?>"
},
<?php } ?>
"offers": {
"@type": "Offer",
"url": "<?php echo $this->url->link('product/product', 'product_id=' . $product_id); ?>",
"priceCurrency": "<?php echo !empty($this->session->data['currency']) ? $this->session->data['currency'] : 'GBP'; ?>",
"price": "<?php echo $special ? preg_replace('/[^0-9\.]/', '', $special) : preg_replace('/[^0-9\.]/', '', $price); ?>",
"priceValidUntil": "2020-12-30",
"availability": "http://schema.org/<?php echo $availability; ?>",
"seller": {
"@type": "Organization",
"name": "<?php echo $seller; ?>"
}
}
}
</script>
<?php } ?>]]></add>
</operation>
</file>
</modification>