adding multiple product images to rich-snippet structured data using getMediaGalleryImages()Adding structured data / rich snippets to existing code without affecting templateRich Snippet Breadcrumbs IssueMagento 2 Import ErrorMagento 2 composer update with sample data removes uploaded images?What are the different parts of an image URL, and how to generate new sizes?Multi website Magento store (2.2.6) 404-error on /pub/media on one storeHow to stop magento to generate all types of images in cache on page visitMagento 2.3 Product image Urls 404Magento 2.3 adds white stripes while resizing a product image for a frontend product listMagento 2.3.2 Product Image Missing after version updating from 2.2.1

How is this kind of structure made?

First amendment and employment: Can a police department terminate an officer for speech?

Multirow in tabularx?

Blocking people from taking pictures of me with smartphone

try/finally with bash shell

Who are these characters/superheroes in the posters from Chris's room in Family Guy?

How does 'AND' distribute over 'OR' (Set Theory)?

Loading military units into ships optimally, using backtracking

Ex-contractor published company source code and secrets online

constant evaluation when using differential equations.

Are differences between uniformly distributed numbers uniformly distributed?

During the Space Shuttle Columbia Disaster of 2003, Why Did The Flight Director Say, "Lock the doors."?

A simple stop watch which I want to extend

How to avoid the "need" to learn more before conducting research?

On Math Looking Obvious in Retrospect

Does this Foo machine halt?

Is there a standardised way to check fake news?

Y2K... in 2019?

Can a fight scene, component-wise, be too complex and complicated?

Not going forward with internship interview process

The cat ate your input again!

Does a code snippet compile? Or does it get compiled?

If "more guns less crime", how do gun advocates explain that the EU has less crime than the US?

In a 2 layer PCB with a top layer densely populated, from an EMI & EMC point of view should the ground plane be on top, bottom or both and why?



adding multiple product images to rich-snippet structured data using getMediaGalleryImages()


Adding structured data / rich snippets to existing code without affecting templateRich Snippet Breadcrumbs IssueMagento 2 Import ErrorMagento 2 composer update with sample data removes uploaded images?What are the different parts of an image URL, and how to generate new sizes?Multi website Magento store (2.2.6) 404-error on /pub/media on one storeHow to stop magento to generate all types of images in cache on page visitMagento 2.3 Product image Urls 404Magento 2.3 adds white stripes while resizing a product image for a frontend product listMagento 2.3.2 Product Image Missing after version updating from 2.2.1






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm looking to add all media images to structured data for the product page.



currently, it only adds one image to the structured data via



'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImages(),


I tried it this way but didn't seem to work.



'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getMediaGalleryImages(),


or create an gallery images array



$productimages = array(); //test
$productimages = $currentProduct->getMediaGalleryImages();//test
'image' => $this->getUrl('pub/media/catalog') . 'product' . $productimages,


the multiple images should be send in an array like this



"image": [
"https://example.com/photos/1x1/photo.jpg",
"https://example.com/photos/4x3/photo.jpg",
"https://example.com/photos/16x9/photo.jpg"
]


Here is part of the code



public function showProductStructuredData()

if ($currentProduct = $this->getProduct())
try
$productId = $currentProduct->getId() ? $currentProduct->getId() : $this->request->getParam('id');

$product = $this->productFactory->create()->load($productId);
$availability = $product->isAvailable() ? 'InStock' : 'OutOfStock';
$productimages = array(); //test
$productimages = $currentProduct->getMediaGalleryImages();//test
$stockItem = $this->stockState->getStockItem(
$product->getId(),
$product->getStore()->getWebsiteId()
);
$priceValidUntil = $currentProduct->getSpecialToDate();
$productStructuredData = [
'@context' => 'http://schema.org/',
'@type' => 'Product',
'name' => $currentProduct->getName(),
'description' => trim(strip_tags($currentProduct->getShortDescription())),
'sku' => $currentProduct->getSku(),
'mpn' => $currentProduct->getSku(), //added 7-30-2019
'url' => $currentProduct->getProductUrl(),
'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImages(),
'brand' => 'mybrand', //added 7-30-2019
'offers' => [
'@type' => 'Offer',
'priceCurrency' => $this->_storeManager->getStore()->getCurrentCurrencyCode(),
'price' => $currentProduct->getPriceInfo()->getPrice('final_price')->getValue(),
'itemOffered' => $stockItem->getQty(),
'itemCondition' => 'New', //added 7-30-2019
'url' => $currentProduct->getProductUrl(), //added 7-30-2019
'availability' => 'http://schema.org/' . $availability
]
];
$productStructuredData = $this->addProductStructuredDataByType($currentProduct->getTypeId(), $currentProduct, $productStructuredData);

