2

I have a 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.

1

You're editing the wrong file, Do it in the default.phtml file https://github.com/magento/magento2/blob/b1e56ed3b6f13f1ab780d8eddc33fc04cb6ecf75/app/code/Magento/Catalog/view/frontend/templates/product/view/type/default.phtml First copy it to your theme, then edit it.

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.