4

All M2 themes I have tested do not have proper structured data/rich snippets. The currency symbol is in the price span, and gets a warning:

An example: link to snippet Problem code cleaned up a bit:

<span itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <span  data-price-amount="54"  data-price-type="finalPrice" itemprop="price">
    <span class="price">$54.00</span>    </span>
    <meta itemprop="priceCurrency" content="USD" />
</span>

Error: price $54.00 (The property $54.00 is not a valid price specification. Find out more about http://schema.org/price.)

If the $ is taken out of <span class="price">$54.00</span> like this it validates fine:

<span itemprop="offers" itemscope itemtype="http://schema.org/Offer">
$<span  data-price-amount="54"  data-price-type="finalPrice" itemprop="price">
<span class="price">54.00</span>    </span>
<meta itemprop="priceCurrency" content="USD" />

But I cannot find which files are creating the price code and which code to change. What is the best way to validate the structured data?

3

This is proper solution and worked

Go to extended file of this:

vendor/magento/module-catalog/view/base/templates/product/price/amount/default.phtml

Replace:

$block->getSchema() ? ' itemprop="price"' :

With:

$block->getSchema() ? ' itemprop="price" content="' . $block->getDisplayValue() . '"':

Source: https://github.com/magento/magento2/issues/7173

0

I edited this file -

vendor\magento\module-catalog\view\base\templates\product\price\amount\default.phtml

moved to theme

app\design\frontend\(Vendor)\(Store)\Magento_Catalog\templates\product\price\amount\default.phtml

The line

<?php /* @escapeNotVerified */ echo $block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer()) ?>

contains $block->formatCurrency which is causing the error. Remove this or change it to <?php echo $block->getDisplayValue(); ?> and the price will now validate.

You can then hardcore the currency symbol before <span <?php if ($block->getPriceId()) But there is a JavaScript code that will overide this file and add it in. If you do not want this happening -

vendor\magento\module-catalog\view\frontend\templates\product\view\form.phtml

moved to

app\design\frontend\(Vendor)\(Store)\Magento_Catalog\templates\product\view\form.phtml

and remove the line - priceBoxes.priceBox({'priceConfig': <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>}); that was calling the JavaScript.

0

After struggling for a long time with this problem I found this fix -

<meta itemprop="price" content="<?php echo preg_replace('/[^0-9.]+/', '',strip_tags(Mage::helper('core')->currency($_product->getFinalPrice()))); ?>">

Just insert that line above this one -

<span class="price"><?php echo $_coreHelper->currency($_price,true,false) ?></span>

All credit goes to -

https://feedarmy.com/kb/magento-microdata-for-google-shopping/

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.