if (!empty($priceValidUntil))
$productStructuredData['offers']['priceValidUntil'] = $priceValidUntil;


if ($this->getReviewCount())
$productStructuredData['aggregateRating']['@type'] = 'AggregateRating';
$productStructuredData['aggregateRating']['bestRating'] = 100;
$productStructuredData['aggregateRating']['worstRating'] = 0;
$productStructuredData['aggregateRating']['ratingValue'] = $this->getRatingSummary();
$productStructuredData['aggregateRating']['reviewCount'] = $this->getReviewCount();


$objectStructuredData = new MagentoFrameworkDataObject(['mpdata' => $productStructuredData]);
$this->_eventManager->dispatch('mp_seo_product_structured_data', ['structured_data' => $objectStructuredData]);
$productStructuredData = $objectStructuredData->getMpdata();

return $this->helperData->createStructuredData($productStructuredData, '<!-- Product Structured Data by Mageplaza SEO-->');
catch (Exception $e)
$this->messageManager->addError(__('Can not add structured data'));












share|improve this question
































    0















    I'm looking to add all media images to structured data for the product page.



    currently, it only adds one image to the structured data via



    'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImages(),


    I tried it this way but didn't seem to work.



    'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getMediaGalleryImages(),


    or create an gallery images array



    $productimages = array(); //test
    $productimages = $currentProduct->getMediaGalleryImages();//test
    'image' => $this->getUrl('pub/media/catalog') . 'product' . $productimages,


    the multiple images should be send in an array like this



    "image": [
    "https://example.com/photos/1x1/photo.jpg",
    "https://example.com/photos/4x3/photo.jpg",
    "https://example.com/photos/16x9/photo.jpg"
    ]


    Here is part of the code



    public function showProductStructuredData()

    if ($currentProduct = $this->getProduct())
    try
    $productId = $currentProduct->getId() ? $currentProduct->getId() : $this->request->getParam('id');

    $product = $this->productFactory->create()->load($productId);
    $availability = $product->isAvailable() ? 'InStock' : 'OutOfStock';
    $productimages = array(); //test
    $productimages = $currentProduct->getMediaGalleryImages();//test
    $stockItem = $this->stockState->getStockItem(
    $product->getId(),
    $product->getStore()->getWebsiteId()
    );
    $priceValidUntil = $currentProduct->getSpecialToDate();
    $productStructuredData = [
    '@context' => 'http://schema.org/',
    '@type' => 'Product',
    'name' => $currentProduct->getName(),
    'description' => trim(strip_tags($currentProduct->getShortDescription())),
    'sku' => $currentProduct->getSku(),
    'mpn' => $currentProduct->getSku(), //added 7-30-2019
    'url' => $currentProduct->getProductUrl(),
    'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImages(),
    'brand' => 'mybrand', //added 7-30-2019
    'offers' => [
    '@type' => 'Offer',
    'priceCurrency' => $this->_storeManager->getStore()->getCurrentCurrencyCode(),
    'price' => $currentProduct->getPriceInfo()->getPrice('final_price')->getValue(),
    'itemOffered' => $stockItem->getQty(),
    'itemCondition' => 'New', //added 7-30-2019
    'url' => $currentProduct->getProductUrl(), //added 7-30-2019
    'availability' => 'http://schema.org/' . $availability
    ]
    ];
    $productStructuredData = $this->addProductStructuredDataByType($currentProduct->getTypeId(), $currentProduct, $productStructuredData);

    if (!empty($priceValidUntil))
    $productStructuredData['offers']['priceValidUntil'] = $priceValidUntil;


    if ($this->getReviewCount())
    $productStructuredData['aggregateRating']['@type'] = 'AggregateRating';
    $productStructuredData['aggregateRating']['bestRating'] = 100;
    $productStructuredData['aggregateRating']['worstRating'] = 0;
    $productStructuredData['aggregateRating']['ratingValue'] = $this->getRatingSummary();
    $productStructuredData['aggregateRating']['reviewCount'] = $this->getReviewCount();


    $objectStructuredData = new MagentoFrameworkDataObject(['mpdata' => $productStructuredData]);
    $this->_eventManager->dispatch('mp_seo_product_structured_data', ['structured_data' => $objectStructuredData]);
    $productStructuredData = $objectStructuredData->getMpdata();

    return $this->helperData->createStructuredData($productStructuredData, '<!-- Product Structured Data by Mageplaza SEO-->');
    catch (Exception $e)
    $this->messageManager->addError(__('Can not add structured data'));












    share|improve this question




























      0












      0








      0








      I'm looking to add all media images to structured data for the product page.



      currently, it only adds one image to the structured data via



      'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImages(),


      I tried it this way but didn't seem to work.



      'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getMediaGalleryImages(),


      or create an gallery images array



      $productimages = array(); //test
      $productimages = $currentProduct->getMediaGalleryImages();//test
      'image' => $this->getUrl('pub/media/catalog') . 'product' . $productimages,


      the multiple images should be send in an array like this



      "image": [
      "https://example.com/photos/1x1/photo.jpg",
      "https://example.com/photos/4x3/photo.jpg",
      "https://example.com/photos/16x9/photo.jpg"
      ]


      Here is part of the code



      public function showProductStructuredData()

      if ($currentProduct = $this->getProduct())
      try
      $productId = $currentProduct->getId() ? $currentProduct->getId() : $this->request->getParam('id');

      $product = $this->productFactory->create()->load($productId);
      $availability = $product->isAvailable() ? 'InStock' : 'OutOfStock';
      $productimages = array(); //test
      $productimages = $currentProduct->getMediaGalleryImages();//test
      $stockItem = $this->stockState->getStockItem(
      $product->getId(),
      $product->getStore()->getWebsiteId()
      );
      $priceValidUntil = $currentProduct->getSpecialToDate();
      $productStructuredData = [
      '@context' => 'http://schema.org/',
      '@type' => 'Product',
      'name' => $currentProduct->getName(),
      'description' => trim(strip_tags($currentProduct->getShortDescription())),
      'sku' => $currentProduct->getSku(),
      'mpn' => $currentProduct->getSku(), //added 7-30-2019
      'url' => $currentProduct->getProductUrl(),
      'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImages(),
      'brand' => 'mybrand', //added 7-30-2019
      'offers' => [
      '@type' => 'Offer',
      'priceCurrency' => $this->_storeManager->getStore()->getCurrentCurrencyCode(),
      'price' => $currentProduct->getPriceInfo()->getPrice('final_price')->getValue(),
      'itemOffered' => $stockItem->getQty(),
      'itemCondition' => 'New', //added 7-30-2019
      'url' => $currentProduct->getProductUrl(), //added 7-30-2019
      'availability' => 'http://schema.org/' . $availability
      ]
      ];
      $productStructuredData = $this->addProductStructuredDataByType($currentProduct->getTypeId(), $currentProduct, $productStructuredData);

      if (!empty($priceValidUntil))
      $productStructuredData['offers']['priceValidUntil'] = $priceValidUntil;


      if ($this->getReviewCount())
      $productStructuredData['aggregateRating']['@type'] = 'AggregateRating';
      $productStructuredData['aggregateRating']['bestRating'] = 100;
      $productStructuredData['aggregateRating']['worstRating'] = 0;
      $productStructuredData['aggregateRating']['ratingValue'] = $this->getRatingSummary();
      $productStructuredData['aggregateRating']['reviewCount'] = $this->getReviewCount();


      $objectStructuredData = new MagentoFrameworkDataObject(['mpdata' => $productStructuredData]);
      $this->_eventManager->dispatch('mp_seo_product_structured_data', ['structured_data' => $objectStructuredData]);
      $productStructuredData = $objectStructuredData->getMpdata();

      return $this->helperData->createStructuredData($productStructuredData, '<!-- Product Structured Data by Mageplaza SEO-->');
      catch (Exception $e)
      $this->messageManager->addError(__('Can not add structured data'));












      share|improve this question
















      I'm looking to add all media images to structured data for the product page.



      currently, it only adds one image to the structured data via



      'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImages(),


      I tried it this way but didn't seem to work.



      'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getMediaGalleryImages(),


      or create an gallery images array



      $productimages = array(); //test
      $productimages = $currentProduct->getMediaGalleryImages();//test
      'image' => $this->getUrl('pub/media/catalog') . 'product' . $productimages,


      the multiple images should be send in an array like this



      "image": [
      "https://example.com/photos/1x1/photo.jpg",
      "https://example.com/photos/4x3/photo.jpg",
      "https://example.com/photos/16x9/photo.jpg"
      ]


      Here is part of the code



      public function showProductStructuredData()

      if ($currentProduct = $this->getProduct())
      try
      $productId = $currentProduct->getId() ? $currentProduct->getId() : $this->request->getParam('id');

      $product = $this->productFactory->create()->load($productId);
      $availability = $product->isAvailable() ? 'InStock' : 'OutOfStock';
      $productimages = array(); //test
      $productimages = $currentProduct->getMediaGalleryImages();//test
      $stockItem = $this->stockState->getStockItem(
      $product->getId(),
      $product->getStore()->getWebsiteId()
      );
      $priceValidUntil = $currentProduct->getSpecialToDate();
      $productStructuredData = [
      '@context' => 'http://schema.org/',
      '@type' => 'Product',
      'name' => $currentProduct->getName(),
      'description' => trim(strip_tags($currentProduct->getShortDescription())),
      'sku' => $currentProduct->getSku(),
      'mpn' => $currentProduct->getSku(), //added 7-30-2019
      'url' => $currentProduct->getProductUrl(),
      'image' => $this->getUrl('pub/media/catalog') . 'product' . $currentProduct->getImages(),
      'brand' => 'mybrand', //added 7-30-2019
      'offers' => [
      '@type' => 'Offer',
      'priceCurrency' => $this->_storeManager->getStore()->getCurrentCurrencyCode(),
      'price' => $currentProduct->getPriceInfo()->getPrice('final_price')->getValue(),
      'itemOffered' => $stockItem->getQty(),
      'itemCondition' => 'New', //added 7-30-2019
      'url' => $currentProduct->getProductUrl(), //added 7-30-2019
      'availability' => 'http://schema.org/' . $availability
      ]
      ];
      $productStructuredData = $this->addProductStructuredDataByType($currentProduct->getTypeId(), $currentProduct, $productStructuredData);

      if (!empty($priceValidUntil))
      $productStructuredData['offers']['priceValidUntil'] = $priceValidUntil;


      if ($this->getReviewCount())
      $productStructuredData['aggregateRating']['@type'] = 'AggregateRating';
      $productStructuredData['aggregateRating']['bestRating'] = 100;
      $productStructuredData['aggregateRating']['worstRating'] = 0;
      $productStructuredData['aggregateRating']['ratingValue'] = $this->getRatingSummary();
      $productStructuredData['aggregateRating']['reviewCount'] = $this->getReviewCount();


      $objectStructuredData = new MagentoFrameworkDataObject(['mpdata' => $productStructuredData]);
      $this->_eventManager->dispatch('mp_seo_product_structured_data', ['structured_data' => $objectStructuredData]);
      $productStructuredData = $objectStructuredData->getMpdata();

      return $this->helperData->createStructuredData($productStructuredData, '<!-- Product Structured Data by Mageplaza SEO-->');
      catch (Exception $e)
      $this->messageManager->addError(__('Can not add structured data'));









      magento2 media-images rich-snippets structured-data






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 1 at 5:18









      poojan sharma

      1,1192 silver badges12 bronze badges




      1,1192 silver badges12 bronze badges










      asked Jul 31 at 17:58









      Kris WenKris Wen

      36310 bronze badges




      36310 bronze badges























          0






          active

          oldest

          votes














          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f283999%2fadding-multiple-product-images-to-rich-snippet-structured-data-using-getmediagal%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f283999%2fadding-multiple-product-images-to-rich-snippet-structured-data-using-getmediagal%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?