I am using Magento 2, I used the structed data testing tools and all of my 600+ products have 8 warnings of which are some important ones such as image, availability, url

How do I correct this?

Some of the fields such as price, name etc are completed

2 Answers 2


You can add below code in one file (catalog_product_view handler) and make adjustments accordingly. It will help to add all options of structured data. Hope this helps

$_product = $this->getProduct();
$summaryModel = $block->getReviewSummary();
$reviewCount = $summaryModel->getReviewsCount();
if (!$reviewCount) {
    $reviewCount = 0;
$ratingSummary = ($summaryModel->getRatingSummary()) ? $summaryModel->getRatingSummary() : 20;

<div itemscope itemtype="http://schema.org/Product">
    <meta itemprop="name" content="<?php /* @escapeNotVerified */ echo $block->escapeQuote($block->stripTags($_product->getName())); ?>" />
    <meta itemprop="image" content="<?php /* @escapeNotVerified */ echo $block->stripTags($block->getImage($_product, 'product_base_image')->getImageUrl()); ?>" />
    <meta itemprop="description" content="<?php /* @escapeNotVerified */ echo $block->stripTags($_product->getDescription()); ?>" />
    <meta itemprop="url" content="<?php /* @escapeNotVerified */ echo $block->stripTags($_product->getProductUrl()); ?>" />
    <meta itemprop="sku" content="<?php /* @escapeNotVerified */ echo $block->stripTags($_product->getSku()); ?>" />
    <div itemtype="http://schema.org/AggregateRating" itemscope itemprop="aggregateRating">
        <meta itemprop="worstRating" content="1" />
        <meta itemprop="bestRating" content="5" />
        <meta itemprop="ratingValue" content="<?php echo $ratingSummary / 20 ; ?>" />
        <meta itemprop="reviewCount" content="<?php echo $reviewCount; ?>" />
    <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        <meta itemprop="priceCurrency" content="<?php echo $block->getCurrencyCode() ?>" />
        <meta itemprop="price" content="<?php echo $_product->getFinalPrice(); ?>" />
        <?php if ($_product->isAvailable()): ?>
            <link itemprop="availability" href="http://schema.org/InStock" />
        <?php else : ?>
            <link  itemprop="availability" href="http://schema.org/OutOfStock" />
        <?php endif ?>
  • thanks for that, where would this file be located in Magento 2?
    – sarah
    Jun 28, 2019 at 12:19
  • this is my custom file.. you need to add this in catalog_product_view page as custom file.. This is not by default template file
    – nishu
    Jun 28, 2019 at 12:25

Actually the perfect way of doping this is to follow goolgle mark up structure: Here it is:

  <div itemtype="http://schema.org/Product" itemscope>
    <meta itemprop="mpn" content="925872" />
    <meta itemprop="name" content="Executive Anvil" />
    <link itemprop="image" href="https://example.com/photos/16x9/photo.jpg" />
    <link itemprop="image" href="https://example.com/photos/4x3/photo.jpg" />
    <link itemprop="image" href="https://example.com/photos/1x1/photo.jpg" />
    <meta itemprop="description" content="Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height." />
    <div itemprop="offers" itemtype="http://schema.org/Offer" itemscope>
      <link itemprop="url" href="https://example.com/anvil" />
      <meta itemprop="availability" content="https://schema.org/InStock" />
      <meta itemprop="priceCurrency" content="USD" />
      <meta itemprop="itemCondition" content="https://schema.org/UsedCondition" />
      <meta itemprop="price" content="119.99" />
      <meta itemprop="priceValidUntil" content="2020-11-05" />
      <div itemprop="seller" itemtype="http://schema.org/Organization" itemscope>
        <meta itemprop="name" content="Executive Objects" />
    <div itemprop="aggregateRating" itemtype="http://schema.org/AggregateRating" itemscope>
      <meta itemprop="reviewCount" content="89" />
      <meta itemprop="ratingValue" content="4.4" />
    <div itemprop="review" itemtype="http://schema.org/Review" itemscope>
      <div itemprop="author" itemtype="http://schema.org/Person" itemscope>
        <meta itemprop="name" content="Fred Benson" />
      <div itemprop="reviewRating" itemtype="http://schema.org/Rating" itemscope>
        <meta itemprop="ratingValue" content="4" />
        <meta itemprop="bestRating" content="5" />
    <meta itemprop="sku" content="0446310786" />
    <div itemprop="brand" itemtype="http://schema.org/Thing" itemscope>
      <meta itemprop="name" content="ACME" />

You can follow this: https://search.google.com/structured-data/testing-tool

But for your site you have to place this code at specific place where need. Not whole code a needed snipet you can take from here and you have to put in your phtml file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.