cancel
Showing results for 
Search instead for 
Did you mean: 

Add microdata stock availbility Magento 2

Add microdata stock availbility Magento 2

I have default file, where rendering price and adding some microdata. I need to add stock availbility. But I can't find a right way.

/app/design/frontend/Theme/myTheme/Magento_Catalog/templates/product/price/amount/default.phtml

 

<?php /** @var \Magento\Framework\Pricing\Render\Amount $block */ ?>

<span class="price-container <?php /* @escapeNotVerified */ echo $block->getAdjustmentCssClasses() ?>">
    <?php if ($block->getDisplayLabel()): ?>
        <span class="price-label"><?php /* @escapeNotVerified */ echo $block->getDisplayLabel(); ?></span>
    <?php endif; ?>
    <span <?php if ($block->getPriceId()): ?> id="<?php /* @escapeNotVerified */ echo $block->getPriceId() ?>"<?php endif;?>
        <?php echo($block->getPriceDisplayLabel()) ? 'data-label="' . $block->getPriceDisplayLabel() . $block->getPriceDisplayInclExclTaxes() . '"' : '' ?>
        data-price-amount="<?php /* @escapeNotVerified */ echo $block->getDisplayValue(); ?>"
        data-price-type="<?php /* @escapeNotVerified */ echo $block->getPriceType(); ?>"
        class="price-wrapper <?php /* @escapeNotVerified */ echo $block->getPriceWrapperCss(); ?>"
        <?php echo $block->getSchema() ? ' itemprop="price"' : '' ?>>
        <?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>
    </span>
    <?php if ($block->hasAdjustmentsHtml()): ?>
        <?php echo $block->getAdjustmentsHtml() ?>
    <?php endif; ?>
    <?php if ($block->getSchema()): ?>
        <meta itemprop="priceCurrency" content="<?php /* @escapeNotVerified */ echo $block->getDisplayCurrencyCode()?>" />
    <?php endif; ?>
</span>

If I add this part:

 

<?php if ($block->displayProductStockStatus()): ?>
    <?php if ($_product->isAvailable()): ?>
          <link itemprop="availability" href="http://schema.org/InStock">
    <?php else: ?>
          <link itemprop="availability" href="http://schema.org/OutOfStock">
    <?php endif; ?>
<?php endif; ?>

I get error Invalid Method: displayProductStockStatus()

 

Please provide me, how can I do it right. Thanks.